"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 bignumber_js_1 = __importDefault(require("bignumber.js"));
const Settlements_1 = require("../Settlements");
const mocks_1 = require("../testUtils/mocks");
const types_1 = require("../types");
jest.mock('~/api/entities/Venue', require("../testUtils/mocks/entities").mockVenueModule('~/api/entities/Venue'));
jest.mock('~/api/entities/Instruction', require("../testUtils/mocks/entities").mockInstructionModule('~/api/entities/Instruction'));
jest.mock('~/base/Procedure', require("../testUtils/mocks/procedure").mockProcedureModule('~/base/Procedure'));
describe('Settlements Class', () => {
    let context;
    let settlements;
    beforeAll(() => {
        mocks_1.dsMockUtils.initMocks();
        mocks_1.entityMockUtils.initMocks();
        mocks_1.procedureMockUtils.initMocks();
    });
    beforeEach(() => {
        context = mocks_1.dsMockUtils.getContextInstance();
        settlements = new Settlements_1.Settlements(context);
    });
    afterEach(() => {
        mocks_1.dsMockUtils.reset();
        mocks_1.entityMockUtils.reset();
        mocks_1.procedureMockUtils.reset();
    });
    afterAll(() => {
        mocks_1.dsMockUtils.cleanup();
        mocks_1.entityMockUtils.cleanup();
        mocks_1.procedureMockUtils.cleanup();
    });
    describe('method: getVenue', () => {
        test('should return a Venue by its id', () => __awaiter(void 0, void 0, void 0, function* () {
            const venueId = new bignumber_js_1.default(1);
            const matchingVenue = mocks_1.entityMockUtils.getVenueInstance({ id: venueId });
            mocks_1.entityMockUtils.configureMocks({
                venueOptions: { exists: true },
            });
            const result = yield settlements.getVenue({ id: venueId });
            expect(result).toMatchObject(matchingVenue);
        }));
        test('should throw if the Venue does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
            const venueId = new bignumber_js_1.default(1);
            mocks_1.entityMockUtils.configureMocks({
                venueOptions: { exists: false },
            });
            return expect(settlements.getVenue({ id: venueId })).rejects.toThrow("The Venue doesn't exist");
        }));
    });
    describe('method: getInstruction', () => {
        test('should return an Instruction by its id', () => __awaiter(void 0, void 0, void 0, function* () {
            const instructionId = new bignumber_js_1.default(1);
            const matchingInstruction = mocks_1.entityMockUtils.getInstructionInstance({ id: instructionId });
            mocks_1.entityMockUtils.configureMocks({
                instructionOptions: { exists: true },
            });
            const result = yield settlements.getInstruction({ id: instructionId });
            expect(result).toMatchObject(matchingInstruction);
        }));
        test('should throw if the Instruction does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
            const instructionId = new bignumber_js_1.default(1);
            mocks_1.entityMockUtils.configureMocks({
                instructionOptions: { exists: false },
            });
            return expect(settlements.getInstruction({ id: instructionId })).rejects.toThrow("The Instruction doesn't exist");
        }));
    });
    describe('method: createVenue', () => {
        test('should prepare the procedure with the correct arguments and context, and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const args = {
                description: 'description',
                type: types_1.VenueType.Distribution,
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield settlements.createVenue(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
});
//# sourceMappingURL=Settlements.js.map