-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
ts/features/itwallet/common/utils/__tests__/itwTrustmarkUtils.test.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,60 @@ | ||
import { getCredentialDocumentNumber } from ".."; | ||
import { Credential } from "@pagopa/io-react-native-wallet"; | ||
import { ItwStoredCredentialsMocks } from "../../../common/utils/itwMocksUtils"; | ||
import { getCredentialDocumentNumber, getCredentialTrustmark } from ".."; | ||
|
||
describe("getCredentialDocumentNumber", () => { | ||
it("should return the document number for a credential", () => { | ||
const documentNumber = getCredentialDocumentNumber( | ||
ItwStoredCredentialsMocks.dc.parsedCredential | ||
jest.mock("@pagopa/io-react-native-wallet", () => ({ | ||
...jest.requireActual("@pagopa/io-react-native-wallet"), | ||
Credential: { | ||
Trustmark: { | ||
getCredentialTrustmark: jest.fn() | ||
} | ||
} | ||
})); | ||
|
||
describe("ITW trustmark utils", () => { | ||
describe("getCredentialDocumentNumber", () => { | ||
it.each([ | ||
["MDL", ItwStoredCredentialsMocks.mdl, "RM8375131N"], | ||
["DC", ItwStoredCredentialsMocks.dc, "10008581"], | ||
["EID", ItwStoredCredentialsMocks.eid, undefined], | ||
["TS", ItwStoredCredentialsMocks.ts, undefined] | ||
])( | ||
"should return the document number for %s", | ||
(_, { parsedCredential }, expected) => { | ||
expect(getCredentialDocumentNumber(parsedCredential)).toBe(expected); | ||
} | ||
); | ||
expect(documentNumber).toBe("10008581"); | ||
}); | ||
|
||
it("should return undefined if the document number is not present", () => { | ||
const documentNumber = getCredentialDocumentNumber( | ||
ItwStoredCredentialsMocks.eid.parsedCredential | ||
); | ||
expect(documentNumber).toBeUndefined(); | ||
describe("getCredentialTrustmark", () => { | ||
it("should return the trustmark", async () => { | ||
jest | ||
.spyOn(Credential.Trustmark, "getCredentialTrustmark") | ||
.mockReturnValueOnce( | ||
Promise.resolve({ | ||
jwt: "testJwt", | ||
expirationTime: 1000 | ||
}) | ||
); | ||
|
||
const trustmark = await getCredentialTrustmark( | ||
"walletInstanceAttestation", | ||
ItwStoredCredentialsMocks.mdl, | ||
"https://verifier.url" | ||
); | ||
|
||
expect(Credential.Trustmark.getCredentialTrustmark).toHaveBeenCalledWith({ | ||
walletInstanceAttestation: "walletInstanceAttestation", | ||
wiaCryptoContext: expect.any(Object), | ||
credentialType: "MDL", | ||
docNumber: "RM8375131N" | ||
}); | ||
|
||
expect(trustmark).toStrictEqual({ | ||
jwt: "testJwt", | ||
expirationTime: 1000, | ||
url: "https://verifier.url?tm=testJwt" | ||
}); | ||
}); | ||
}); | ||
}); |