From: Kai Moritz Date: Sat, 11 Oct 2025 18:34:53 +0000 (+0200) Subject: feat: Shared the refinements with the provider X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=9790fd661dbe2ff1ff15729d25d3c4a224be5b93;p=demos%2Fkafka%2Fchat feat: Shared the refinements with the provider --- diff --git a/pacts b/pacts index 3f62f442..9d3b95c2 160000 --- a/pacts +++ b/pacts @@ -1 +1 @@ -Subproject commit 3f62f442fa6cdf81d3a49e55a481fc3374ed852c +Subproject commit 9d3b95c268e7db8710f9b6bd5bd2690bac65a9ab diff --git a/src/app/chatroom/chatroom.service.pact.spec.ts b/src/app/chatroom/chatroom.service.pact.spec.ts index d1080ece..5ab6a71c 100644 --- a/src/app/chatroom/chatroom.service.pact.spec.ts +++ b/src/app/chatroom/chatroom.service.pact.spec.ts @@ -19,9 +19,9 @@ describe('Pact between the ChatroomService and the backend', () => { const EXAMPLE_CHATROOM: Chatroom = { - id: "1", - name: "foo", - shard: 7 + id: "5c73531c-6fc4-426c-adcb-afc5c140a0f7", + name: "FOO", + shard: 2 }; @@ -29,7 +29,8 @@ describe('Pact between the ChatroomService and the backend', () => { await provider .addInteraction() - .given('some chatrooms are known') + .given('there are 10 shards') + .given('chatroom with ID "5c73531c-6fc4-426c-adcb-afc5c140a0f7" exists in shard "2"') .uponReceiving('a request for /list') .withRequest('GET', '/list') .willRespondWith(200, (builder) => { @@ -56,7 +57,8 @@ describe('Pact between the ChatroomService and the backend', () => { await provider .addInteraction() - .given('no chatrooms are known') + .given('there are 10 shards') + .given('there is no chatroom at all') .uponReceiving('a request for /list') .withRequest('GET', '/list') .willRespondWith(200, (builder) => { @@ -79,14 +81,15 @@ describe('Pact between the ChatroomService and the backend', () => { }); }); - it('a request for /1 with header "X-Shard: 7" returns an HTTP 200 and the chatroom, if the chatroom with id "1" exists in shard 7', async () => { + it('a request for "/5c73531c-6fc4-426c-adcb-afc5c140a0f7" with header "X-Shard: 2" returns an HTTP 200 and the chatroom, if the chatroom with id "5c73531c-6fc4-426c-adcb-afc5c140a0f7" exists in shard 2', async () => { await provider .addInteraction() - .given('chatroom with ID "1" exists in shard "7"') - .uponReceiving('a request for /1') - .withRequest('GET', '/1', (builder) => { - builder.headers({ 'X-Shard': 7 }) + .given('there are 10 shards') + .given('chatroom with ID "5c73531c-6fc4-426c-adcb-afc5c140a0f7" exists in shard "2"') + .uponReceiving('a request for /5c73531c-6fc4-426c-adcb-afc5c140a0f7') + .withRequest('GET', '/5c73531c-6fc4-426c-adcb-afc5c140a0f7', (builder) => { + builder.headers({ 'X-Shard': 2 }) }) .willRespondWith(200, (builder) => { builder.headers({ 'Content-Type': 'application/json' }); @@ -102,19 +105,20 @@ describe('Pact between the ChatroomService and the backend', () => { }); const service = TestBed.inject(ChatroomService); - const chatroom = await lastValueFrom(service.getChatroom("7", "1")); + const chatroom = await lastValueFrom(service.getChatroom("2", "5c73531c-6fc4-426c-adcb-afc5c140a0f7")); expect(chatroom).toEqual(EXAMPLE_CHATROOM); }); }); - it('a request for /1 with header "X-Shard: 6" returns HTTP 404, if the chatroom with id "1" exists in shard 7', async () => { + it('a request for /5c73531c-6fc4-426c-adcb-afc5c140a0f7 with header "X-Shard: 6" returns HTTP 404, if the chatroom with id "5c73531c-6fc4-426c-adcb-afc5c140a0f7" exists in shard 2', async () => { await provider .addInteraction() - .given('chatroom with ID "1" exists in shard "7"') - .uponReceiving('a request for /1') - .withRequest('GET', '/1', (builder) => { + .given('there are 10 shards') + .given('chatroom with ID "5c73531c-6fc4-426c-adcb-afc5c140a0f7" exists in shard "2"') + .uponReceiving('a request for /5c73531c-6fc4-426c-adcb-afc5c140a0f7') + .withRequest('GET', '/5c73531c-6fc4-426c-adcb-afc5c140a0f7', (builder) => { builder.headers({ 'X-Shard': 6 }) }) .willRespondWith(404) @@ -132,7 +136,7 @@ describe('Pact between the ChatroomService and the backend', () => { return new Promise((resolve, reject) => { service - .getChatroom("6", "1") + .getChatroom("6", "5c73531c-6fc4-426c-adcb-afc5c140a0f7") .subscribe({ next: (chatrooms) => { reject('a status other than 200 should have rejected the observable')