diff options
Diffstat (limited to 'spec/frontend_integration/test_helpers')
5 files changed, 35 insertions, 7 deletions
diff --git a/spec/frontend_integration/test_helpers/fixtures.js b/spec/frontend_integration/test_helpers/fixtures.js index b2768440607..5673e36197f 100644 --- a/spec/frontend_integration/test_helpers/fixtures.js +++ b/spec/frontend_integration/test_helpers/fixtures.js @@ -40,6 +40,12 @@ export const getMergeRequestVersions = factory.json(() => export const getRepositoryFiles = factory.json(() => require('test_fixtures/projects_json/files.json'), ); +export const getDiffsMetadata = factory.json(() => + require('test_fixtures/merge_request_diffs/diffs_metadata.json'), +); +export const getDiffsBatch = factory.json(() => + require('test_fixtures/merge_request_diffs/diffs_batch.json'), +); export const getPipelinesEmptyResponse = factory.json(() => require('test_fixtures/projects_json/pipelines_empty.json'), ); diff --git a/spec/frontend_integration/test_helpers/mock_server/graphql.js b/spec/frontend_integration/test_helpers/mock_server/graphql.js index e2658852599..27396842523 100644 --- a/spec/frontend_integration/test_helpers/mock_server/graphql.js +++ b/spec/frontend_integration/test_helpers/mock_server/graphql.js @@ -1,13 +1,11 @@ import { buildSchema, graphql } from 'graphql'; +import { memoize } from 'lodash'; -/* eslint-disable import/no-unresolved */ -// This rule is disabled for the following line. // The graphql schema is dynamically generated in CI // during the `graphql-schema-dump` job. -import gitlabSchemaStr from '../../../../tmp/tests/graphql/gitlab_schema.graphql'; -/* eslint-enable import/no-unresolved */ +// eslint-disable-next-line global-require, import/no-unresolved +const getGraphqlSchema = () => require('../../../../tmp/tests/graphql/gitlab_schema.graphql'); -const graphqlSchema = buildSchema(gitlabSchemaStr.loc.source.body); const graphqlResolvers = { project({ fullPath }, schema) { const result = schema.projects.findBy({ path_with_namespace: fullPath }); @@ -21,6 +19,7 @@ const graphqlResolvers = { }; }, }; +const buildGraphqlSchema = memoize(() => buildSchema(getGraphqlSchema().loc.source.body)); export const graphqlQuery = (query, variables, schema) => - graphql(graphqlSchema, query, graphqlResolvers, schema, variables); + graphql(buildGraphqlSchema(), query, graphqlResolvers, schema, variables); diff --git a/spec/frontend_integration/test_helpers/mock_server/index.js b/spec/frontend_integration/test_helpers/mock_server/index.js index 20cb441daa7..486c9452dbd 100644 --- a/spec/frontend_integration/test_helpers/mock_server/index.js +++ b/spec/frontend_integration/test_helpers/mock_server/index.js @@ -1,4 +1,5 @@ import { Server, Model, RestSerializer } from 'miragejs'; +import setupRoutes from 'ee_else_ce_test_helpers/mock_server/routes'; import { getProject, getEmptyProject, @@ -11,7 +12,6 @@ import { getBlobImage, getBlobZip, } from 'test_helpers/fixtures'; -import setupRoutes from './routes'; export const createMockServerOptions = () => ({ models: { diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/diffs.js b/spec/frontend_integration/test_helpers/mock_server/routes/diffs.js new file mode 100644 index 00000000000..8301627e842 --- /dev/null +++ b/spec/frontend_integration/test_helpers/mock_server/routes/diffs.js @@ -0,0 +1,22 @@ +import { getDiffsMetadata, getDiffsBatch } from 'test_helpers/fixtures'; +import { withValues } from 'test_helpers/utils/obj'; + +export default (server) => { + server.get('/:namespace/:project/-/merge_requests/:mrid/diffs_metadata.json', () => { + return getDiffsMetadata(); + }); + + server.get('/:namespace/:project/-/merge_requests/:mrid/diffs_batch.json', () => { + const { pagination, ...result } = getDiffsBatch(); + + return { + ...result, + pagination: withValues(pagination, { + current_page: null, + next_page: null, + total_pages: 1, + next_page_href: null, + }), + }; + }); +}; diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/index.js b/spec/frontend_integration/test_helpers/mock_server/routes/index.js index e30fecf2f06..48eff2702dd 100644 --- a/spec/frontend_integration/test_helpers/mock_server/routes/index.js +++ b/spec/frontend_integration/test_helpers/mock_server/routes/index.js @@ -5,6 +5,7 @@ export default (server) => { require('./projects'), require('./repository'), require('./ci'), + require('./diffs'), require('./404'), ].forEach(({ default: setup }) => { setup(server); |