Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from m00sey/feat/le-coverage
Browse files Browse the repository at this point in the history
adds le coverage
  • Loading branch information
m00sey authored Oct 5, 2023
2 parents d3501e9 + d8b8484 commit faed701
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export type AID = string;
export * from './qvi';
export * from './le';
export * from './edges';
export * from './credentials';
export * from './credentials';
8 changes: 4 additions & 4 deletions src/le.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export class LE {
*
* @param {AID} issuee AID of QVI
* @param {credentials.EngagementContextRoleAuthorizationCredentialData} data
* @param {edges.EngagementContextRoleAuthorizationCredentialEdgeData} edge}
* @param {edges.EngagementContextRoleAuthorizationEdge} edge}
* @returns
*/
public async createECRAuthCredential(
issuee: AID,
data: credentials.EngagementContextRoleAuthorizationCredentialData,
edge: edges.EngagementContextRoleAuthorizationCredentialEdgeData
edge: edges.EngagementContextRoleAuthorizationEdge
) {
return await this.client
.credentials()
Expand All @@ -62,13 +62,13 @@ export class LE {
*
* @param {AID} issuee AID of QVI
* @param {credentials.OfficialOrganizationalRoleAuthorizationCredentialData} data
* @param {edges.OfficialOrganizationalRoleAuthorizationCredentialEdgeData} edge}
* @param {edges.OfficialOrganizationalRoleAuthorizationCredentialEdge} edge}
* @returns
*/
public async createOORAuthCredential(
issuee: AID,
data: credentials.OfficialOrganizationalRoleAuthorizationCredentialData,
edge: edges.OfficialOrganizationalRoleAuthorizationCredentialEdgeData
edge: edges.OfficialOrganizationalRoleAuthorizationEdge
) {
return await this.client
.credentials()
Expand Down
214 changes: 116 additions & 98 deletions test/le.test.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1,125 @@
import { describe, expect, it } from '@jest/globals';
import { Credentials, SignifyClient } from 'signify-ts';
import { anyOfClass, capture, instance, mock, verify, when } from 'ts-mockito';
import { LE, credentials, edges } from '../src';
import { rules } from '../src/rules';

describe('a legal entity', () => {
it('should create ecr auth credential', () => {
expect(true).toBe(true);
// let mockedClient: SignifyClient = mock(SignifyClient);

// let c: Credentials = mock(Credentials);
// when(mockedClient.credentials()).thenReturn(instance(c));

// let client = instance(mockedClient);
// let le = new LE(client, 'qvi_name', 'qvi_registry_aid');

// let data = new ECRAuthvLEICredentialData({
// qviAID: 'qvi_aid',
// timestamp: 'timestamp',
// recipient: 'recipient',
// LEI: 'lei',
// personLegalName: 'my legal name',
// engagementContextRole: 'context role',
// });
// let auth = new ECRAuthEdgeData({ leCredentialSAID: 'a said' });
// let edge = new ECRAuthEdge({ auth: auth });

// le.createECRAuthCredential('issuee aid', data, edge);

// let cap = capture(c.issue).last();

// verify(
// c.issue(
// 'qvi_name',
// 'qvi_registry_aid',
// 'EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g',
// 'issuee aid',
// anyOfClass(ECRAuthvLEICredentialData),
// Rules.ECRAuth,
// anyOfClass(ECRAuthEdge),
// false
// )
// ).once();

// let DATA_ARG = 4;
// expect(cap[DATA_ARG].LEI).toBe('lei');

// let EDGE_ARG = 6;
// expect(cap[EDGE_ARG].d).toBe(
// 'ENbbrJVx-rr8V7HzNmnrwt6OUaYD0sB-S-gxclr0TSM8'
// );
// expect(cap[EDGE_ARG].auth.n).toBe('a said');
// expect(cap[EDGE_ARG].auth.s).toBe(
// 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY'
// );
let mockedClient: SignifyClient = mock(SignifyClient);

let c: Credentials = mock(Credentials);
when(mockedClient.credentials()).thenReturn(instance(c));

let client = instance(mockedClient);
let le = new LE(client, 'qvi_name', 'qvi_registry_aid');
let data =
new credentials.EngagementContextRoleAuthorizationCredentialData({
qviAID: 'issueing to this qvi',
timestamp: 'time stamp',
issuee: 'ecr is meant for this aid',
LEI: 'LEI',
personLegalName: 'legal name',
engagementContextRole: 'my context role',
});
let edgeData =
new edges.EngagementContextRoleAuthorizationCredentialEdgeData({
legalEntityCredentialSAID: 'said',
});
let edge = new edges.EngagementContextRoleAuthorizationEdge({
le: edgeData,
});

le.createECRAuthCredential('issuee aid', data, edge);

let cap = capture(c.issue).last();

verify(
c.issue(
'qvi_name',
'qvi_registry_aid',
'EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g',
'issuee aid',
anyOfClass(
credentials.EngagementContextRoleAuthorizationCredentialData
),
rules.ECRAuth,
anyOfClass(edges.EngagementContextRoleAuthorizationEdge),
false
)
).once();

let DATA_ARG = 4;
expect(cap[DATA_ARG].LEI).toBe('LEI');

let EDGE_ARG = 6;
expect(cap[EDGE_ARG].d).toBe(
'EBlx5jE_cpbCQtypw1WLST-9Dz_PaNoRhgSIma7rWr0L'
);
expect(cap[EDGE_ARG].le.n).toBe('said');
expect(cap[EDGE_ARG].le.s).toBe(
'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY'
);
});

it('should create oor auth credential', () => {
expect(true).toBe(true);
// let mockedClient: SignifyClient = mock(SignifyClient);

// let c: Credentials = mock(Credentials);
// when(mockedClient.credentials()).thenReturn(instance(c));

// let client = instance(mockedClient);
// let le = new LE(client, 'qvi_name', 'qvi_registry_aid');

// let data = new OORAuthvLEICredentialData({
// qviAID: 'qvi_aid',
// timestamp: 'timestamp',
// recipient: 'recipient',
// LEI: 'lei',
// personLegalName: 'my legal name',
// officialOrganizationalRole: 'official role',
// });
// let auth = new OORAuthvLEIEdgeData({
// leCredentialSAID: 'legal_entity_aid',
// });
// let edge = new OORAuthEdge({ auth: auth });

// le.createOORAuthCredential('issuee aid', data, edge);

// let cap = capture(c.issue).last();

// verify(
// c.issue(
// 'qvi_name',
// 'qvi_registry_aid',
// 'EKA57bKBKxr_kN7iN5i7lMUxpMG-s19dRcmov1iDxz-E',
// 'issuee aid',
// anyOfClass(OORAuthvLEICredentialData),
// Rules.OORAuth,
// anyOfClass(OORAuthEdge),
// false
// )
// ).once();

// let DATA_ARG = 4;
// expect(cap[DATA_ARG].LEI).toBe('lei');

// let EDGE_ARG = 6;
// expect(cap[EDGE_ARG].d).toBe(
// 'ED1dQiXEfyqMu2sh1zz7RMv5GP4g5b8YGMLrNdIht-TP'
// );
// expect(cap[EDGE_ARG].auth.n).toBe('legal_entity_aid');
// expect(cap[EDGE_ARG].auth.s).toBe(
// 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY'
// );
let mockedClient: SignifyClient = mock(SignifyClient);

let c: Credentials = mock(Credentials);
when(mockedClient.credentials()).thenReturn(instance(c));

let client = instance(mockedClient);
let le = new LE(client, 'qvi_name', 'qvi_registry_aid');
let data =
new credentials.OfficialOrganizationalRoleAuthorizationCredentialData(
{
qviAID: 'issueing to this qvi',
timestamp: 'time stamp',
issuee: 'oor is meant for this aid',
LEI: 'LEI',
personLegalName: 'legal name',
officialOrganizationalRole: 'my official role',
}
);
let edgeData =
new edges.OfficialOrganizationalRoleAuthorizationCredentialEdgeData(
{
legalEntityCredentialSAID: 'said',
}
);
let edge = new edges.OfficialOrganizationalRoleAuthorizationEdge({
le: edgeData,
});

le.createOORAuthCredential('issuee aid', data, edge);

let cap = capture(c.issue).last();

verify(
c.issue(
'qvi_name',
'qvi_registry_aid',
'EKA57bKBKxr_kN7iN5i7lMUxpMG-s19dRcmov1iDxz-E',
'issuee aid',
anyOfClass(
credentials.OfficialOrganizationalRoleAuthorizationCredentialData
),
rules.OORAuth,
anyOfClass(edges.OfficialOrganizationalRoleAuthorizationEdge),
false
)
).once();

let DATA_ARG = 4;
expect(cap[DATA_ARG].LEI).toBe('LEI');

let EDGE_ARG = 6;
expect(cap[EDGE_ARG].d).toBe(
'EBlx5jE_cpbCQtypw1WLST-9Dz_PaNoRhgSIma7rWr0L'
);
expect(cap[EDGE_ARG].le.n).toBe('said');
expect(cap[EDGE_ARG].le.s).toBe(
'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY'
);
});
});

0 comments on commit faed701

Please sign in to comment.