1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
import { pactWith } from 'jest-pact';
import { DiffsBatch } from '../../../fixtures/project/merge_request/diffs_batch.fixture';
import { Discussions } from '../../../fixtures/project/merge_request/discussions.fixture';
import { DiffsMetadata } from '../../../fixtures/project/merge_request/diffs_metadata.fixture';
import {
getDiffsBatch,
getDiffsMetadata,
getDiscussions,
} from '../../../resources/api/project/merge_requests';
const CONSUMER_NAME = 'MergeRequest#show';
const CONSUMER_LOG = '../logs/consumer.log';
const CONTRACT_DIR = '../contracts/project/merge_request/show';
const DIFFS_BATCH_PROVIDER_NAME = 'Merge Request Diffs Batch Endpoint';
const DISCUSSIONS_PROVIDER_NAME = 'Merge Request Discussions Endpoint';
const DIFFS_METADATA_PROVIDER_NAME = 'Merge Request Diffs Metadata Endpoint';
// API endpoint: /merge_requests/:id/diffs_batch.json
pactWith(
{
consumer: CONSUMER_NAME,
provider: DIFFS_BATCH_PROVIDER_NAME,
log: CONSUMER_LOG,
dir: CONTRACT_DIR,
},
(provider) => {
describe(DIFFS_BATCH_PROVIDER_NAME, () => {
beforeEach(() => {
const interaction = {
...DiffsBatch.scenario,
...DiffsBatch.request,
willRespondWith: DiffsBatch.success,
};
provider.addInteraction(interaction);
});
it('returns a successful body', async () => {
const diffsBatch = await getDiffsBatch({
url: provider.mockService.baseUrl,
});
expect(diffsBatch).toEqual(DiffsBatch.body);
});
});
},
);
pactWith(
{
consumer: CONSUMER_NAME,
provider: DISCUSSIONS_PROVIDER_NAME,
log: CONSUMER_LOG,
dir: CONTRACT_DIR,
},
(provider) => {
describe(DISCUSSIONS_PROVIDER_NAME, () => {
beforeEach(() => {
const interaction = {
...Discussions.scenario,
...Discussions.request,
willRespondWith: Discussions.success,
};
provider.addInteraction(interaction);
});
it('return a successful body', async () => {
const discussions = await getDiscussions({
url: provider.mockService.baseUrl,
});
expect(discussions).toEqual(Discussions.body);
});
});
},
);
pactWith(
{
consumer: CONSUMER_NAME,
provider: DIFFS_METADATA_PROVIDER_NAME,
log: CONSUMER_LOG,
dir: CONTRACT_DIR,
},
(provider) => {
describe(DIFFS_METADATA_PROVIDER_NAME, () => {
beforeEach(() => {
const interaction = {
...DiffsMetadata.scenario,
...DiffsMetadata.request,
willRespondWith: DiffsMetadata.success,
};
provider.addInteraction(interaction);
});
it('return a successful body', async () => {
const diffsMetadata = await getDiffsMetadata({
url: provider.mockService.baseUrl,
});
expect(diffsMetadata).toEqual(DiffsMetadata.body);
});
});
},
);
|