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:
authorPaul Slaughter <pslaughter@gitlab.com>2019-06-17 20:53:58 +0300
committerPaul Slaughter <pslaughter@gitlab.com>2019-06-17 22:04:35 +0300
commit894ad6f6e983cb17c7b63b4185c63a42b6203a4f (patch)
treebd3990e5b4fe0e9521287bf0c327925a82084c50 /spec/frontend/ide/services
parent89a89b3230717920410de6fb6d6b7152ef41a03e (diff)
Fix IDE commit to use start_ref
**Why?** The branch HEAD could be changed since the IDE was opened. This leads to user's unintentionally creating commits that overwrite other changes. https://gitlab.com/gitlab-org/gitlab-ce/issues/59023
Diffstat (limited to 'spec/frontend/ide/services')
-rw-r--r--spec/frontend/ide/services/index_spec.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/frontend/ide/services/index_spec.js b/spec/frontend/ide/services/index_spec.js
new file mode 100644
index 00000000000..499fa8fc012
--- /dev/null
+++ b/spec/frontend/ide/services/index_spec.js
@@ -0,0 +1,55 @@
+import services from '~/ide/services';
+import Api from '~/api';
+
+jest.mock('~/api');
+
+const TEST_PROJECT_ID = 'alice/wonderland';
+const TEST_BRANCH = 'master-patch-123';
+const TEST_COMMIT_SHA = '123456789';
+
+describe('IDE services', () => {
+ describe('commit', () => {
+ let payload;
+
+ beforeEach(() => {
+ payload = {
+ branch: TEST_BRANCH,
+ commit_message: 'Hello world',
+ actions: [],
+ start_sha: undefined,
+ };
+
+ Api.createBranch.mockReturnValue(Promise.resolve());
+ Api.commitMultiple.mockReturnValue(Promise.resolve());
+ });
+
+ describe.each`
+ startSha | shouldCreateBranch
+ ${undefined} | ${false}
+ ${TEST_COMMIT_SHA} | ${true}
+ `('when start_sha is $startSha', ({ startSha, shouldCreateBranch }) => {
+ beforeEach(() => {
+ payload.start_sha = startSha;
+
+ return services.commit(TEST_PROJECT_ID, payload);
+ });
+
+ if (shouldCreateBranch) {
+ it('should create branch', () => {
+ expect(Api.createBranch).toHaveBeenCalledWith(TEST_PROJECT_ID, {
+ ref: TEST_COMMIT_SHA,
+ branch: TEST_BRANCH,
+ });
+ });
+ } else {
+ it('should not create branch', () => {
+ expect(Api.createBranch).not.toHaveBeenCalled();
+ });
+ }
+
+ it('should commit', () => {
+ expect(Api.commitMultiple).toHaveBeenCalledWith(TEST_PROJECT_ID, payload);
+ });
+ });
+ });
+});