diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-06 00:09:08 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-06 00:09:08 +0000 |
commit | 1acb6e46feb8e564232282a08acccd394334c185 (patch) | |
tree | d23b5a620fdd4ec633aae6ac88c41207a4ce6c82 /spec/contracts | |
parent | b54ba745ea5268221b493e0a4349fd75a042e20c (diff) | |
download | gitlab-ce-1acb6e46feb8e564232282a08acccd394334c185.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/contracts')
7 files changed, 199 insertions, 1 deletions
diff --git a/spec/contracts/consumer/fixtures/project/pipeline_schedule/update_pipeline_schedule.fixture.js b/spec/contracts/consumer/fixtures/project/pipeline_schedule/update_pipeline_schedule.fixture.js new file mode 100644 index 00000000000..acdc94d5c6e --- /dev/null +++ b/spec/contracts/consumer/fixtures/project/pipeline_schedule/update_pipeline_schedule.fixture.js @@ -0,0 +1,48 @@ +/* eslint-disable @gitlab/require-i18n-strings */ + +import { Matchers } from '@pact-foundation/pact'; +import { REDIRECT_HTML } from '../../../helpers/common_regex_patterns'; + +const body = Matchers.term({ + matcher: REDIRECT_HTML, + generate: + '<html><body>You are being <a href="http://example.org/gitlab-org/gitlab-qa/-/pipelines/5">redirected</a>.</body></html>', +}); + +const UpdatePipelineSchedule = { + success: { + status: 302, + headers: { + 'Content-Type': 'text/html; charset=utf-8', + }, + body, + }, + + scenario: { + state: 'a project with a pipeline schedule exists', + uponReceiving: 'a request to edit a pipeline schedule', + }, + + request: { + withRequest: { + method: 'PUT', + path: '/gitlab-org/gitlab-qa/-/pipeline_schedules/25', + headers: { + Accept: '*/*', + 'Content-Type': 'application/json; charset=utf-8', + }, + body: { + schedule: { + description: 'bar', + cron: '0 1 * * *', + cron_timezone: 'UTC', + active: true, + }, + }, + }, + }, +}; + +export { UpdatePipelineSchedule }; + +/* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/consumer/helpers/common_regex_patterns.js b/spec/contracts/consumer/helpers/common_regex_patterns.js index 2fbb4ea49f8..78dfeb7748f 100644 --- a/spec/contracts/consumer/helpers/common_regex_patterns.js +++ b/spec/contracts/consumer/helpers/common_regex_patterns.js @@ -3,7 +3,7 @@ */ export const URL = '^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$'; export const URL_PATH = '^/[a-zA-Z0-9#-=?_]+$'; -export const REDIRECT_HTML = 'You are being <a href=\\"(.)+/pipelines/[0-9]+\\">redirected</a>.'; +export const REDIRECT_HTML = 'You are being <a href=\\"(.)+\\">redirected</a>.'; // Pipelines export const PIPELINE_GROUPS = diff --git a/spec/contracts/consumer/resources/api/pipeline_schedules.js b/spec/contracts/consumer/resources/api/pipeline_schedules.js new file mode 100644 index 00000000000..ad04e59b9cd --- /dev/null +++ b/spec/contracts/consumer/resources/api/pipeline_schedules.js @@ -0,0 +1,26 @@ +import axios from 'axios'; + +export async function updatePipelineSchedule(endpoint) { + const { url } = endpoint; + + return axios({ + method: 'PUT', + baseURL: url, + url: '/gitlab-org/gitlab-qa/-/pipeline_schedules/25', + headers: { + Accept: '*/*', + 'Content-Type': 'application/json; charset=utf-8', + }, + data: { + schedule: { + description: 'bar', + cron: '0 1 * * *', + cron_timezone: 'UTC', + active: true, + }, + }, + validateStatus: (status) => { + return status === 302; + }, + }); +} diff --git a/spec/contracts/consumer/specs/project/pipeline_schedule/edit.spec.js b/spec/contracts/consumer/specs/project/pipeline_schedule/edit.spec.js new file mode 100644 index 00000000000..7d89825bcd4 --- /dev/null +++ b/spec/contracts/consumer/specs/project/pipeline_schedule/edit.spec.js @@ -0,0 +1,45 @@ +/* eslint-disable @gitlab/require-i18n-strings */ + +import { pactWith } from 'jest-pact'; + +import { UpdatePipelineSchedule } from '../../../fixtures/project/pipeline_schedule/update_pipeline_schedule.fixture'; +import { updatePipelineSchedule } from '../../../resources/api/pipeline_schedules'; + +const CONSUMER_NAME = 'PipelineSchedules#edit'; +const CONSUMER_LOG = '../logs/consumer.log'; +const CONTRACT_DIR = '../contracts/project/pipeline_schedule/edit'; +const PROVIDER_NAME = 'PUT Edit a pipeline schedule'; + +// API endpoint: /pipelines.json +pactWith( + { + consumer: CONSUMER_NAME, + provider: PROVIDER_NAME, + log: CONSUMER_LOG, + dir: CONTRACT_DIR, + }, + + (provider) => { + describe(PROVIDER_NAME, () => { + beforeEach(() => { + const interaction = { + ...UpdatePipelineSchedule.scenario, + ...UpdatePipelineSchedule.request, + willRespondWith: UpdatePipelineSchedule.success, + }; + + provider.addInteraction(interaction); + }); + + it('returns a successful body', async () => { + const pipelineSchedule = await updatePipelineSchedule({ + url: provider.mockService.baseUrl, + }); + + expect(pipelineSchedule.status).toEqual(UpdatePipelineSchedule.success.status); + }); + }); + }, +); + +/* eslint-enable @gitlab/require-i18n-strings */ diff --git a/spec/contracts/contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json b/spec/contracts/contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json new file mode 100644 index 00000000000..e0dd68dc230 --- /dev/null +++ b/spec/contracts/contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json @@ -0,0 +1,48 @@ +{ + "consumer": { + "name": "PipelineSchedules#edit" + }, + "provider": { + "name": "PUT Edit a pipeline schedule" + }, + "interactions": [ + { + "description": "a request to edit a pipeline schedule", + "providerState": "a project with a pipeline schedule exists", + "request": { + "method": "PUT", + "path": "/gitlab-org/gitlab-qa/-/pipeline_schedules/25", + "headers": { + "Accept": "*/*", + "Content-Type": "application/json; charset=utf-8" + }, + "body": { + "schedule": { + "description": "bar", + "cron": "0 1 * * *", + "cron_timezone": "UTC", + "active": true + } + } + }, + "response": { + "status": 302, + "headers": { + "Content-Type": "text/html; charset=utf-8" + }, + "body": "<html><body>You are being <a href=\"http://example.org/gitlab-org/gitlab-qa/-/pipelines/5\">redirected</a>.</body></html>", + "matchingRules": { + "$.body": { + "match": "regex", + "regex": "You are being <a href=\\\"(.)+\\\">redirected<\\/a>." + } + } + } + } + ], + "metadata": { + "pactSpecification": { + "version": "2.0.0" + } + } +}
\ No newline at end of file diff --git a/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb new file mode 100644 index 00000000000..a83aa9524dc --- /dev/null +++ b/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../../../spec_helper' +require_relative '../../../states/project/pipeline_schedule/edit_state' + +module Provider + module CreateNewPipelineHelper + Pact.service_provider "PUT Edit a pipeline schedule" do + app { Environments::Test.app } + + honours_pact_with 'PipelineSchedule#edit' do + pact_uri '../contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json' + end + end + end +end diff --git a/spec/contracts/provider/states/project/pipeline_schedule/edit_state.rb b/spec/contracts/provider/states/project/pipeline_schedule/edit_state.rb new file mode 100644 index 00000000000..4ee714f15f3 --- /dev/null +++ b/spec/contracts/provider/states/project/pipeline_schedule/edit_state.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +Pact.provider_states_for "PipelineSchedules#edit" do + provider_state "a project with a pipeline schedule exists" do + set_up do + user = User.find_by(name: Provider::UsersHelper::CONTRACT_USER_NAME) + namespace = create(:namespace, name: 'gitlab-org') + project = create(:project, :repository, name: 'gitlab-qa', namespace: namespace, creator: user) + + project.add_maintainer(user) + + create(:ci_pipeline_schedule, id: 25, project: project, owner: user) + end + end +end |