debian-mirror-gitlab/spec/contracts/consumer/specs/project/merge_requests/show.spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-07-23 23:45:48 +05:30
import { pactWith } from 'jest-pact';
2023-03-04 22:38:38 +05:30
import { DiffsBatch } from '../../../fixtures/project/merge_requests/diffs_batch.fixture';
import { Discussions } from '../../../fixtures/project/merge_requests/discussions.fixture';
import { DiffsMetadata } from '../../../fixtures/project/merge_requests/diffs_metadata.fixture';
2022-07-23 23:45:48 +05:30
import {
getDiffsBatch,
getDiffsMetadata,
getDiscussions,
2022-08-27 11:52:29 +05:30
} from '../../../resources/api/project/merge_requests';
2022-07-23 23:45:48 +05:30
2023-03-04 22:38:38 +05:30
const CONSUMER_NAME = 'MergeRequests#show';
2022-07-23 23:45:48 +05:30
const CONSUMER_LOG = '../logs/consumer.log';
2023-03-04 22:38:38 +05:30
const CONTRACT_DIR = '../contracts/project/merge_requests/show';
const GET_DIFFS_BATCH_PROVIDER_NAME = 'GET diffs batch';
const GET_DISCUSSIONS_PROVIDER_NAME = 'GET discussions';
const GET_DIFFS_METADATA_PROVIDER_NAME = 'GET diffs metadata';
2022-07-23 23:45:48 +05:30
// API endpoint: /merge_requests/:id/diffs_batch.json
pactWith(
{
consumer: CONSUMER_NAME,
2023-03-04 22:38:38 +05:30
provider: GET_DIFFS_BATCH_PROVIDER_NAME,
2022-07-23 23:45:48 +05:30
log: CONSUMER_LOG,
dir: CONTRACT_DIR,
},
(provider) => {
2023-03-04 22:38:38 +05:30
describe(GET_DIFFS_BATCH_PROVIDER_NAME, () => {
2022-07-23 23:45:48 +05:30
beforeEach(() => {
const interaction = {
2022-08-27 11:52:29 +05:30
...DiffsBatch.scenario,
2022-07-23 23:45:48 +05:30
...DiffsBatch.request,
willRespondWith: DiffsBatch.success,
};
provider.addInteraction(interaction);
});
2022-08-27 11:52:29 +05:30
it('returns a successful body', async () => {
const diffsBatch = await getDiffsBatch({
2022-07-23 23:45:48 +05:30
url: provider.mockService.baseUrl,
});
2022-08-27 11:52:29 +05:30
expect(diffsBatch).toEqual(DiffsBatch.body);
2022-07-23 23:45:48 +05:30
});
});
},
);
pactWith(
{
consumer: CONSUMER_NAME,
2023-03-04 22:38:38 +05:30
provider: GET_DISCUSSIONS_PROVIDER_NAME,
2022-07-23 23:45:48 +05:30
log: CONSUMER_LOG,
dir: CONTRACT_DIR,
},
(provider) => {
2023-03-04 22:38:38 +05:30
describe(GET_DISCUSSIONS_PROVIDER_NAME, () => {
2022-07-23 23:45:48 +05:30
beforeEach(() => {
const interaction = {
2022-08-27 11:52:29 +05:30
...Discussions.scenario,
2022-07-23 23:45:48 +05:30
...Discussions.request,
willRespondWith: Discussions.success,
};
provider.addInteraction(interaction);
});
2022-08-27 11:52:29 +05:30
it('return a successful body', async () => {
const discussions = await getDiscussions({
2022-07-23 23:45:48 +05:30
url: provider.mockService.baseUrl,
});
2022-08-27 11:52:29 +05:30
expect(discussions).toEqual(Discussions.body);
2022-07-23 23:45:48 +05:30
});
});
},
);
pactWith(
{
consumer: CONSUMER_NAME,
2023-03-04 22:38:38 +05:30
provider: GET_DIFFS_METADATA_PROVIDER_NAME,
2022-07-23 23:45:48 +05:30
log: CONSUMER_LOG,
dir: CONTRACT_DIR,
},
(provider) => {
2023-03-04 22:38:38 +05:30
describe(GET_DIFFS_METADATA_PROVIDER_NAME, () => {
2022-07-23 23:45:48 +05:30
beforeEach(() => {
const interaction = {
2022-08-27 11:52:29 +05:30
...DiffsMetadata.scenario,
2022-07-23 23:45:48 +05:30
...DiffsMetadata.request,
willRespondWith: DiffsMetadata.success,
};
provider.addInteraction(interaction);
});
2022-08-27 11:52:29 +05:30
it('return a successful body', async () => {
const diffsMetadata = await getDiffsMetadata({
2022-07-23 23:45:48 +05:30
url: provider.mockService.baseUrl,
});
2022-08-27 11:52:29 +05:30
expect(diffsMetadata).toEqual(DiffsMetadata.body);
2022-07-23 23:45:48 +05:30
});
});
},
);