diff options
Diffstat (limited to 'spec/contracts/consumer/specs/project/pipelines')
3 files changed, 170 insertions, 0 deletions
diff --git a/spec/contracts/consumer/specs/project/pipelines/index.spec.js b/spec/contracts/consumer/specs/project/pipelines/index.spec.js new file mode 100644 index 00000000000..14bad31a763 --- /dev/null +++ b/spec/contracts/consumer/specs/project/pipelines/index.spec.js @@ -0,0 +1,40 @@ +import { pactWith } from 'jest-pact'; + +import { ProjectPipelines } from '../../../fixtures/project/pipelines/get_list_project_pipelines.fixture'; +import { getProjectPipelines } from '../../../resources/api/project/pipelines'; + +const CONSUMER_NAME = 'Pipelines#index'; +const CONSUMER_LOG = '../logs/consumer.log'; +const CONTRACT_DIR = '../contracts/project/pipelines/index'; +const PROVIDER_NAME = 'GET list project pipelines'; + +// API endpoint: /pipelines.json +pactWith( + { + consumer: CONSUMER_NAME, + provider: PROVIDER_NAME, + log: CONSUMER_LOG, + dir: CONTRACT_DIR, + }, + + (provider) => { + describe(PROVIDER_NAME, () => { + beforeEach(() => { + const interaction = { + ...ProjectPipelines.scenario, + ...ProjectPipelines.request, + willRespondWith: ProjectPipelines.success, + }; + provider.addInteraction(interaction); + }); + + it('returns a successful body', async () => { + const pipelines = await getProjectPipelines({ + url: provider.mockService.baseUrl, + }); + + expect(pipelines).toEqual(ProjectPipelines.body); + }); + }); + }, +); diff --git a/spec/contracts/consumer/specs/project/pipelines/new.spec.js b/spec/contracts/consumer/specs/project/pipelines/new.spec.js new file mode 100644 index 00000000000..9e381a61670 --- /dev/null +++ b/spec/contracts/consumer/specs/project/pipelines/new.spec.js @@ -0,0 +1,41 @@ +import { pactWith } from 'jest-pact'; + +import { NewProjectPipeline } from '../../../fixtures/project/pipelines/create_a_new_pipeline.fixture'; +import { postProjectPipelines } from '../../../resources/api/project/pipelines'; + +const CONSUMER_NAME = 'Pipelines#new'; +const CONSUMER_LOG = '../logs/consumer.log'; +const CONTRACT_DIR = '../contracts/project/pipelines/new'; +const PROVIDER_NAME = 'POST create a new pipeline'; + +// API endpoint: /pipelines.json +pactWith( + { + consumer: CONSUMER_NAME, + provider: PROVIDER_NAME, + log: CONSUMER_LOG, + dir: CONTRACT_DIR, + }, + + (provider) => { + describe(PROVIDER_NAME, () => { + beforeEach(async () => { + const interaction = { + ...NewProjectPipeline.scenario, + ...NewProjectPipeline.request, + willRespondWith: NewProjectPipeline.success, + }; + + provider.addInteraction(interaction); + }); + + it('returns a successful body', async () => { + const newPipeline = await postProjectPipelines({ + url: provider.mockService.baseUrl, + }); + + expect(newPipeline.status).toEqual(NewProjectPipeline.success.status); + }); + }); + }, +); diff --git a/spec/contracts/consumer/specs/project/pipelines/show.spec.js b/spec/contracts/consumer/specs/project/pipelines/show.spec.js new file mode 100644 index 00000000000..97ad9dbbc9d --- /dev/null +++ b/spec/contracts/consumer/specs/project/pipelines/show.spec.js @@ -0,0 +1,89 @@ +import { pactWith } from 'jest-pact'; +import { GraphQLInteraction } from '@pact-foundation/pact'; + +import { extractGraphQLQuery } from '../../../helpers/graphql_query_extractor'; + +import { PipelineHeaderData } from '../../../fixtures/project/pipelines/get_pipeline_header_data.fixture'; +import { DeletePipeline } from '../../../fixtures/project/pipelines/delete_pipeline.fixture'; + +import { getPipelineHeaderDataRequest, deletePipeline } from '../../../resources/graphql/pipelines'; + +const CONSUMER_NAME = 'Pipelines#show'; +const CONSUMER_LOG = '../logs/consumer.log'; +const CONTRACT_DIR = '../contracts/project/pipelines/show'; +const GET_PIPELINE_HEADER_DATA_PROVIDER_NAME = 'GET pipeline header data'; +const DELETE_PIPELINE_PROVIDER_NAME = 'DELETE pipeline'; + +// GraphQL query: getPipelineHeaderData +pactWith( + { + consumer: CONSUMER_NAME, + provider: GET_PIPELINE_HEADER_DATA_PROVIDER_NAME, + log: CONSUMER_LOG, + dir: CONTRACT_DIR, + }, + + (provider) => { + describe(GET_PIPELINE_HEADER_DATA_PROVIDER_NAME, () => { + beforeEach(async () => { + const query = await extractGraphQLQuery( + 'app/assets/javascripts/pipelines/graphql/queries/get_pipeline_header_data.query.graphql', + ); + const graphqlQuery = new GraphQLInteraction() + .given(PipelineHeaderData.scenario.state) + .uponReceiving(PipelineHeaderData.scenario.uponReceiving) + .withQuery(query) + .withRequest(PipelineHeaderData.request) + .withVariables(PipelineHeaderData.variables) + .willRespondWith(PipelineHeaderData.success); + + provider.addInteraction(graphqlQuery); + }); + + it('returns a successful body', async () => { + const pipelineHeaderData = await getPipelineHeaderDataRequest({ + url: provider.mockService.baseUrl, + }); + + expect(pipelineHeaderData.data).toEqual(PipelineHeaderData.body); + }); + }); + }, +); + +// GraphQL query: deletePipeline +pactWith( + { + consumer: CONSUMER_NAME, + provider: DELETE_PIPELINE_PROVIDER_NAME, + log: CONSUMER_LOG, + dir: CONTRACT_DIR, + }, + + (provider) => { + describe(DELETE_PIPELINE_PROVIDER_NAME, () => { + beforeEach(async () => { + const query = await extractGraphQLQuery( + 'app/assets/javascripts/pipelines/graphql/mutations/delete_pipeline.mutation.graphql', + ); + const graphqlQuery = new GraphQLInteraction() + .given(DeletePipeline.scenario.state) + .uponReceiving(DeletePipeline.scenario.uponReceiving) + .withQuery(query) + .withRequest(DeletePipeline.request) + .withVariables(DeletePipeline.variables) + .willRespondWith(DeletePipeline.success); + + provider.addInteraction(graphqlQuery); + }); + + it('returns a successful body', async () => { + const deletePipelineResponse = await deletePipeline({ + url: provider.mockService.baseUrl, + }); + + expect(deletePipelineResponse.status).toEqual(DeletePipeline.success.status); + }); + }); + }, +); |