Skip to content

Commit a14daad

Browse files
committed
test: test and assert more stuff
1 parent 825cbb6 commit a14daad

File tree

2 files changed

+90
-4
lines changed

2 files changed

+90
-4
lines changed

packages/app-runtime/test/lib/MockUIBridge.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export class MockUIBridge implements IUIBridge {
1616
public reset(): void {
1717
this._passwordToReturn = undefined;
1818
this._accountIdToReturn = undefined;
19+
20+
this._showDeviceOnboardingCalls = [];
21+
this._requestAccountSelectionCalls = [];
22+
this._enterPasswordCalls = [];
1923
}
2024

2125
public showMessage(_account: LocalAccountDTO, _relationship: IdentityDVO, _message: MessageDVO | MailDVO | RequestMessageDVO): Promise<Result<void>> {
@@ -30,8 +34,19 @@ export class MockUIBridge implements IUIBridge {
3034
throw new Error("Method not implemented.");
3135
}
3236

33-
public showDeviceOnboarding(_deviceOnboardingInfo: DeviceOnboardingInfoDTO): Promise<Result<void>> {
34-
throw new Error("Method not implemented.");
37+
public showDeviceOnboarding(deviceOnboardingInfo: DeviceOnboardingInfoDTO): Promise<Result<void>> {
38+
this._showDeviceOnboardingCalls.push(deviceOnboardingInfo);
39+
40+
return Promise.resolve(Result.ok(undefined));
41+
}
42+
43+
private _showDeviceOnboardingCalls: DeviceOnboardingInfoDTO[] = [];
44+
public showDeviceOnboardingCalled(deviceId: string): boolean {
45+
return this._showDeviceOnboardingCalls.some((x) => x.id === deviceId);
46+
}
47+
48+
public showDeviceOnboardingNotCalled(): boolean {
49+
return this._showDeviceOnboardingCalls.length === 0;
3550
}
3651

3752
public showRequest(_account: LocalAccountDTO, _request: LocalRequestDVO): Promise<Result<void>> {
@@ -42,7 +57,9 @@ export class MockUIBridge implements IUIBridge {
4257
throw new Error("Method not implemented.");
4358
}
4459

45-
public requestAccountSelection(possibleAccounts: LocalAccountDTO[], _title?: string, _description?: string): Promise<Result<LocalAccountDTO | undefined>> {
60+
public requestAccountSelection(possibleAccounts: LocalAccountDTO[], title?: string, description?: string): Promise<Result<LocalAccountDTO | undefined>> {
61+
this._requestAccountSelectionCalls.push({ possibleAccounts: possibleAccounts, title: title, description: description });
62+
4663
if (!this._accountIdToReturn) return Promise.resolve(Result.fail(new ApplicationError("code", "message")));
4764

4865
const foundAccount = possibleAccounts.find((x) => x.id === this._accountIdToReturn);
@@ -51,9 +68,29 @@ export class MockUIBridge implements IUIBridge {
5168
return Promise.resolve(Result.ok(foundAccount));
5269
}
5370

54-
public enterPassword(_passwordType: "pw" | "pin", _pinLength?: number): Promise<Result<string>> {
71+
private _requestAccountSelectionCalls: { possibleAccounts: LocalAccountDTO[]; title?: string; description?: string }[] = [];
72+
public requestAccountSelectionCalled(possibleAccountsLength: number): boolean {
73+
return this._requestAccountSelectionCalls.some((x) => x.possibleAccounts.length === possibleAccountsLength);
74+
}
75+
76+
public requestAccountSelectionNotCalled(): boolean {
77+
return this._requestAccountSelectionCalls.length === 0;
78+
}
79+
80+
public enterPassword(passwordType: "pw" | "pin", pinLength?: number): Promise<Result<string>> {
81+
this._enterPasswordCalls.push({ passwordType: passwordType, pinLength: pinLength });
82+
5583
if (!this._passwordToReturn) return Promise.resolve(Result.fail(new ApplicationError("code", "message")));
5684

5785
return Promise.resolve(Result.ok(this._passwordToReturn));
5886
}
87+
88+
private _enterPasswordCalls: { passwordType: "pw" | "pin"; pinLength?: number }[] = [];
89+
public enterPasswordCalled(passwordType: "pw" | "pin", pinLength?: number): boolean {
90+
return this._enterPasswordCalls.some((x) => x.passwordType === passwordType && x.pinLength === pinLength);
91+
}
92+
93+
public enterPasswordNotCalled(): boolean {
94+
return this._enterPasswordCalls.length === 0;
95+
}
5996
}

packages/app-runtime/test/runtime/AppStringProcessor.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ describe("AppStringProcessor", function () {
4747
expect(result.isError).toBeDefined();
4848

4949
expect(result.error.code).toBe("error.appStringProcessor.truncatedReferenceInvalid");
50+
51+
expect(mockUiBridge.enterPasswordNotCalled()).toBeTruthy();
52+
expect(mockUiBridge.requestAccountSelectionNotCalled()).toBeTruthy();
5053
});
5154

5255
test("should properly handle a personalized RelationshipTemplate with the correct Identity available", async function () {
@@ -63,6 +66,9 @@ describe("AppStringProcessor", function () {
6366
expect(result).toBeSuccessful();
6467

6568
await expect(eventBus).toHavePublished(PeerRelationshipTemplateLoadedEvent);
69+
70+
expect(mockUiBridge.enterPasswordNotCalled()).toBeTruthy();
71+
expect(mockUiBridge.requestAccountSelectionNotCalled()).toBeTruthy();
6672
});
6773

6874
test("should properly handle a personalized RelationshipTemplate with the correct Identity not available", async function () {
@@ -77,6 +83,9 @@ describe("AppStringProcessor", function () {
7783

7884
const result = await runtime2.stringProcessor.processTruncatedReference(templateResult.value.truncatedReference);
7985
expect(result).toBeAnError("There is no account matching the given 'forIdentityTruncated'.", "error.appruntime.general.noAccountAvailableForIdentityTruncated");
86+
87+
expect(mockUiBridge.enterPasswordNotCalled()).toBeTruthy();
88+
expect(mockUiBridge.requestAccountSelectionNotCalled()).toBeTruthy();
8089
});
8190

8291
test("should properly handle a password protected RelationshipTemplate", async function () {
@@ -94,6 +103,9 @@ describe("AppStringProcessor", function () {
94103
expect(result.value).toBeUndefined();
95104

96105
await expect(eventBus).toHavePublished(PeerRelationshipTemplateLoadedEvent);
106+
107+
expect(mockUiBridge.enterPasswordCalled("pw")).toBeTruthy();
108+
expect(mockUiBridge.requestAccountSelectionCalled(2)).toBeTruthy();
97109
});
98110

99111
test("should properly handle a pin protected RelationshipTemplate", async function () {
@@ -111,6 +123,9 @@ describe("AppStringProcessor", function () {
111123
expect(result.value).toBeUndefined();
112124

113125
await expect(eventBus).toHavePublished(PeerRelationshipTemplateLoadedEvent);
126+
127+
expect(mockUiBridge.enterPasswordCalled("pin", 6)).toBeTruthy();
128+
expect(mockUiBridge.requestAccountSelectionCalled(2)).toBeTruthy();
114129
});
115130

116131
test("should properly handle a password protected personalized RelationshipTemplate", async function () {
@@ -128,6 +143,9 @@ describe("AppStringProcessor", function () {
128143
expect(result.value).toBeUndefined();
129144

130145
await expect(eventBus).toHavePublished(PeerRelationshipTemplateLoadedEvent);
146+
147+
expect(mockUiBridge.enterPasswordCalled("pw")).toBeTruthy();
148+
expect(mockUiBridge.requestAccountSelectionNotCalled()).toBeTruthy();
131149
});
132150

133151
test("should properly handle a pin protected personalized RelationshipTemplate", async function () {
@@ -145,5 +163,36 @@ describe("AppStringProcessor", function () {
145163
expect(result.value).toBeUndefined();
146164

147165
await expect(eventBus).toHavePublished(PeerRelationshipTemplateLoadedEvent);
166+
167+
expect(mockUiBridge.enterPasswordCalled("pin", 6)).toBeTruthy();
168+
expect(mockUiBridge.requestAccountSelectionNotCalled()).toBeTruthy();
169+
});
170+
171+
describe("onboarding", function () {
172+
let runtime3: AppRuntime;
173+
const runtime3MockUiBridge = new MockUIBridge();
174+
175+
beforeAll(async function () {
176+
runtime3 = await TestUtil.createRuntime(undefined, runtime3MockUiBridge, eventBus);
177+
await runtime3.start();
178+
});
179+
180+
afterAll(async () => await runtime3.stop());
181+
182+
test("device onboarding with a password protected Token", async function () {
183+
const deviceResult = await runtime1Session.transportServices.devices.createDevice({});
184+
const tokenResult = await runtime1Session.transportServices.devices.getDeviceOnboardingToken({
185+
id: deviceResult.value.id,
186+
passwordProtection: { password: "password" }
187+
});
188+
189+
mockUiBridge.passwordToReturn = "password";
190+
191+
const result = await runtime2.stringProcessor.processTruncatedReference(tokenResult.value.truncatedReference);
192+
expect(result).toBeSuccessful();
193+
expect(result.value).toBeUndefined();
194+
195+
expect(mockUiBridge.showDeviceOnboardingCalled(deviceResult.value.id)).toBeTruthy();
196+
});
148197
});
149198
});

0 commit comments

Comments
 (0)