Skip to content

Commit

Permalink
test(identity): improves testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gdixon authored and shavinac committed Apr 12, 2022
1 parent f692259 commit f6fee0f
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 167 deletions.
4 changes: 2 additions & 2 deletions iam/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
/dist/*
/coverage/*
/node_modules/*
**/__mocks__/**/*
**/__tests__/**/*
/__mocks__/**/*
/__tests__/**/*
4 changes: 2 additions & 2 deletions iam/src/providers/simple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ----- Types
import { Provider, ProviderOptions } from "../types";
import { RequestPayload, VerifiedPayload } from "@dpopp/types";
import type { Provider, ProviderOptions } from "../types";
import type { RequestPayload, VerifiedPayload } from "@dpopp/types";

// Export a simple Provider as an example
export class SimpleProvider implements Provider {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions iam/src/utils/providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---- Types
import { Provider } from "../types";
import { RequestPayload, ChallengePayload, VerifiedPayload } from "@dpopp/types";
import type { Provider } from "../types";
import type { RequestPayload, ChallengePayload, VerifiedPayload } from "@dpopp/types";

// ---- Return randomBytes as a challenge to test that the user has control of a provided address
import crypto from "crypto";
Expand Down
4 changes: 2 additions & 2 deletions identity/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
/node_modules/*
/src/didkit-node/*
/src/didkit-browser/*
**/__mocks__/**/*
**/__tests__/**/*
/__mocks__/**/*
/__tests__/**/*
20 changes: 10 additions & 10 deletions identity/__mocks__/axios.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
module.exports = {
post: async (url, data) => {
post: jest.fn(async (url, data) => {
switch (url) {
case "/vbad/challenge":
case "/vTest-Case-1/challenge":
return {
data: {
credential: {
credentialSubject: {},
credentialSubject: {
challenge: "this is a challenge",
},
},
},
};
case "/vbad/verify":
case "/vTest-Case-1/verify":
return {
data: {
credential: {},
record: {},
},
};
case "/v0.0.0/challenge":
case "/vTest-Case-2/challenge":
return {
data: {
credential: {
credentialSubject: {
challenge: "this is a challenge",
},
credentialSubject: {},
},
},
};
case "/v0.0.0/verify":
case "/vTest-Case-2/verify":
return {
data: {
credential: {},
record: {},
},
};
}
},
}),
};
24 changes: 24 additions & 0 deletions identity/__mocks__/didkit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ---- Generate & Verify methods
module.exports = {
keyToDID: jest.fn(() => Promise.resolve("did:key:PUBLIC_KEY")),
keyToVerificationMethod: jest.fn(() => Promise.resolve("did:key:PUBLIC_KEY#PUBLIC_KEY")),
issueCredential: jest.fn((credential) =>
Promise.resolve(
JSON.stringify({
...JSON.parse(credential),
...{
proof: {},
},
})
)
),
verifyCredential: jest.fn(() =>
Promise.resolve(
JSON.stringify({
checks: [],
warnings: [],
errors: [],
})
)
),
};
Loading

0 comments on commit f6fee0f

Please sign in to comment.