-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The RequestModule creates expired requests in the `PeerRelationshipTe…
…mplateLoaded` event handler (#427) * fix: add new event type * fix: trigger new event type * fix: handle new event type * chore: simplify testutil * test: add matchers * test: add tests for RelationshipTemplateProcessedModule * chore: wording
- Loading branch information
1 parent
7dadb23
commit 40345c6
Showing
6 changed files
with
153 additions
and
12 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
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
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
72 changes: 72 additions & 0 deletions
72
packages/app-runtime/test/modules/appEvents/RelationshipTemplateProcessedModule.test.ts
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { sleep } from "@js-soft/ts-utils"; | ||
import { AuthenticationRequestItem, RelationshipTemplateContent } from "@nmshd/content"; | ||
import { CoreDate } from "@nmshd/core-types"; | ||
import assert from "assert"; | ||
import { AppRuntime, LocalAccountSession } from "../../../src"; | ||
import { MockEventBus, MockUIBridge, TestUtil } from "../../lib"; | ||
|
||
describe("RelationshipTemplateProcessedModule", function () { | ||
const uiBridge = new MockUIBridge(); | ||
const eventBus = new MockEventBus(); | ||
|
||
let runtime1: AppRuntime; | ||
let session1: LocalAccountSession; | ||
let session2: LocalAccountSession; | ||
|
||
beforeAll(async function () { | ||
runtime1 = await TestUtil.createRuntime(undefined, uiBridge, eventBus); | ||
await runtime1.start(); | ||
|
||
const [localAccount1, localAccount2] = await TestUtil.provideAccounts(runtime1, 2); | ||
|
||
session1 = await runtime1.selectAccount(localAccount1.id); | ||
session2 = await runtime1.selectAccount(localAccount2.id); | ||
}); | ||
|
||
afterAll(async function () { | ||
await runtime1.stop(); | ||
}); | ||
|
||
afterEach(async function () { | ||
uiBridge.reset(); | ||
eventBus.reset(); | ||
|
||
const incomingRequests = await session2.consumptionServices.incomingRequests.getRequests({ query: { status: ["Open", "DecisionRequired", "ManualDecisionRequired"] } }); | ||
for (const request of incomingRequests.value) { | ||
const response = await session2.consumptionServices.incomingRequests.reject({ requestId: request.id, items: [{ accept: false }] }); | ||
assert(response.isSuccess); | ||
} | ||
|
||
await eventBus.waitForRunningEventHandlers(); | ||
}); | ||
|
||
test("should show request when RelationshipTemplateProcessedEvent is received with ManualRequestDecisionRequired", async function () { | ||
await TestUtil.createAndLoadPeerTemplate( | ||
session1, | ||
session2, | ||
RelationshipTemplateContent.from({ onNewRelationship: { items: [AuthenticationRequestItem.from({ mustBeAccepted: false })] } }).toJSON() | ||
); | ||
await eventBus.waitForRunningEventHandlers(); | ||
|
||
expect(uiBridge).showRequestCalled(); | ||
}); | ||
|
||
test("should show an error when RelationshipTemplateProcessedEvent is received with an expired Request", async function () { | ||
const templateFrom = ( | ||
await session1.transportServices.relationshipTemplates.createOwnRelationshipTemplate({ | ||
content: RelationshipTemplateContent.from({ | ||
onNewRelationship: { expiresAt: CoreDate.utc().add({ seconds: 2 }), items: [AuthenticationRequestItem.from({ mustBeAccepted: false })] } | ||
}).toJSON(), | ||
expiresAt: CoreDate.utc().add({ minutes: 5 }).toString(), | ||
maxNumberOfAllocations: 1 | ||
}) | ||
).value; | ||
|
||
await sleep(3000); | ||
await session2.transportServices.relationshipTemplates.loadPeerRelationshipTemplate({ reference: templateFrom.truncatedReference }); | ||
await eventBus.waitForRunningEventHandlers(); | ||
|
||
expect(uiBridge).showRequestNotCalled(); | ||
expect(uiBridge).showErrorCalled("error.relationshipTemplateProcessedModule.requestExpired"); | ||
}); | ||
}); |
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
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