debian-mirror-gitlab/spec/frontend_integration/test_helpers/mock_server/index.js

75 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { Server, Model, RestSerializer } from 'miragejs';
2021-02-22 17:27:13 +05:30
import {
getProject,
getEmptyProject,
getBranch,
getMergeRequests,
2021-03-11 19:13:27 +05:30
getMergeRequestWithChanges,
getMergeRequestVersions,
2021-02-22 17:27:13 +05:30
getRepositoryFiles,
getBlobReadme,
getBlobImage,
getBlobZip,
} from 'test_helpers/fixtures';
2020-10-24 23:57:45 +05:30
import setupRoutes from './routes';
export const createMockServerOptions = () => ({
models: {
project: Model,
branch: Model,
mergeRequest: Model,
2021-03-11 19:13:27 +05:30
mergeRequestChange: Model,
mergeRequestVersion: Model,
2020-10-24 23:57:45 +05:30
file: Model,
userPermission: Model,
},
serializers: {
application: RestSerializer.extend({
root: false,
}),
},
seeds(schema) {
schema.db.loadData({
2021-03-08 18:12:59 +05:30
files: getRepositoryFiles().map((path) => ({ path })),
2021-02-22 17:27:13 +05:30
projects: [getProject(), getEmptyProject()],
2020-10-24 23:57:45 +05:30
branches: [getBranch()],
mergeRequests: getMergeRequests(),
2021-03-11 19:13:27 +05:30
mergeRequestChanges: [getMergeRequestWithChanges()],
mergeRequestVersions: getMergeRequestVersions(),
2021-02-22 17:27:13 +05:30
filesRaw: [
{
raw: getBlobReadme(),
path: 'README.md',
},
{
raw: getBlobZip(),
path: 'Gemfile.zip',
},
{
raw: getBlobImage(),
path: 'files/images/logo-white.png',
},
],
2020-10-24 23:57:45 +05:30
userPermissions: [
{
createMergeRequestIn: true,
readMergeRequest: true,
pushCode: true,
},
],
});
},
routes() {
this.namespace = '';
this.urlPrefix = '/';
setupRoutes(this);
},
});
export const createMockServer = () => {
const server = new Server(createMockServerOptions());
return server;
};