Skip to content

Commit

Permalink
feat: getInvestorUniquenessClaims method
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Dec 23, 2020
1 parent 3d50158 commit 61bc1cc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Claims.ts
Expand Up @@ -312,7 +312,7 @@ export class Claims {

const result = await context.getIdentityClaimsFromChain({
targets: [did],
claimTypes: [ClaimType.CustomerDueDiligence],
claimTypes: [ClaimType.InvestorUniqueness],
includeExpired,
});

Expand Down
38 changes: 38 additions & 0 deletions src/__tests__/Claims.ts
Expand Up @@ -608,6 +608,44 @@ describe('Claims Class', () => {
});
});

describe('method: getInvestorUniquenessClaims', () => {
test('should return a list of claim data', async () => {
const target = 'someTarget';

const scope = {
type: ScopeType.Identity,
value: 'someIdentityScope',
};

const getIdentityClaimsFromChain: ClaimData[] = [
{
target: entityMockUtils.getIdentityInstance({ did: target }),
issuer: entityMockUtils.getIdentityInstance({ did: 'otherDid' }),
issuedAt: new Date(),
expiry: null,
claim: {
type: ClaimType.InvestorUniqueness,
scope,
cddId: 'someCddId',
scopeId: 'someScopeId',
},
},
];

dsMockUtils.configureMocks({
contextOptions: {
getIdentityClaimsFromChain,
},
});

let result = await claims.getInvestorUniquenessClaims({ target });
expect(result).toEqual(getIdentityClaimsFromChain);

result = await claims.getInvestorUniquenessClaims();
expect(result).toEqual(getIdentityClaimsFromChain);
});
});

test('should return a list of claims issued with an Identity as target and a given Scope', async () => {
const did = 'someDid';
const issuerDid = 'someIssuerDid';
Expand Down
2 changes: 1 addition & 1 deletion src/base/Context.ts
Expand Up @@ -594,7 +594,7 @@ export class Context {
/**
* @hidden
*/
private async getIdentityClaimsFromChain(args: {
public async getIdentityClaimsFromChain(args: {
targets: (string | Identity)[];
claimTypes: ClaimType[];
trustedClaimIssuers?: (string | Identity)[];
Expand Down
11 changes: 11 additions & 0 deletions src/testUtils/mocks/dataSources.ts
Expand Up @@ -215,6 +215,7 @@ interface ContextOptions {
currentPairAddress?: string;
currentPairIsLocked?: boolean;
issuedClaims?: ResultSet<ClaimData>;
getIdentityClaimsFromChain?: ClaimData[];
primaryKey?: string;
secondaryKeys?: SecondaryKey[];
transactionHistory?: ResultSet<ExtrinsicData>;
Expand Down Expand Up @@ -451,6 +452,15 @@ const defaultContextOptions: ContextOptions = {
next: 1,
count: 1,
},
getIdentityClaimsFromChain: [
{
target: ('targetIdentity' as unknown) as Identity,
issuer: ('issuerIdentity' as unknown) as Identity,
issuedAt: new Date(),
expiry: null,
claim: { type: ClaimType.NoData },
},
],
primaryKey: 'primaryKey',
secondaryKeys: [],
transactionHistory: {
Expand Down Expand Up @@ -542,6 +552,7 @@ function configureContext(opts: ContextOptions): void {
getTransactionArguments: sinon.stub().returns([]),
getSecondaryKeys: sinon.stub().returns(opts.secondaryKeys),
issuedClaims: sinon.stub().resolves(opts.issuedClaims),
getIdentityClaimsFromChain: sinon.stub().resolves(opts.getIdentityClaimsFromChain),
getLatestBlock: sinon.stub().resolves(opts.latestBlock),
isMiddlewareEnabled: sinon.stub().returns(opts.middlewareEnabled),
isMiddlewareAvailable: sinon.stub().resolves(opts.middlewareAvailable),
Expand Down

0 comments on commit 61bc1cc

Please sign in to comment.