|
| 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 | +}); |
0 commit comments