Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend_integration/test_helpers/mock_server/routes/repository.js')
-rw-r--r--spec/frontend_integration/test_helpers/mock_server/routes/repository.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/repository.js b/spec/frontend_integration/test_helpers/mock_server/routes/repository.js
new file mode 100644
index 00000000000..c5e91c9e87e
--- /dev/null
+++ b/spec/frontend_integration/test_helpers/mock_server/routes/repository.js
@@ -0,0 +1,38 @@
+import { createNewCommit, createCommitIdGenerator } from 'test_helpers/factories';
+
+export default server => {
+ const commitIdGenerator = createCommitIdGenerator();
+
+ server.get('/api/v4/projects/:id/repository/branches', schema => {
+ return schema.db.branches;
+ });
+
+ server.get('/api/v4/projects/:id/repository/branches/:name', (schema, request) => {
+ const { name } = request.params;
+
+ const branch = schema.branches.findBy({ name });
+
+ return branch.attrs;
+ });
+
+ server.get('*/-/files/:id', schema => {
+ return schema.db.files.map(({ path }) => path);
+ });
+
+ server.post('/api/v4/projects/:id/repository/commits', (schema, request) => {
+ const { branch: branchName, commit_message: message, actions } = JSON.parse(
+ request.requestBody,
+ );
+
+ const branch = schema.branches.findBy({ name: branchName });
+
+ const commit = {
+ ...createNewCommit({ id: commitIdGenerator.next(), message }, branch.attrs.commit),
+ __actions: actions,
+ };
+
+ branch.update({ commit });
+
+ return commit;
+ });
+};