Skip to content

Commit 45c1723

Browse files
add contract tests
1 parent 5b8b2de commit 45c1723

File tree

5 files changed

+1018
-1
lines changed

5 files changed

+1018
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/dist
55
/tmp
66
/out-tsc
7+
/pacts
78

89
# dependencies
910
/node_modules
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { pactWith } from 'jest-pact';
2+
import * as path from 'path';
3+
import { InteractionObject } from '@pact-foundation/pact';
4+
import axios from 'axios';
5+
import { integer, eachLike, string } from '@pact-foundation/pact/dsl/matchers';
6+
7+
pactWith({
8+
log: path.resolve(
9+
process.cwd(),
10+
'pacts',
11+
'logs',
12+
'mockserver-integration.log'
13+
),
14+
cors: true,
15+
dir: path.resolve(process.cwd(), 'pacts'),
16+
spec: 3,
17+
logLevel: 'info',
18+
consumer: 'Album_Consumer',
19+
provider: 'Album_Provider',
20+
}, async (provider) => {
21+
test('should be able to load albums', async () => {
22+
const url = `${provider.mockService.baseUrl}`;
23+
const requestPath = '/albums';
24+
const interaction: InteractionObject = {
25+
state: `An album exists`,
26+
uponReceiving: 'A get request to get an album',
27+
withRequest: {
28+
method: 'GET',
29+
path: requestPath,
30+
},
31+
willRespondWith: {
32+
status: 200,
33+
body: eachLike({
34+
userId: integer(1),
35+
id: integer(1),
36+
title: string('sarah'),
37+
}),
38+
headers: {
39+
'Content-Type': 'application/json',
40+
},
41+
},
42+
};
43+
44+
await provider.addInteraction(interaction);
45+
46+
const response = await axios.get(`${url}${requestPath}`);
47+
48+
expect(response.status).toBe(200);
49+
expect(response.data[0].title).toBe('sarah');
50+
});
51+
});

apps/angular-testing/src/app/app.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AlbumService } from './album.service';
44
import { of } from 'rxjs';
55
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
66

7-
it('should be able to load albums', async () => {
7+
test('should be able to load albums', async () => {
88
const albums: Album[] = [
99
{
1010
userId: 1,

0 commit comments

Comments
 (0)