summaryrefslogtreecommitdiff
path: root/spec/frontend_integration/test_helpers/fixtures.js
blob: 5673e36197f8d7081135a998ff0e743e979da621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* eslint-disable global-require */
// We use "require" rather than `fs` so that this works in a browser environment.

/* eslint "import/no-unresolved": 0 */
// We don't want to require *all* fixtures to be generated (especailly in a local environment).
// We use `eslint` instead of `eslint-disable`, so that we also don't trigger an `Unused eslint-disable directive` when all fixtures are present.

import { memoize } from 'lodash';

const createFactoryWithDefault = (fn, defaultValue) => () => {
  try {
    return fn();
  } catch {
    return defaultValue;
  }
};

const factory = {
  json: (fn) => createFactoryWithDefault(fn, { error: 'fixture not found' }),
  text: (fn) => createFactoryWithDefault(fn, 'Hello world\nHow are you today?\n'),
  binary: (fn) => createFactoryWithDefault(fn, ''),
};

export const getProject = factory.json(() => require('test_fixtures/api/projects/get.json'));
export const getEmptyProject = factory.json(() =>
  require('test_fixtures/api/projects/get_empty.json'),
);
export const getBranch = factory.json(() =>
  require('test_fixtures/api/projects/branches/get.json'),
);
export const getMergeRequests = factory.json(() =>
  require('test_fixtures/api/merge_requests/get.json'),
);
export const getMergeRequestWithChanges = factory.json(() =>
  require('test_fixtures/api/merge_requests/changes.json'),
);
export const getMergeRequestVersions = factory.json(() =>
  require('test_fixtures/api/merge_requests/versions.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'),
);
export const getCommit = memoize(() => getBranch().commit);

export const getBlobReadme = factory.text(() => require('test_fixtures/blob/text/README.md'));
export const getBlobZip = factory.binary(() => require('test_fixtures/blob/binary/Gemfile.zip'));
export const getBlobImage = factory.binary(() =>
  require('test_fixtures/blob/images/logo-white.png'),
);