debian-mirror-gitlab/spec/frontend/ide/services/terminals_spec.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-11-11 11:23:49 +05:30
import MockAdapter from 'axios-mock-adapter';
import * as terminalService from '~/ide/services/terminals';
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
2021-11-11 11:23:49 +05:30
const TEST_PROJECT_PATH = 'lorem/ipsum/dolar';
const TEST_BRANCH = 'ref';
describe('~/ide/services/terminals', () => {
let axiosSpy;
let mock;
beforeEach(() => {
2023-04-23 21:23:45 +05:30
axiosSpy = jest.fn().mockReturnValue([HTTP_STATUS_OK, {}]);
2021-11-11 11:23:49 +05:30
mock = new MockAdapter(axios);
mock.onPost(/.*/).reply((...args) => axiosSpy(...args));
});
afterEach(() => {
mock.restore();
});
it.each`
method | relativeUrlRoot | url
${'checkConfig'} | ${''} | ${`/${TEST_PROJECT_PATH}/ide_terminals/check_config`}
${'checkConfig'} | ${'/'} | ${`/${TEST_PROJECT_PATH}/ide_terminals/check_config`}
${'checkConfig'} | ${'/gitlabbin'} | ${`/gitlabbin/${TEST_PROJECT_PATH}/ide_terminals/check_config`}
${'create'} | ${''} | ${`/${TEST_PROJECT_PATH}/ide_terminals`}
${'create'} | ${'/'} | ${`/${TEST_PROJECT_PATH}/ide_terminals`}
${'create'} | ${'/gitlabbin'} | ${`/gitlabbin/${TEST_PROJECT_PATH}/ide_terminals`}
`(
'when $method called, posts request to $url (relative_url_root=$relativeUrlRoot)',
async ({ method, url, relativeUrlRoot }) => {
gon.relative_url_root = relativeUrlRoot;
await terminalService[method](TEST_PROJECT_PATH, TEST_BRANCH);
expect(axiosSpy).toHaveBeenCalledWith(
expect.objectContaining({
data: JSON.stringify({
branch: TEST_BRANCH,
format: 'json',
}),
url,
}),
);
},
);
});