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
|
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);
});
});
});
});
|