"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 CurrentIdentity_1 = require("../CurrentIdentity");
const mocks_1 = require("../testUtils/mocks");
const types_1 = require("../types");
jest.mock('~/base/Procedure', require("../testUtils/mocks/procedure").mockProcedureModule('~/base/Procedure'));
describe('CurrentIdentity class', () => {
    let context;
    beforeAll(() => {
        mocks_1.dsMockUtils.initMocks();
        mocks_1.entityMockUtils.initMocks();
        mocks_1.procedureMockUtils.initMocks();
    });
    beforeEach(() => {
        context = mocks_1.dsMockUtils.getContextInstance();
    });
    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: removeSecondaryKeys', () => {
        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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const signers = [mocks_1.entityMockUtils.getAccountInstance({ address: 'someAccount' })];
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { signers }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.removeSecondaryKeys({ signers });
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: revokePermissions', () => {
        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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const signers = [mocks_1.entityMockUtils.getAccountInstance({ address: 'someAccount' })];
            const secondaryKeys = [
                {
                    signer: signers[0],
                    permissions: {
                        tokens: { type: types_1.PermissionType.Include, values: [] },
                        transactions: { type: types_1.PermissionType.Include, values: [] },
                        portfolios: { type: types_1.PermissionType.Include, values: [] },
                    },
                },
            ];
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { secondaryKeys }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.revokePermissions({ secondaryKeys: signers });
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: modifyPermissions', () => {
        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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const secondaryKeys = [
                {
                    signer: mocks_1.entityMockUtils.getAccountInstance({ address: 'someAccount' }),
                    permissions: { tokens: null, transactions: null, portfolios: null },
                },
            ];
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { secondaryKeys }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.modifyPermissions({ secondaryKeys });
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: inviteAccount', () => {
        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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const args = {
                targetAccount: 'someAccount',
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.inviteAccount(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
    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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            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 currentIdentity.createVenue(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: freezeSecondaryKeys', () => {
        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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const args = {
                freeze: true,
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.freezeSecondaryKeys();
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: unfreezeSecondaryKeys', () => {
        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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const args = {
                freeze: false,
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.unfreezeSecondaryKeys();
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: reserveTicker', () => {
        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 currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const args = {
                ticker: 'SOMETICKER',
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.reserveTicker(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: createToken', () => {
        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 ticker = 'FAKETICKER';
            const currentIdentity = new CurrentIdentity_1.CurrentIdentity(context);
            const args = {
                ticker,
                name: 'TEST',
                totalSupply: new bignumber_js_1.default(100),
                isDivisible: true,
                tokenType: types_1.KnownTokenType.EquityCommon,
                tokenIdentifiers: [{ type: types_1.TokenIdentifierType.Isin, value: '12345' }],
                fundingRound: 'Series A',
                requireInvestorUniqueness: false,
                reservationRequired: false,
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield currentIdentity.createToken(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
});
//# sourceMappingURL=CurrentIdentity.js.map