Skip to content

Commit f191c27

Browse files
committed
chore: add test
1 parent 206f5ce commit f191c27

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

packages/runtime/test/modules/RequestModule.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,3 +584,61 @@ describe("Handling the rejection and the revocation of a Relationship by the Req
584584
return sRelationship;
585585
}
586586
});
587+
588+
describe("Handle Multiple RelationshipTemplate loadings", () => {
589+
const runtimeServiceProvider = new RuntimeServiceProvider();
590+
let sRuntimeServices: TestRuntimeServices;
591+
let rRuntimeServices: TestRuntimeServices;
592+
593+
beforeAll(async () => {
594+
const runtimeServices = await runtimeServiceProvider.launch(2, { enableRequestModule: true, enableDeciderModule: true });
595+
596+
sRuntimeServices = runtimeServices[0];
597+
rRuntimeServices = runtimeServices[1];
598+
}, 30000);
599+
600+
beforeEach(() => {
601+
sRuntimeServices.eventBus.reset();
602+
rRuntimeServices.eventBus.reset();
603+
});
604+
605+
afterEach(() => {
606+
sRuntimeServices.eventBus.reset();
607+
rRuntimeServices.eventBus.reset();
608+
});
609+
610+
afterAll(async () => await runtimeServiceProvider.stop());
611+
612+
test("no multiple open Requests that lead to a Relationship can exist for the same Identity", async () => {
613+
const relationshipTemplateContent = RelationshipTemplateContent.from({
614+
onNewRelationship: { "@type": "Request", items: [{ "@type": "TestRequestItem", mustBeAccepted: false }] }
615+
}).toJSON();
616+
617+
const firstTemplate = await exchangeTemplate(sRuntimeServices.transport, rRuntimeServices.transport, relationshipTemplateContent);
618+
await rRuntimeServices.eventBus.waitForRunningEventHandlers();
619+
await expect(rRuntimeServices.eventBus).toHavePublished(
620+
RelationshipTemplateProcessedEvent,
621+
(e) => e.data.result === RelationshipTemplateProcessedResult.ManualRequestDecisionRequired
622+
);
623+
624+
const requestForTemplate = (await rRuntimeServices.consumption.incomingRequests.getRequests({ query: { "source.reference": firstTemplate.id } })).value[0];
625+
626+
rRuntimeServices.eventBus.reset();
627+
628+
const secondTemplate = await exchangeTemplate(sRuntimeServices.transport, rRuntimeServices.transport, relationshipTemplateContent);
629+
await rRuntimeServices.eventBus.waitForRunningEventHandlers();
630+
631+
await expect(rRuntimeServices.eventBus).not.toHavePublished(
632+
RelationshipTemplateProcessedEvent,
633+
(e) => e.data.result === RelationshipTemplateProcessedResult.ManualRequestDecisionRequired
634+
);
635+
636+
await expect(rRuntimeServices.eventBus).toHavePublished(
637+
RelationshipTemplateProcessedEvent,
638+
(e) =>
639+
e.data.result === RelationshipTemplateProcessedResult.NonCompletedRequestExists &&
640+
e.data.template.id === secondTemplate.id &&
641+
e.data.requestId === requestForTemplate.id
642+
);
643+
});
644+
});

0 commit comments

Comments
 (0)