Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 committed Dec 4, 2024
1 parent 3248f79 commit 777b370
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jest.mock("../../../../../config", () => ({
itwEnabled: true
}));

jest.mock("../../../../../store/reducers/cie", () => ({
isCieSupportedSelector: () => true
jest.mock("../../../machine/eid/selectors", () => ({
isCIEAuthenticationSupportedSelector: () => true
}));

describe("ItwIdentificationModeSelectionScreen", () => {
Expand Down
75 changes: 51 additions & 24 deletions ts/features/itwallet/machine/eid/__tests__/machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ItwStoredCredentialsMocks } from "../../../common/utils/itwMocksUtils";
import { StoredCredential } from "../../../common/utils/itwTypesUtils";
import { ItwTags } from "../../tags";
import {
CheckCIECapabilitiesActorOutput,
GetAuthRedirectUrlActorParam,
GetWalletAttestationActorParams,
RequestEidActorParams,
Expand Down Expand Up @@ -51,6 +52,7 @@ describe("itwEidIssuanceMachine", () => {
const onInit = jest.fn();

const createWalletInstance = jest.fn();
const checkCIECapabilities = jest.fn();
const getWalletAttestation = jest.fn();
const requestEid = jest.fn();
const startAuthFlow = jest.fn();
Expand Down Expand Up @@ -101,6 +103,8 @@ describe("itwEidIssuanceMachine", () => {
string,
GetWalletAttestationActorParams
>(getWalletAttestation),
checkCIECapabilities:
fromPromise<CheckCIECapabilitiesActorOutput>(checkCIECapabilities),
requestEid: fromPromise<StoredCredential, RequestEidActorParams>(
requestEid
),
Expand All @@ -120,14 +124,6 @@ describe("itwEidIssuanceMachine", () => {
}
});

beforeEach(() => {
onInit.mockImplementation(() => ({
integrityKeyTag: undefined,
walletInstanceAttestation: undefined
}));
hasValidWalletInstanceAttestation.mockImplementation(() => false);
});

afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -320,7 +316,7 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
value: { UserIdentification: "ModeSelection" },
context: {
integrityKeyTag: T_INTEGRITY_KEY,
Expand Down Expand Up @@ -387,11 +383,15 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
value: { UserIdentification: "ModeSelection" },
context: {
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA
walletInstanceAttestation: T_WIA,
cieCapabilities: {
isNFCEnabled: true,
isCIEAuthenticationSupported: true
}
}
} as MachineSnapshot);

Expand All @@ -416,7 +416,11 @@ describe("itwEidIssuanceMachine", () => {
...InitialContext,
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA,
identification: undefined
identification: undefined,
cieCapabilities: {
isNFCEnabled: true,
isCIEAuthenticationSupported: true
}
});
expect(navigateToCiePinScreen).toHaveBeenCalledTimes(1);

Expand All @@ -428,8 +432,7 @@ describe("itwEidIssuanceMachine", () => {

actor.send({
type: "cie-pin-entered",
pin: "12345678",
isNfcEnabled: true
pin: "12345678"
});

expect(actor.getSnapshot().value).toStrictEqual({
Expand All @@ -444,6 +447,10 @@ describe("itwEidIssuanceMachine", () => {
identification: {
mode: "ciePin",
pin: "12345678"
},
cieCapabilities: {
isNFCEnabled: true,
isCIEAuthenticationSupported: true
}
});
expect(actor.getSnapshot().tags).toStrictEqual(new Set([ItwTags.Loading]));
Expand Down Expand Up @@ -488,15 +495,19 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
value: {
UserIdentification: {
CiePin: "InsertingCardPin"
}
},
context: {
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA
walletInstanceAttestation: T_WIA,
cieCapabilities: {
isNFCEnabled: false,
isCIEAuthenticationSupported: true
}
}
} as MachineSnapshot);

Expand All @@ -511,13 +522,12 @@ describe("itwEidIssuanceMachine", () => {

actor.send({
type: "cie-pin-entered",
pin: "12345678",
isNfcEnabled: false
pin: "12345678"
});

expect(actor.getSnapshot().value).toStrictEqual({
UserIdentification: {
CiePin: "ActivateNfc"
CiePin: "RequestingNfcActivation"
}
});
expect(actor.getSnapshot().tags).toStrictEqual(new Set());
Expand All @@ -528,6 +538,10 @@ describe("itwEidIssuanceMachine", () => {
identification: {
mode: "ciePin",
pin: "12345678"
},
cieCapabilities: {
isNFCEnabled: false,
isCIEAuthenticationSupported: true
}
});
expect(navigateToNfcInstructionsScreen).toHaveBeenCalledTimes(1);
Expand All @@ -545,6 +559,19 @@ describe("itwEidIssuanceMachine", () => {
CiePin: "StartingCieAuthFlow"
}
});
expect(actor.getSnapshot().context).toStrictEqual<Context>({
...InitialContext,
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA,
identification: {
mode: "ciePin",
pin: "12345678"
},
cieCapabilities: {
isNFCEnabled: true,
isCIEAuthenticationSupported: true
}
});

/** Last part is the same as the previous test */
});
Expand All @@ -554,7 +581,7 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
context: {
integrityKeyTag: T_INTEGRITY_KEY
}
Expand Down Expand Up @@ -603,7 +630,7 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
context: {
integrityKeyTag: T_INTEGRITY_KEY,
walletInstanceAttestation: T_WIA
Expand Down Expand Up @@ -655,7 +682,7 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
value: "Success"
} as MachineSnapshot);

Expand Down Expand Up @@ -846,7 +873,7 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
value: { UserIdentification: "ModeSelection" }
} as MachineSnapshot);

Expand Down Expand Up @@ -917,7 +944,7 @@ describe("itwEidIssuanceMachine", () => {
itwEidIssuanceMachine
).getSnapshot();

const snapshot: MachineSnapshot = _.merge(initialSnapshot, {
const snapshot: MachineSnapshot = _.merge(undefined, initialSnapshot, {
value: "Failure"
} as MachineSnapshot);

Expand Down

0 comments on commit 777b370

Please sign in to comment.