diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-16 09:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-16 09:08:59 +0300 |
commit | 06bcbc77e472a70b8332150a941539c55953ef2b (patch) | |
tree | 903ff19991a3c3234626b1e86827a42063eeac61 /spec/contracts | |
parent | 1325f8cf2dce0f24403ea27c4ee58afd51fa3a8e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/contracts')
20 files changed, 182 insertions, 178 deletions
diff --git a/spec/contracts/consumer/endpoints/merge_requests.js b/spec/contracts/consumer/endpoints/project/merge_requests.js index ae4d5544df6..38773e5fb10 100644 --- a/spec/contracts/consumer/endpoints/merge_requests.js +++ b/spec/contracts/consumer/endpoints/project/merge_requests.js @@ -1,6 +1,6 @@ import { request } from 'axios'; -export function getMetadata(endpoint) { +export function getDiffsMetadata(endpoint) { const { url } = endpoint; return request({ @@ -22,7 +22,7 @@ export function getDiscussions(endpoint) { }).then((response) => response.data); } -export function getDiffs(endpoint) { +export function getDiffsBatch(endpoint) { const { url } = endpoint; return request({ diff --git a/spec/contracts/consumer/fixtures/diffs.fixture.js b/spec/contracts/consumer/fixtures/project/merge_request/diffs_batch.fixture.js index cc2c054b08f..b53e4bb335d 100644 --- a/spec/contracts/consumer/fixtures/diffs.fixture.js +++ b/spec/contracts/consumer/fixtures/project/merge_request/diffs_batch.fixture.js @@ -62,7 +62,7 @@ const body = { }, }; -const Diffs = { +const DiffsBatch = { body: Matchers.extractPayload(body), success: { @@ -86,5 +86,6 @@ const Diffs = { }, }; -export { Diffs }; +export { DiffsBatch }; + /* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/consumer/fixtures/metadata.fixture.js b/spec/contracts/consumer/fixtures/project/merge_request/diffs_metadata.fixture.js index c19ca2175b3..39dbcf78ee7 100644 --- a/spec/contracts/consumer/fixtures/metadata.fixture.js +++ b/spec/contracts/consumer/fixtures/project/merge_request/diffs_metadata.fixture.js @@ -70,7 +70,7 @@ const body = { project_name: Matchers.string('contract-testing'), }; -const Metadata = { +const DiffsMetadata = { body: Matchers.extractPayload(body), success: { @@ -82,7 +82,7 @@ const Metadata = { }, request: { - uponReceiving: 'a request for Metadata', + uponReceiving: 'a request for Diffs Metadata', withRequest: { method: 'GET', path: '/gitlab-org/gitlab-qa/-/merge_requests/1/diffs_metadata.json', @@ -93,5 +93,6 @@ const Metadata = { }, }; -export { Metadata }; +export { DiffsMetadata }; + /* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/consumer/fixtures/discussions.fixture.js b/spec/contracts/consumer/fixtures/project/merge_request/discussions.fixture.js index 26f1d65f663..af0962a01cb 100644 --- a/spec/contracts/consumer/fixtures/discussions.fixture.js +++ b/spec/contracts/consumer/fixtures/project/merge_request/discussions.fixture.js @@ -83,4 +83,5 @@ const Discussions = { }; export { Discussions }; + /* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/consumer/specs/diffs.spec.js b/spec/contracts/consumer/specs/diffs.spec.js deleted file mode 100644 index 6b1cefdbdbc..00000000000 --- a/spec/contracts/consumer/specs/diffs.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-disable @gitlab/require-i18n-strings */ - -import { pactWith } from 'jest-pact'; - -import { Diffs } from '../fixtures/diffs.fixture'; -import { getDiffs } from '../endpoints/merge_requests'; - -pactWith( - { - consumer: 'Merge Request Page', - provider: 'Merge Request Diffs Endpoint', - log: '../logs/consumer.log', - dir: '../contracts', - }, - - (provider) => { - describe('Diffs Endpoint', () => { - beforeEach(() => { - const interaction = { - state: 'a merge request with diffs exists', - ...Diffs.request, - willRespondWith: Diffs.success, - }; - provider.addInteraction(interaction); - }); - - it('return a successful body', () => { - return getDiffs({ - url: provider.mockService.baseUrl, - }).then((diffs) => { - expect(diffs).toEqual(Diffs.body); - }); - }); - }); - }, -); -/* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/consumer/specs/discussions.spec.js b/spec/contracts/consumer/specs/discussions.spec.js deleted file mode 100644 index 2a5d0ba6267..00000000000 --- a/spec/contracts/consumer/specs/discussions.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-disable @gitlab/require-i18n-strings */ - -import { pactWith } from 'jest-pact'; - -import { Discussions } from '../fixtures/discussions.fixture'; -import { getDiscussions } from '../endpoints/merge_requests'; - -pactWith( - { - consumer: 'Merge Request Page', - provider: 'Merge Request Discussions Endpoint', - log: '../logs/consumer.log', - dir: '../contracts', - }, - - (provider) => { - describe('Discussions Endpoint', () => { - beforeEach(() => { - const interaction = { - state: 'a merge request with discussions exists', - ...Discussions.request, - willRespondWith: Discussions.success, - }; - provider.addInteraction(interaction); - }); - - it('return a successful body', () => { - return getDiscussions({ - url: provider.mockService.baseUrl, - }).then((discussions) => { - expect(discussions).toEqual(Discussions.body); - }); - }); - }); - }, -); -/* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/consumer/specs/metadata.spec.js b/spec/contracts/consumer/specs/metadata.spec.js deleted file mode 100644 index fc082cb6a46..00000000000 --- a/spec/contracts/consumer/specs/metadata.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-disable @gitlab/require-i18n-strings */ - -import { pactWith } from 'jest-pact'; - -import { Metadata } from '../fixtures/metadata.fixture'; -import { getMetadata } from '../endpoints/merge_requests'; - -pactWith( - { - consumer: 'Merge Request Page', - provider: 'Merge Request Metadata Endpoint', - log: '../logs/consumer.log', - dir: '../contracts', - }, - - (provider) => { - describe('Metadata Endpoint', () => { - beforeEach(() => { - const interaction = { - state: 'a merge request exists', - ...Metadata.request, - willRespondWith: Metadata.success, - }; - provider.addInteraction(interaction); - }); - - it('return a successful body', () => { - return getMetadata({ - url: provider.mockService.baseUrl, - }).then((metadata) => { - expect(metadata).toEqual(Metadata.body); - }); - }); - }); - }, -); -/* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/consumer/specs/project/merge_request/show.spec.js b/spec/contracts/consumer/specs/project/merge_request/show.spec.js new file mode 100644 index 00000000000..8c6e029cb12 --- /dev/null +++ b/spec/contracts/consumer/specs/project/merge_request/show.spec.js @@ -0,0 +1,112 @@ +/* eslint-disable @gitlab/require-i18n-strings */ + +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 '../../../endpoints/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 = { + state: 'a merge request with diffs exists', + ...DiffsBatch.request, + willRespondWith: DiffsBatch.success, + }; + provider.addInteraction(interaction); + }); + + it('returns a successful body', () => { + return getDiffsBatch({ + url: provider.mockService.baseUrl, + }).then((diffsBatch) => { + 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 = { + state: 'a merge request with discussions exists', + ...Discussions.request, + willRespondWith: Discussions.success, + }; + provider.addInteraction(interaction); + }); + + it('return a successful body', () => { + return getDiscussions({ + url: provider.mockService.baseUrl, + }).then((discussions) => { + 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 = { + state: 'a merge request exists', + ...DiffsMetadata.request, + willRespondWith: DiffsMetadata.success, + }; + provider.addInteraction(interaction); + }); + + it('return a successful body', () => { + return getDiffsMetadata({ + url: provider.mockService.baseUrl, + }).then((diffsMetadata) => { + expect(diffsMetadata).toEqual(DiffsMetadata.body); + }); + }); + }); + }, +); + +/* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/contracts/merge_request_page-merge_request_diffs_endpoint.json b/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json index 2f097d8eb24..3fa13766766 100644 --- a/spec/contracts/contracts/merge_request_page-merge_request_diffs_endpoint.json +++ b/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json @@ -1,9 +1,9 @@ { "consumer": { - "name": "Merge Request Page" + "name": "MergeRequest#show" }, "provider": { - "name": "Merge Request Diffs Endpoint" + "name": "Merge Request Diffs Batch Endpoint" }, "interactions": [ { @@ -226,4 +226,4 @@ "version": "2.0.0" } } -} +}
\ No newline at end of file diff --git a/spec/contracts/contracts/merge_request_page-merge_request_metadata_endpoint.json b/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json index eb22b7d2e3c..b98a0127e54 100644 --- a/spec/contracts/contracts/merge_request_page-merge_request_metadata_endpoint.json +++ b/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json @@ -1,13 +1,13 @@ { "consumer": { - "name": "Merge Request Page" + "name": "MergeRequest#show" }, "provider": { - "name": "Merge Request Metadata Endpoint" + "name": "Merge Request Diffs Metadata Endpoint" }, "interactions": [ { - "description": "a request for Metadata", + "description": "a request for Diffs Metadata", "providerState": "a merge request exists", "request": { "method": "GET", @@ -220,4 +220,4 @@ "version": "2.0.0" } } -} +}
\ No newline at end of file diff --git a/spec/contracts/contracts/merge_request_page-merge_request_discussions_endpoint.json b/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json index 819d95276b3..ecaf9c123af 100644 --- a/spec/contracts/contracts/merge_request_page-merge_request_discussions_endpoint.json +++ b/spec/contracts/contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json @@ -1,6 +1,6 @@ { "consumer": { - "name": "Merge Request Page" + "name": "MergeRequest#show" }, "provider": { "name": "Merge Request Discussions Endpoint" @@ -233,4 +233,4 @@ "version": "2.0.0" } } -} +}
\ No newline at end of file diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/diffs_batch_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/diffs_batch_helper.rb new file mode 100644 index 00000000000..7d1fbe91e86 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/merge_request/diffs_batch_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../../../spec_helper' +require_relative '../../../states/project/merge_request/diffs_batch_state' + +module Provider + module DiffsBatchHelper + Pact.service_provider "Merge Request Diffs Batch Endpoint" do + app { Environments::Test.app } + + honours_pact_with 'MergeRequest#show' do + pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json' + end + end + end +end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/diffs_metadata_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/diffs_metadata_helper.rb new file mode 100644 index 00000000000..5f0c58d18d4 --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/merge_request/diffs_metadata_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../../../spec_helper' +require_relative '../../../states/project/merge_request/diffs_metadata_state' + +module Provider + module DiffsMetadataHelper + Pact.service_provider "Merge Request Diffs Metadata Endpoint" do + app { Environments::Test.app } + + honours_pact_with 'MergeRequest#show' do + pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json' + end + end + end +end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/discussions_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/discussions_helper.rb new file mode 100644 index 00000000000..0f4244ba40a --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/merge_request/discussions_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../../../spec_helper' +require_relative '../../../states/project/merge_request/discussions_state' + +module Provider + module DiscussionsHelper + Pact.service_provider "Merge Request Discussions Endpoint" do + app { Environments::Test.app } + + honours_pact_with 'MergeRequest#show' do + pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json' + end + end + end +end diff --git a/spec/contracts/provider/specs/diffs_helper.rb b/spec/contracts/provider/specs/diffs_helper.rb deleted file mode 100644 index 24bdd00dbae..00000000000 --- a/spec/contracts/provider/specs/diffs_helper.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative '../spec_helper' -require_relative '../states/diffs_state' - -module Provider - module DiffsHelper - Pact.service_provider "Merge Request Diffs Endpoint" do - app { Environments::Test.app } - - honours_pact_with 'Merge Request Page' do - pact_uri '../contracts/merge_request_page-merge_request_diffs_endpoint.json' - end - end - end -end diff --git a/spec/contracts/provider/specs/discussions_helper.rb b/spec/contracts/provider/specs/discussions_helper.rb deleted file mode 100644 index 135ccf48276..00000000000 --- a/spec/contracts/provider/specs/discussions_helper.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative '../spec_helper' -require_relative '../states/discussions_state' - -module Provider - module DiscussionsHelper - Pact.service_provider "Merge Request Discussions Endpoint" do - app { Environments::Test.app } - - honours_pact_with 'Merge Request Page' do - pact_uri '../contracts/merge_request_page-merge_request_discussions_endpoint.json' - end - end - end -end diff --git a/spec/contracts/provider/specs/metadata_helper.rb b/spec/contracts/provider/specs/metadata_helper.rb deleted file mode 100644 index e73b993a31a..00000000000 --- a/spec/contracts/provider/specs/metadata_helper.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative '../spec_helper' -require_relative '../states/metadata_state' - -module Provider - module MetadataHelper - Pact.service_provider "Merge Request Metadata Endpoint" do - app { Environments::Test.app } - - honours_pact_with 'Merge Request Page' do - pact_uri '../contracts/merge_request_page-merge_request_metadata_endpoint.json' - end - end - end -end diff --git a/spec/contracts/provider/states/diffs_state.rb b/spec/contracts/provider/states/project/merge_request/diffs_batch_state.rb index d959cde5f5e..ac20c17c187 100644 --- a/spec/contracts/provider/states/diffs_state.rb +++ b/spec/contracts/provider/states/project/merge_request/diffs_batch_state.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -Pact.provider_states_for "Merge Request Page" do +Pact.provider_states_for "MergeRequest#show" do provider_state "a merge request with diffs exists" do set_up do user = User.find_by(name: Provider::UsersHelper::CONTRACT_USER_NAME) diff --git a/spec/contracts/provider/states/metadata_state.rb b/spec/contracts/provider/states/project/merge_request/diffs_metadata_state.rb index 59b290ce2fe..8754232690c 100644 --- a/spec/contracts/provider/states/metadata_state.rb +++ b/spec/contracts/provider/states/project/merge_request/diffs_metadata_state.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -Pact.provider_states_for "Merge Request Page" do +Pact.provider_states_for "MergeRequest#show" do provider_state "a merge request exists" do set_up do user = User.find_by(name: Provider::UsersHelper::CONTRACT_USER_NAME) diff --git a/spec/contracts/provider/states/discussions_state.rb b/spec/contracts/provider/states/project/merge_request/discussions_state.rb index ddbcf80f2c8..2d64f85eedf 100644 --- a/spec/contracts/provider/states/discussions_state.rb +++ b/spec/contracts/provider/states/project/merge_request/discussions_state.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -Pact.provider_states_for "Merge Request Page" do +Pact.provider_states_for "MergeRequest#show" do provider_state "a merge request with discussions exists" do set_up do user = User.find_by(name: Provider::UsersHelper::CONTRACT_USER_NAME) |