"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 Identities_1 = require("../Identities");
const internal_1 = require("../internal");
const mocks_1 = require("../testUtils/mocks");
jest.mock('~/api/entities/Identity', require("../testUtils/mocks/entities").mockIdentityModule('~/api/entities/Identity'));
jest.mock('~/base/Procedure', require("../testUtils/mocks/procedure").mockProcedureModule('~/base/Procedure'));
describe('Identities Class', () => {
    let context;
    let identities;
    beforeAll(() => {
        mocks_1.dsMockUtils.initMocks();
        mocks_1.entityMockUtils.initMocks();
        mocks_1.procedureMockUtils.initMocks();
    });
    beforeEach(() => {
        context = mocks_1.dsMockUtils.getContextInstance();
        identities = new Identities_1.Identities(context);
    });
    afterEach(() => {
        mocks_1.dsMockUtils.reset();
        mocks_1.entityMockUtils.reset();
        mocks_1.procedureMockUtils.reset();
    });
    afterAll(() => {
        mocks_1.dsMockUtils.cleanup();
        mocks_1.procedureMockUtils.cleanup();
    });
    describe('method: getIdentity', () => {
        test('should return an Identity object with the passed did', () => __awaiter(void 0, void 0, void 0, function* () {
            const params = { did: 'testDid' };
            const identity = new internal_1.Identity(params, context);
            context.getIdentity.onFirstCall().resolves(identity);
            const result = yield identities.getIdentity(params);
            expect(result).toMatchObject(identity);
        }));
    });
    describe('method: registerIdentity', () => {
        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 = {
                targetAccount: 'someTarget',
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield identities.registerIdentity(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: createPortfolio', () => {
        test('should prepare the procedure and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const args = { name: 'someName' };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield identities.createPortfolio(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: isIdentityValid', () => {
        test('should return true if the supplied Identity exists', () => __awaiter(void 0, void 0, void 0, function* () {
            const did = 'someDid';
            const result = yield identities.isIdentityValid({
                identity: mocks_1.entityMockUtils.getIdentityInstance({ did }),
            });
            expect(result).toBe(true);
        }));
        test('should return false if the supplied Identity is invalid', () => __awaiter(void 0, void 0, void 0, function* () {
            const did = 'someDid';
            mocks_1.entityMockUtils.configureMocks({ identityOptions: { exists: false } });
            const result = yield identities.isIdentityValid({ identity: did });
            expect(result).toBe(false);
        }));
    });
});
//# sourceMappingURL=Identities.js.map