Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoenig134 committed Oct 23, 2024
1 parent 206f5ce commit f191c27
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/runtime/test/modules/RequestModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,61 @@ describe("Handling the rejection and the revocation of a Relationship by the Req
return sRelationship;
}
});

describe("Handle Multiple RelationshipTemplate loadings", () => {
const runtimeServiceProvider = new RuntimeServiceProvider();
let sRuntimeServices: TestRuntimeServices;
let rRuntimeServices: TestRuntimeServices;

beforeAll(async () => {
const runtimeServices = await runtimeServiceProvider.launch(2, { enableRequestModule: true, enableDeciderModule: true });

sRuntimeServices = runtimeServices[0];
rRuntimeServices = runtimeServices[1];
}, 30000);

beforeEach(() => {
sRuntimeServices.eventBus.reset();
rRuntimeServices.eventBus.reset();
});

afterEach(() => {
sRuntimeServices.eventBus.reset();
rRuntimeServices.eventBus.reset();
});

afterAll(async () => await runtimeServiceProvider.stop());

test("no multiple open Requests that lead to a Relationship can exist for the same Identity", async () => {
const relationshipTemplateContent = RelationshipTemplateContent.from({
onNewRelationship: { "@type": "Request", items: [{ "@type": "TestRequestItem", mustBeAccepted: false }] }
}).toJSON();

const firstTemplate = await exchangeTemplate(sRuntimeServices.transport, rRuntimeServices.transport, relationshipTemplateContent);
await rRuntimeServices.eventBus.waitForRunningEventHandlers();
await expect(rRuntimeServices.eventBus).toHavePublished(
RelationshipTemplateProcessedEvent,
(e) => e.data.result === RelationshipTemplateProcessedResult.ManualRequestDecisionRequired
);

const requestForTemplate = (await rRuntimeServices.consumption.incomingRequests.getRequests({ query: { "source.reference": firstTemplate.id } })).value[0];

rRuntimeServices.eventBus.reset();

const secondTemplate = await exchangeTemplate(sRuntimeServices.transport, rRuntimeServices.transport, relationshipTemplateContent);
await rRuntimeServices.eventBus.waitForRunningEventHandlers();

await expect(rRuntimeServices.eventBus).not.toHavePublished(
RelationshipTemplateProcessedEvent,
(e) => e.data.result === RelationshipTemplateProcessedResult.ManualRequestDecisionRequired
);

await expect(rRuntimeServices.eventBus).toHavePublished(
RelationshipTemplateProcessedEvent,
(e) =>
e.data.result === RelationshipTemplateProcessedResult.NonCompletedRequestExists &&
e.data.template.id === secondTemplate.id &&
e.data.requestId === requestForTemplate.id
);
});
});

0 comments on commit f191c27

Please sign in to comment.