Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/app-runtime/src/AppStringProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ export class AppStringProcessor {
// RelationshipTemplates are processed by the RequestModule
break;
case "Token":
return Result.fail(AppRuntimeErrors.appStringProcessor.notSupportedTokenContent());
await uiBridge.showToken(account, result.value.value);
break;
case "DeviceOnboardingInfo":
return Result.fail(AppRuntimeErrors.appStringProcessor.deviceOnboardingNotAllowed());
}
Expand Down
3 changes: 2 additions & 1 deletion packages/app-runtime/src/extensibility/ui/IUIBridge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ApplicationError, Result } from "@js-soft/ts-utils";
import { DeviceOnboardingInfoDTO, FileDVO, IdentityDVO, LocalRequestDVO, MailDVO, MessageDVO, RequestMessageDVO } from "@nmshd/runtime";
import { DeviceOnboardingInfoDTO, FileDVO, IdentityDVO, LocalRequestDVO, MailDVO, MessageDVO, RequestMessageDVO, TokenDTO } from "@nmshd/runtime";
import { LocalAccountDTO } from "../../multiAccount";

export interface IUIBridge {
showMessage(account: LocalAccountDTO, relationship: IdentityDVO, message: MessageDVO | MailDVO | RequestMessageDVO): Promise<Result<void>>;
showRelationship(account: LocalAccountDTO, relationship: IdentityDVO): Promise<Result<void>>;
showFile(account: LocalAccountDTO, file: FileDVO): Promise<Result<void>>;
showToken(account: LocalAccountDTO, token: TokenDTO): Promise<Result<void>>;
showDeviceOnboarding(deviceOnboardingInfo: DeviceOnboardingInfoDTO): Promise<Result<void>>;
showRequest(account: LocalAccountDTO, request: LocalRequestDVO): Promise<Result<void>>;
showError(error: ApplicationError, account?: LocalAccountDTO): Promise<Result<void>>;
Expand Down
4 changes: 4 additions & 0 deletions packages/app-runtime/test/lib/FakeUIBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class FakeUIBridge implements IUIBridge {
return Promise.resolve(Result.ok(undefined));
}

public showToken(): Promise<Result<void, ApplicationError>> {
return Promise.resolve(Result.ok(undefined));
}

public showDeviceOnboarding(): Promise<Result<void, ApplicationError>> {
return Promise.resolve(Result.ok(undefined));
}
Expand Down
33 changes: 33 additions & 0 deletions packages/app-runtime/test/lib/MockUIBridge.matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,38 @@ expect.extend({

return { pass: true, message: () => "" };
},
showTokenCalled(mockUIBridge: unknown, id: string) {
if (!(mockUIBridge instanceof MockUIBridge)) {
throw new Error("This method can only be used with expect(MockUIBridge).");
}

const calls = mockUIBridge.calls.filter((x) => x.method === "showToken");
if (calls.length === 0) {
return { pass: false, message: () => "The method showToken was not called." };
}

const matchingCalls = calls.filter((x) => x.token.id === id);
if (matchingCalls.length === 0) {
return {
pass: false,
message: () => `The method showToken was called, but not with the specified token id '${id}', instead with ids '${calls.map((e) => e.token.id).join(", ")}'.`
};
}

return { pass: true, message: () => "" };
},
showTokenNotCalled(mockUIBridge: unknown) {
if (!(mockUIBridge instanceof MockUIBridge)) {
throw new Error("This method can only be used with expect(MockUIBridge).");
}

const calls = mockUIBridge.calls.filter((x) => x.method === "showToken");
if (calls.length > 0) {
return { pass: false, message: () => `The method showToken called: ${calls.map((c) => `'account id: ${c.account.id} - tokenId: ${c.token.id}'`)}` };
}

return { pass: true, message: () => "" };
},
showErrorCalled(mockUIBridge: unknown, code: string) {
if (!(mockUIBridge instanceof MockUIBridge)) {
throw new Error("This method can only be used with expect(MockUIBridge).");
Expand Down Expand Up @@ -201,6 +233,7 @@ declare global {
showRequestNotCalled(): R;
showFileCalled(id: string): R;
showFileNotCalled(): R;
showTokenCalled(id: string): R;
showErrorCalled(code: string): R;
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/app-runtime/test/lib/MockUIBridge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ApplicationError, Result } from "@js-soft/ts-utils";
import { DeviceOnboardingInfoDTO, FileDVO, IdentityDVO, LocalRequestDVO, MailDVO, MessageDVO, RequestMessageDVO } from "@nmshd/runtime";
import { DeviceOnboardingInfoDTO, FileDVO, IdentityDVO, LocalRequestDVO, MailDVO, MessageDVO, RequestMessageDVO, TokenDTO } from "@nmshd/runtime";
import { IUIBridge, LocalAccountDTO } from "../../src";

export type MockUIBridgeCall =
| { method: "showMessage"; account: LocalAccountDTO; relationship: IdentityDVO; message: MessageDVO | MailDVO | RequestMessageDVO }
| { method: "showRelationship"; account: LocalAccountDTO; relationship: IdentityDVO }
| { method: "showFile"; account: LocalAccountDTO; file: FileDVO }
| { method: "showToken"; account: LocalAccountDTO; token: TokenDTO }
| { method: "showDeviceOnboarding"; deviceOnboardingInfo: DeviceOnboardingInfoDTO }
| { method: "showRequest"; account: LocalAccountDTO; request: LocalRequestDVO }
| { method: "showError"; error: ApplicationError; account?: LocalAccountDTO }
Expand Down Expand Up @@ -53,6 +54,12 @@ export class MockUIBridge implements IUIBridge {
return Promise.resolve(Result.ok(undefined));
}

public showToken(account: LocalAccountDTO, token: TokenDTO): Promise<Result<void>> {
this._calls.push({ method: "showToken", account, token });

return Promise.resolve(Result.ok(undefined));
}

public showDeviceOnboarding(deviceOnboardingInfo: DeviceOnboardingInfoDTO): Promise<Result<void>> {
this._calls.push({ method: "showDeviceOnboarding", deviceOnboardingInfo });

Expand Down
15 changes: 15 additions & 0 deletions packages/app-runtime/test/runtime/AppStringProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,21 @@ describe("AppStringProcessor", function () {
expect(runtime4MockUiBridge).showFileCalled(file.id);
});

test("get a token using a url", async function () {
const tokenResult = await runtime1Session.transportServices.tokens.createOwnToken({
content: { custom: "tokenContent" },
expiresAt: CoreDate.utc().add({ days: 1 }).toISOString(),
ephemeral: true
});
const token = tokenResult.value;

const result = await runtime4.stringProcessor.processURL(token.reference.url, runtime4Session.account);
expect(result).toBeSuccessful();
expect(result.value).toBeUndefined();

expect(runtime4MockUiBridge).showTokenCalled(token.id);
});

test("get a template using a url", async function () {
const templateResult = await runtime1Session.transportServices.relationshipTemplates.createOwnRelationshipTemplate({
content: RelationshipTemplateContent.from({
Expand Down