Skip to content

Commit 69fbcf5

Browse files
committed
CCM-10483: add user created provider spec file
1 parent 2beaeff commit 69fbcf5

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

.github/workflows/stage-2-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ jobs:
189189

190190
provider-contracts:
191191
name: Provider Contract Tests
192+
needs: consumer-contracts # ensures that the latest consumer contracts are available - probably not needed in reality
192193
runs-on: ubuntu-latest
193194
environment: dev
194195
steps:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { MessageProviderPact } from '@pact-foundation/pact';
4+
5+
// This would be the actual function that produces the event payload in the producer source code
6+
function createUserCreatedEvent() {
7+
return {
8+
'detail-type': 'UserCreated',
9+
source: 'uk.nhs.notify.auth',
10+
time: new Date().toISOString(),
11+
version: '1.0',
12+
detail: {
13+
clientId: '3aef04e4-4491-42ae-b24a-95c66b80cbc9',
14+
userId: 'f58efb29-27a0-4da3-a502-ddd387771c1e',
15+
},
16+
};
17+
}
18+
19+
describe('Pact Message Provider - UserCreated Event', () => {
20+
const pactDir = path.resolve(__dirname, 'pacts');
21+
22+
const messagePact = new MessageProviderPact({
23+
provider: 'auth',
24+
pactUrls: fs
25+
.readdirSync(pactDir)
26+
.filter((f) => f.endsWith('.json'))
27+
.map((f) => path.join(pactDir, f)),
28+
messageProviders: {
29+
UserCreated: () => createUserCreatedEvent(),
30+
},
31+
logLevel: 'error',
32+
});
33+
34+
it('should produce a message that satisfies the consumer contracts for UserCreated', () => {
35+
return messagePact.verify();
36+
});
37+
});

tests/contracts/tests/templates/provider/template-deleted.provider.pact.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Pact Message Provider - TemplateDeleted Event', () => {
3131
logLevel: 'error',
3232
});
3333

34-
it('should produce a message that satisfies the consumer contract for TemplateDeleted', () => {
34+
it('should produce a message that satisfies the consumer contracts for TemplateDeleted', () => {
3535
return messagePact.verify();
3636
});
3737
});

0 commit comments

Comments
 (0)