diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-07 12:09:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-07 12:09:00 +0300 |
commit | bdd03bc52aee1c3f37e25ae9b1fc8a27885b7428 (patch) | |
tree | e409a6e1f76d9dc69c5413a06e9b4c4b3f74fef7 /spec/contracts/consumer | |
parent | bed53d96d214fd96ea688d3e86e53457ce50043e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/contracts/consumer')
-rw-r--r-- | spec/contracts/consumer/.node-version | 1 | ||||
-rw-r--r-- | spec/contracts/consumer/endpoints/merge_requests.js | 42 | ||||
-rw-r--r-- | spec/contracts/consumer/fixtures/diffs.fixture.js | 89 | ||||
-rw-r--r-- | spec/contracts/consumer/fixtures/discussions.fixture.js | 85 | ||||
-rw-r--r-- | spec/contracts/consumer/fixtures/metadata.fixture.js | 96 | ||||
-rw-r--r-- | spec/contracts/consumer/package.json | 17 | ||||
-rw-r--r-- | spec/contracts/consumer/specs/diffs.spec.js | 36 | ||||
-rw-r--r-- | spec/contracts/consumer/specs/discussions.spec.js | 36 | ||||
-rw-r--r-- | spec/contracts/consumer/specs/metadata.spec.js | 36 |
9 files changed, 438 insertions, 0 deletions
diff --git a/spec/contracts/consumer/.node-version b/spec/contracts/consumer/.node-version new file mode 100644 index 00000000000..18711d290ea --- /dev/null +++ b/spec/contracts/consumer/.node-version @@ -0,0 +1 @@ +14.17.5 diff --git a/spec/contracts/consumer/endpoints/merge_requests.js b/spec/contracts/consumer/endpoints/merge_requests.js new file mode 100644 index 00000000000..04e66c57dc9 --- /dev/null +++ b/spec/contracts/consumer/endpoints/merge_requests.js @@ -0,0 +1,42 @@ +'use strict'; + +const axios = require('axios'); + +exports.getMetadata = (endpoint) => { + const url = endpoint.url; + + return axios + .request({ + method: 'GET', + baseURL: url, + url: '/gitlab-org/gitlab-qa/-/merge_requests/1/diffs_metadata.json', + headers: { Accept: '*/*' }, + }) + .then((response) => response.data); +}; + +exports.getDiscussions = (endpoint) => { + const url = endpoint.url; + + return axios + .request({ + method: 'GET', + baseURL: url, + url: '/gitlab-org/gitlab-qa/-/merge_requests/1/discussions.json', + headers: { Accept: '*/*' }, + }) + .then((response) => response.data); +}; + +exports.getDiffs = (endpoint) => { + const url = endpoint.url; + + return axios + .request({ + method: 'GET', + baseURL: url, + url: '/gitlab-org/gitlab-qa/-/merge_requests/1/diffs_batch.json?page=0', + headers: { Accept: '*/*' }, + }) + .then((response) => response.data); +}; diff --git a/spec/contracts/consumer/fixtures/diffs.fixture.js b/spec/contracts/consumer/fixtures/diffs.fixture.js new file mode 100644 index 00000000000..7dbe825b093 --- /dev/null +++ b/spec/contracts/consumer/fixtures/diffs.fixture.js @@ -0,0 +1,89 @@ +'use strict'; + +const { Matchers } = require('@pact-foundation/pact'); + +const body = { + diff_files: Matchers.eachLike({ + content_sha: Matchers.string('b0c94059db75b2473d616d4b1fde1a77533355a3'), + submodule: Matchers.boolean(false), + edit_path: Matchers.string('/gitlab-qa-bot/...'), + ide_edit_path: Matchers.string('/gitlab-qa-bot/...'), + old_path_html: Matchers.string('Gemfile'), + new_path_html: Matchers.string('Gemfile'), + blob: { + id: Matchers.string('855071bb3928d140764885964f7be1bb3e582495'), + path: Matchers.string('Gemfile'), + name: Matchers.string('Gemfile'), + mode: Matchers.string('1234567'), + readable_text: Matchers.boolean(true), + icon: Matchers.string('doc-text'), + }, + can_modify_blob: Matchers.boolean(false), + file_identifier_hash: Matchers.string('67d82b8716a5b6c52c7abf0b2cd99c7594ed3587'), + file_hash: Matchers.string('67d82b8716a5b6c52c7abf0b2cd99c7594ed3587'), + file_path: Matchers.string('Gemfile'), + old_path: Matchers.string('Gemfile'), + new_path: Matchers.string('Gemfile'), + new_file: Matchers.boolean(false), + renamed_file: Matchers.boolean(false), + deleted_file: Matchers.boolean(false), + diff_refs: { + base_sha: Matchers.string('67d82b8716a5b6c52c7abf0b2cd99c7594ed3587'), + start_sha: Matchers.string('67d82b8716a5b6c52c7abf0b2cd99c7594ed3587'), + head_sha: Matchers.string('67d82b8716a5b6c52c7abf0b2cd99c7594ed3587'), + }, + mode_changed: Matchers.boolean(false), + a_mode: Matchers.string('123456'), + b_mode: Matchers.string('123456'), + viewer: { + name: Matchers.string('text'), + collapsed: Matchers.boolean(false), + }, + old_size: Matchers.integer(2288), + new_size: Matchers.integer(2288), + added_lines: Matchers.integer(1), + removed_lines: Matchers.integer(1), + load_collapsed_diff_url: Matchers.string('/gitlab-qa-bot/...'), + view_path: Matchers.string('/gitlab-qa-bot/...'), + context_lines_path: Matchers.string('/gitlab-qa-bot/...'), + highlighted_diff_lines: Matchers.eachLike({ + // The following values can also be null which is not supported + //line_code: Matchers.string('de3150c01c3a946a6168173c4116741379fe3579_1_1'), + //old_line: Matchers.integer(1), + //new_line: Matchers.integer(1), + text: Matchers.string('source'), + rich_text: Matchers.string('<span></span>'), + can_receive_suggestion: Matchers.boolean(true), + }), + is_fully_expanded: Matchers.boolean(false), + }), + pagination: { + total_pages: Matchers.integer(1), + }, +}; + +const Diffs = { + body: Matchers.extractPayload(body), + + success: { + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf-8', + }, + body: body, + }, + + request: { + uponReceiving: 'a request for diff lines', + withRequest: { + method: 'GET', + path: '/gitlab-org/gitlab-qa/-/merge_requests/1/diffs_batch.json', + headers: { + Accept: '*/*', + }, + query: 'page=0', + }, + }, +}; + +exports.Diffs = Diffs; diff --git a/spec/contracts/consumer/fixtures/discussions.fixture.js b/spec/contracts/consumer/fixtures/discussions.fixture.js new file mode 100644 index 00000000000..c28b9bdd505 --- /dev/null +++ b/spec/contracts/consumer/fixtures/discussions.fixture.js @@ -0,0 +1,85 @@ +'use strict'; + +const { Matchers } = require('@pact-foundation/pact'); + +const body = Matchers.eachLike({ + id: Matchers.string('fd73763cbcbf7b29eb8765d969a38f7d735e222a'), + reply_id: Matchers.string('fd73763cbcbf7b29eb8765d969a38f7d735e222a'), + project_id: Matchers.integer(6954442), + confidential: Matchers.boolean(false), + diff_discussion: Matchers.boolean(false), + expanded: Matchers.boolean(false), + for_commit: Matchers.boolean(false), + individual_note: Matchers.boolean(true), + resolvable: Matchers.boolean(false), + resolved_by_push: Matchers.boolean(false), + notes: Matchers.eachLike({ + id: Matchers.string('76489845'), + author: { + id: Matchers.integer(1675733), + username: Matchers.string('gitlab-qa-bot'), + name: Matchers.string('gitlab-qa-bot'), + state: Matchers.string('active'), + avatar_url: Matchers.string( + 'https://secure.gravatar.com/avatar/8355ad0f2761367fae6b9c4fe80994b9?s=80&d=identicon', + ), + show_status: Matchers.boolean(false), + path: Matchers.string('/gitlab-qa-bot'), + }, + created_at: Matchers.iso8601DateTimeWithMillis('2022-02-22T07:06:55.038Z'), + updated_at: Matchers.iso8601DateTimeWithMillis('2022-02-22T07:06:55.038Z'), + system: Matchers.boolean(false), + noteable_id: Matchers.integer(8333422), + noteable_type: Matchers.string('MergeRequest'), + resolvable: Matchers.boolean(false), + resolved: Matchers.boolean(true), + confidential: Matchers.boolean(false), + noteable_iid: Matchers.integer(1), + note: Matchers.string('This is a test comment'), + note_html: Matchers.string( + '<p data-sourcepos="1:1-1:22" dir="auto">This is a test comment</p>', + ), + current_user: { + can_edit: Matchers.boolean(true), + can_award_emoji: Matchers.boolean(true), + can_resolve: Matchers.boolean(false), + can_resolve_discussion: Matchers.boolean(false), + }, + is_noteable_author: Matchers.boolean(true), + discussion_id: Matchers.string('fd73763cbcbf7b29eb8765d969a38f7d735e222a'), + emoji_awardable: Matchers.boolean(true), + report_abuse_path: Matchers.string('/gitlab-qa-bot/...'), + noteable_note_url: Matchers.string('https://staging.gitlab.com/gitlab-qa-bot/...'), + cached_markdown_version: Matchers.integer(1900552), + human_access: Matchers.string('Maintainer'), + is_contributor: Matchers.boolean(false), + project_name: Matchers.string('contract-testing'), + path: Matchers.string('/gitlab-qa-bot/...'), + }), + resolved: Matchers.boolean(true), +}); + +const Discussions = { + body: Matchers.extractPayload(body), + + success: { + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf-8', + }, + body: body, + }, + + request: { + uponReceiving: 'a request for discussions', + withRequest: { + method: 'GET', + path: '/gitlab-org/gitlab-qa/-/merge_requests/1/discussions.json', + headers: { + Accept: '*/*', + }, + }, + }, +}; + +exports.Discussions = Discussions; diff --git a/spec/contracts/consumer/fixtures/metadata.fixture.js b/spec/contracts/consumer/fixtures/metadata.fixture.js new file mode 100644 index 00000000000..3fca6cf9181 --- /dev/null +++ b/spec/contracts/consumer/fixtures/metadata.fixture.js @@ -0,0 +1,96 @@ +'use strict'; + +const { Matchers } = require('@pact-foundation/pact'); + +const body = { + real_size: Matchers.string('1'), + size: Matchers.integer(1), + branch_name: Matchers.string('testing-branch-1'), + source_branch_exists: Matchers.boolean(true), + target_branch_name: Matchers.string('master'), + merge_request_diff: { + created_at: Matchers.iso8601DateTimeWithMillis('2022-02-17T11:47:08.804Z'), + commits_count: Matchers.integer(1), + latest: Matchers.boolean(true), + short_commit_sha: Matchers.string('aee1ffec'), + base_version_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_id=10581773', + ), + head_version_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_head=true', + ), + version_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_id=10581773', + ), + compare_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_id=10581773&start_sha=aee1ffec2299c0cfb17c8821e931339b73a3759f', + ), + }, + latest_diff: Matchers.boolean(true), + latest_version_path: Matchers.string('/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs'), + added_lines: Matchers.integer(1), + removed_lines: Matchers.integer(1), + render_overflow_warning: Matchers.boolean(false), + email_patch_path: Matchers.string('/gitlab-qa-bot/contract-testing/-/merge_requests/1.patch'), + plain_diff_path: Matchers.string('/gitlab-qa-bot/contract-testing/-/merge_requests/1.diff'), + merge_request_diffs: Matchers.eachLike({ + commits_count: Matchers.integer(1), + latest: Matchers.boolean(true), + short_commit_sha: Matchers.string('aee1ffec'), + base_version_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_id=10581773', + ), + head_version_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_head=true', + ), + version_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_id=10581773', + ), + compare_path: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/merge_requests/1/diffs?diff_id=10581773&start_sha=aee1ffec2299c0cfb17c8821e931339b73a3759f', + ), + }), + definition_path_prefix: Matchers.string( + '/gitlab-qa-bot/contract-testing/-/blob/aee1ffec2299c0cfb17c8821e931339b73a3759f', + ), + diff_files: Matchers.eachLike({ + added_lines: Matchers.integer(1), + removed_lines: Matchers.integer(1), + new_path: Matchers.string('Gemfile'), + old_path: Matchers.string('Gemfile'), + new_file: Matchers.boolean(false), + deleted_file: Matchers.boolean(false), + submodule: Matchers.boolean(false), + file_identifier_hash: Matchers.string('67d82b8716a5b6c52c7abf0b2cd99c7594ed3587'), + file_hash: Matchers.string('de3150c01c3a946a6168173c4116741379fe3579'), + }), + has_conflicts: Matchers.boolean(false), + can_merge: Matchers.boolean(false), + project_path: Matchers.string('gitlab-qa-bot/contract-testing'), + project_name: Matchers.string('contract-testing'), +}; + +const Metadata = { + body: Matchers.extractPayload(body), + + success: { + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf-8', + }, + body: body, + }, + + request: { + uponReceiving: 'a request for Metadata', + withRequest: { + method: 'GET', + path: '/gitlab-org/gitlab-qa/-/merge_requests/1/diffs_metadata.json', + headers: { + Accept: '*/*', + }, + }, + }, +}; + +exports.Metadata = Metadata; diff --git a/spec/contracts/consumer/package.json b/spec/contracts/consumer/package.json new file mode 100644 index 00000000000..6a427ff8a7b --- /dev/null +++ b/spec/contracts/consumer/package.json @@ -0,0 +1,17 @@ +{ + "name": "consumer", + "version": "1.0.0", + "description": "consumer side contract testing", + "license": "MIT", + "repository": "https://gitlab.com/gitlab-org/gitlab.git", + "dependencies": { + "@pact-foundation/pact": "^9.17.2", + "axios": "^0.26.0", + "jest": "^27.5.1", + "jest-pact": "^0.9.1", + "prettier": "^2.5.1" + }, + "scripts": { + "test": "jest --runInBand" + } +} diff --git a/spec/contracts/consumer/specs/diffs.spec.js b/spec/contracts/consumer/specs/diffs.spec.js new file mode 100644 index 00000000000..b812461cb69 --- /dev/null +++ b/spec/contracts/consumer/specs/diffs.spec.js @@ -0,0 +1,36 @@ +'use strict'; + +const { pactWith } = require('jest-pact'); + +const { Diffs } = require('../fixtures/diffs.fixture'); +const { getDiffs } = require('../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); + }); + }); + }); + }, +); diff --git a/spec/contracts/consumer/specs/discussions.spec.js b/spec/contracts/consumer/specs/discussions.spec.js new file mode 100644 index 00000000000..304c240f7d3 --- /dev/null +++ b/spec/contracts/consumer/specs/discussions.spec.js @@ -0,0 +1,36 @@ +'use strict'; + +const { pactWith } = require('jest-pact'); + +const { Discussions } = require('../fixtures/discussions.fixture'); +const { getDiscussions } = require('../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); + }); + }); + }); + }, +); diff --git a/spec/contracts/consumer/specs/metadata.spec.js b/spec/contracts/consumer/specs/metadata.spec.js new file mode 100644 index 00000000000..c49d4c354b1 --- /dev/null +++ b/spec/contracts/consumer/specs/metadata.spec.js @@ -0,0 +1,36 @@ +'use strict'; + +const { pactWith } = require('jest-pact'); + +const { Metadata } = require('../fixtures/metadata.fixture'); +const { getMetadata } = require('../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); + }); + }); + }); + }, +); |