"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const internal_1 = require("../../../internal");
const mocks_1 = require("../../../testUtils/mocks");
const types_1 = require("../../../types");
jest.mock('~/api/entities/SecurityToken', require("../../../testUtils/mocks/entities").mockSecurityTokenModule('~/api/entities/SecurityToken'));
describe('KnownPermissionGroup class', () => {
    const ticker = 'TOKENNAME';
    let context;
    beforeAll(() => {
        mocks_1.dsMockUtils.initMocks();
        mocks_1.entityMockUtils.initMocks();
    });
    beforeEach(() => {
        context = mocks_1.dsMockUtils.getContextInstance();
    });
    afterEach(() => {
        mocks_1.dsMockUtils.reset();
        mocks_1.entityMockUtils.reset();
    });
    afterAll(() => {
        mocks_1.dsMockUtils.cleanup();
        mocks_1.entityMockUtils.cleanup();
    });
    test('should extend PermissionGroup', () => {
        expect(internal_1.KnownPermissionGroup.prototype instanceof internal_1.PermissionGroup).toBe(true);
    });
    describe('constructor', () => {
        test('should assign id to instance', () => {
            const type = types_1.PermissionGroupType.Full;
            const knownPermissionGroup = new internal_1.KnownPermissionGroup({ type, ticker }, context);
            expect(knownPermissionGroup.token.ticker).toBe(ticker);
            expect(knownPermissionGroup.type).toBe(type);
        });
    });
    describe('method: isUniqueIdentifiers', () => {
        test('should return true if the object conforms to the interface', () => {
            expect(internal_1.KnownPermissionGroup.isUniqueIdentifiers({
                type: types_1.PermissionGroupType.PolymeshV1Caa,
                ticker,
            })).toBe(true);
            expect(internal_1.KnownPermissionGroup.isUniqueIdentifiers({})).toBe(false);
            expect(internal_1.KnownPermissionGroup.isUniqueIdentifiers({ ticker })).toBe(false);
        });
    });
    describe('method: toJson', () => {
        test('should return a human readable version of the entity', () => {
            mocks_1.entityMockUtils.configureMocks({
                securityTokenOptions: {
                    toJson: ticker,
                },
            });
            const type = types_1.PermissionGroupType.Full;
            const knownPermissionGroup = new internal_1.KnownPermissionGroup({ type, ticker }, context);
            expect(knownPermissionGroup.toJson()).toEqual({
                type,
                ticker,
            });
        });
    });
    describe('method: getPermissions', () => {
        test('should return a list of permissions and transaction groups', () => __awaiter(void 0, void 0, void 0, function* () {
            let type = types_1.PermissionGroupType.ExceptMeta;
            let knownPermissionGroup = new internal_1.KnownPermissionGroup({ type, ticker }, context);
            let result = yield knownPermissionGroup.getPermissions();
            expect(result).toEqual({
                transactions: { values: ['externalAgents'], type: 'Exclude' },
                transactionGroups: [],
            });
            type = types_1.PermissionGroupType.PolymeshV1Caa;
            knownPermissionGroup = new internal_1.KnownPermissionGroup({ type, ticker }, context);
            result = yield knownPermissionGroup.getPermissions();
            expect(result).toEqual({
                transactions: {
                    values: ['capitalDistribution', 'corporateAction', 'corporateBallot'],
                    type: 'Include',
                },
                transactionGroups: [],
            });
            type = types_1.PermissionGroupType.PolymeshV1Pia;
            knownPermissionGroup = new internal_1.KnownPermissionGroup({ type, ticker }, context);
            result = yield knownPermissionGroup.getPermissions();
            expect(result).toEqual({
                transactions: {
                    values: ['asset.controllerTransfer', 'asset.issue', 'asset.redeem', 'sto'],
                    exceptions: ['sto.invest'],
                    type: 'Include',
                },
                transactionGroups: ['Issuance'],
            });
            type = types_1.PermissionGroupType.Full;
            knownPermissionGroup = new internal_1.KnownPermissionGroup({ type, ticker }, context);
            result = yield knownPermissionGroup.getPermissions();
            expect(result).toEqual({ transactions: null, transactionGroups: [] });
        }));
    });
    describe('exists', () => {
        test('should return true', () => {
            const type = types_1.PermissionGroupType.ExceptMeta;
            const knownPermissionGroup = new internal_1.KnownPermissionGroup({ type, ticker }, context);
            return expect(knownPermissionGroup.exists()).resolves.toBe(true);
        });
    });
});
//# sourceMappingURL=KnownPermissionGroup.js.map