UNPKG

@microsoft/useragent-sdk

Version:

SDK for building decentralized identity wallets and enterprise agents.

102 lines 5.37 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); const HubInterface_1 = require("../../src/hubInterfaces/HubInterface"); const Identifier_1 = require("../../src/Identifier"); const Collections_1 = require("../../src/hubInterfaces/Collections"); const Permissions_1 = require("../../src/hubInterfaces/Permissions"); const Actions_1 = require("../../src/hubInterfaces/Actions"); const Profile_1 = require("../../src/hubInterfaces/Profile"); const UserAgentError_1 = require("../../src/UserAgentError"); const src_1 = require("../../src"); const IPermissionGrant_1 = require("../../src/hubSession/objects/IPermissionGrant"); const CryptoFactoryNode_1 = require("../../src/crypto/plugin/CryptoFactoryNode"); describe('Hub Interface', () => { let options; const uaOptions = new src_1.UserAgentOptions(); uaOptions.cryptoOptions.cryptoFactory = new CryptoFactoryNode_1.default(new src_1.KeyStoreInMemory(), src_1.SubtleCryptoNode.getSubtleCrypto()); const identifier = new Identifier_1.default('did:test:12345', uaOptions); identifier.options.cryptoOptions.signingKeyReference = 'testKey'; beforeEach(() => { options = new HubInterface_1.HubInterfaceOptions(); options.context = 'https://schema.org/test'; options.type = 'test'; options.clientIdentifier = identifier; options.hubOwner = identifier; }); describe('Collections', () => { it('should create a new Instance of Collections', () => { const collections = new Collections_1.default(options); expect(collections).toBeDefined(); expect(collections.type).toBe('test'); expect(collections.commitStrategy).toBe('basic'); expect(collections.hubInterface).toBe(HubInterface_1.HubInterfaceType.Collections); expect(collections.context).toBe('https://schema.org/test'); }); it('should throw error if context is not defined', () => { try { delete options.context; const collections = new Collections_1.default(options); // should not get passed this point. fail(); console.log(collections); } catch (error) { expect(error instanceof UserAgentError_1.default).toBeTruthy(); expect(error.message).toEqual('Hub Interface Options missing context parameter'); } }); it('should throw error if type is not defined', () => { try { delete options.type; const collections = new Collections_1.default(options); // should not get passed this point. fail(); console.log(collections); } catch (error) { expect(error instanceof UserAgentError_1.default).toBeTruthy(); expect(error.message).toEqual('Hub Interface Options missing type parameter'); } }); it('should add object to a hub', async () => { const collections = new Collections_1.default(options); spyOn(collections.hubClient, 'commit').and.stub; const commit = await collections.addObject('test object'); }); }); describe('Actions', () => { it('should create a new Instance of Actions', () => { const collections = new Actions_1.default(options); expect(collections).toBeDefined(); expect(collections.type).toBe('test'); expect(collections.commitStrategy).toBe('basic'); expect(collections.hubInterface).toBe(HubInterface_1.HubInterfaceType.Actions); expect(collections.context).toBe('https://schema.org/test'); }); }); describe('Permissions', () => { it('should create a new Instance of Permissions', () => { const collections = new Permissions_1.default(options); expect(collections).toBeDefined(); expect(collections.type).toBe(IPermissionGrant_1.PERMISSION_GRANT_TYPE); expect(collections.commitStrategy).toBe('basic'); expect(collections.hubInterface).toBe(HubInterface_1.HubInterfaceType.Permissions); expect(collections.context).toBe(IPermissionGrant_1.PERMISSION_GRANT_CONTEXT); }); }); describe('Profile', () => { it('should create a new Instance of Profile', () => { const collections = new Profile_1.default(options); expect(collections).toBeDefined(); expect(collections.type).toBe('test'); expect(collections.commitStrategy).toBe('basic'); expect(collections.hubInterface).toBe(HubInterface_1.HubInterfaceType.Profile); expect(collections.context).toBe('https://schema.org/test'); }); }); }); //# sourceMappingURL=hubInterface.spec.js.map