"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sinon_1 = __importDefault(require("sinon"));
const internal_1 = require("../../internal");
describe('Post Transaction Value class', () => {
    describe('method: run', () => {
        test('should run the provided resolver function with the receipt and assign the resulting value', () => __awaiter(void 0, void 0, void 0, function* () {
            const receipt = 1;
            const resolverFunctionStub = sinon_1.default.stub().callsFake(r => Promise.resolve(r));
            const p = new internal_1.PostTransactionValue(resolverFunctionStub);
            yield p.run(receipt);
            sinon_1.default.assert.calledWith(resolverFunctionStub, receipt);
            expect(p.value).toBe(receipt);
        }));
    });
    describe('method: transform', () => {
        test('should return a new PTV that runs its value through the callback', () => __awaiter(void 0, void 0, void 0, function* () {
            const receipt = 1;
            const resolverFunctionStub = sinon_1.default.stub().callsFake(r => Promise.resolve(r));
            const p = new internal_1.PostTransactionValue(resolverFunctionStub);
            const transformed = p.transform(n => `${n}`);
            yield p.run(receipt);
            sinon_1.default.assert.calledWith(resolverFunctionStub, receipt);
            expect(transformed.value).toBe('1');
        }));
    });
    describe('method: merge', () => {
        test('should return a new PTV that runs both underlying values through the callback', () => __awaiter(void 0, void 0, void 0, function* () {
            const pReceipt = 1;
            const qReceipt = 'a';
            const pResolverFunctionStub = sinon_1.default.stub().callsFake(r => Promise.resolve(r));
            const qResolverFunctionStub = sinon_1.default.stub().callsFake(r => Promise.resolve(r));
            const p = new internal_1.PostTransactionValue(pResolverFunctionStub);
            const q = new internal_1.PostTransactionValue(qResolverFunctionStub);
            const merged = p.merge(q, (a, b) => `${a * 2}${b}`);
            yield p.run(pReceipt);
            yield q.run(qReceipt);
            sinon_1.default.assert.calledWith(pResolverFunctionStub, pReceipt);
            sinon_1.default.assert.calledWith(qResolverFunctionStub, qReceipt);
            expect(merged.value).toBe('2a');
        }));
        test('should accept non PTV values', () => __awaiter(void 0, void 0, void 0, function* () {
            const receipt = 1;
            const resolverFunctionStub = sinon_1.default.stub().callsFake(r => Promise.resolve(r));
            const p = new internal_1.PostTransactionValue(resolverFunctionStub);
            const merged = p.merge('a', (a, b) => `${a * 2}${b}`);
            yield p.run(receipt);
            sinon_1.default.assert.calledWith(resolverFunctionStub, receipt);
            expect(merged.value).toBe('2a');
        }));
    });
});
//# sourceMappingURL=PostTransactionValue.js.map