"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 sinon_1 = __importDefault(require("sinon"));
const createVenue_1 = require("../createVenue");
const mocks_1 = require("../../../testUtils/mocks");
const types_1 = require("../../../types");
const utilsConversionModule = __importStar(require("../../../utils/conversion"));
const utilsInternalModule = __importStar(require("../../../utils/internal"));
describe('createVenue procedure', () => {
    let mockContext;
    let stringToVenueDetailsStub;
    let venueTypeToMeshVenueTypeStub;
    let addTransactionStub;
    let createVenueTransaction;
    let venue;
    beforeAll(() => {
        mocks_1.entityMockUtils.initMocks();
        mocks_1.procedureMockUtils.initMocks();
        mocks_1.dsMockUtils.initMocks();
        stringToVenueDetailsStub = sinon_1.default.stub(utilsConversionModule, 'stringToVenueDetails');
        venueTypeToMeshVenueTypeStub = sinon_1.default.stub(utilsConversionModule, 'venueTypeToMeshVenueType');
        venue = 'venue';
    });
    beforeEach(() => {
        mockContext = mocks_1.dsMockUtils.getContextInstance();
        addTransactionStub = mocks_1.procedureMockUtils.getAddTransactionStub().returns([venue]);
        createVenueTransaction = mocks_1.dsMockUtils.createTxStub('settlement', 'createVenue');
    });
    afterEach(() => {
        mocks_1.entityMockUtils.reset();
        mocks_1.procedureMockUtils.reset();
        mocks_1.dsMockUtils.reset();
    });
    afterAll(() => {
        mocks_1.entityMockUtils.cleanup();
        mocks_1.procedureMockUtils.cleanup();
        mocks_1.dsMockUtils.cleanup();
    });
    test('should add a createVenue transaction to the queue', () => __awaiter(void 0, void 0, void 0, function* () {
        const description = 'description';
        const type = types_1.VenueType.Distribution;
        const args = {
            description,
            type,
        };
        const rawDetails = mocks_1.dsMockUtils.createMockVenueDetails(description);
        const rawType = mocks_1.dsMockUtils.createMockVenueType(type);
        const proc = mocks_1.procedureMockUtils.getInstance(mockContext);
        stringToVenueDetailsStub.withArgs(description, mockContext).returns(rawDetails);
        venueTypeToMeshVenueTypeStub.withArgs(type, mockContext).returns(rawType);
        const result = yield createVenue_1.prepareCreateVenue.call(proc, args);
        sinon_1.default.assert.calledWith(addTransactionStub, createVenueTransaction, sinon_1.default.match({
            resolvers: sinon_1.default.match.array,
        }), rawDetails, [], rawType);
        expect(result).toBe(venue);
    }));
});
describe('createCreateVenueResolver', () => {
    const filterEventRecordsStub = sinon_1.default.stub(utilsInternalModule, 'filterEventRecords');
    const id = new bignumber_js_1.default(10);
    const rawId = mocks_1.dsMockUtils.createMockU64(id.toNumber());
    beforeAll(() => {
        mocks_1.entityMockUtils.initMocks({
            venueOptions: {
                id,
            },
        });
    });
    beforeEach(() => {
        filterEventRecordsStub.returns([mocks_1.dsMockUtils.createMockIEvent(['did', rawId])]);
    });
    afterEach(() => {
        filterEventRecordsStub.reset();
    });
    test('should return the new Venue', () => {
        const fakeContext = {};
        const result = createVenue_1.createCreateVenueResolver(fakeContext)({});
        expect(result.id).toEqual(id);
    });
});
//# sourceMappingURL=createVenue.js.map