Commit 071e3d7d authored by Nick Thomas's avatar Nick Thomas

Remove now-unused methods in api.js and add tests

parent 08dd4408
...@@ -15,12 +15,7 @@ const Api = { ...@@ -15,12 +15,7 @@ const Api = {
mergeRequestChangesPath: '/api/:version/projects/:id/merge_requests/:mrid/changes', mergeRequestChangesPath: '/api/:version/projects/:id/merge_requests/:mrid/changes',
mergeRequestVersionsPath: '/api/:version/projects/:id/merge_requests/:mrid/versions', mergeRequestVersionsPath: '/api/:version/projects/:id/merge_requests/:mrid/versions',
groupLabelsPath: '/groups/:namespace_path/-/labels', groupLabelsPath: '/groups/:namespace_path/-/labels',
templatesPath: '/api/:version/templates/:key',
licensePath: '/api/:version/templates/licenses/:key',
gitignorePath: '/api/:version/templates/gitignores/:key',
gitlabCiYmlPath: '/api/:version/templates/gitlab_ci_ymls/:key',
ldapGroupsPath: '/api/:version/ldap/:provider/groups.json', ldapGroupsPath: '/api/:version/ldap/:provider/groups.json',
dockerfilePath: '/api/:version/templates/dockerfiles/:key',
issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key', issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key',
projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key', projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key',
projectTemplatesPath: '/api/:version/projects/:id/templates/:type', projectTemplatesPath: '/api/:version/projects/:id/templates/:type',
...@@ -200,31 +195,6 @@ const Api = { ...@@ -200,31 +195,6 @@ const Api = {
return axios.get(url); return axios.get(url);
}, },
// Return text for a specific license
licenseText(key, data, callback) {
const url = Api.buildUrl(Api.licensePath).replace(':key', key);
return axios
.get(url, {
params: data,
})
.then(res => callback(res.data));
},
gitignoreText(key, callback) {
const url = Api.buildUrl(Api.gitignorePath).replace(':key', key);
return axios.get(url).then(({ data }) => callback(data));
},
gitlabCiYml(key, callback) {
const url = Api.buildUrl(Api.gitlabCiYmlPath).replace(':key', key);
return axios.get(url).then(({ data }) => callback(data));
},
dockerfileYml(key, callback) {
const url = Api.buildUrl(Api.dockerfilePath).replace(':key', key);
return axios.get(url).then(({ data }) => callback(data));
},
projectTemplate(id, type, key, options, callback) { projectTemplate(id, type, key, options, callback) {
const url = Api.buildUrl(this.projectTemplatePath) const url = Api.buildUrl(this.projectTemplatePath)
.replace(':id', encodeURIComponent(id)) .replace(':id', encodeURIComponent(id))
...@@ -305,12 +275,6 @@ const Api = { ...@@ -305,12 +275,6 @@ const Api = {
}); });
}, },
templates(key, params = {}) {
const url = Api.buildUrl(this.templatesPath).replace(':key', key);
return axios.get(url, { params });
},
approverUsers(search, options, callback = $.noop) { approverUsers(search, options, callback = $.noop) {
const url = Api.buildUrl('/autocomplete/users.json'); const url = Api.buildUrl('/autocomplete/users.json');
return axios return axios
......
...@@ -66,9 +66,6 @@ export default class TemplateSelector { ...@@ -66,9 +66,6 @@ export default class TemplateSelector {
// be added by all subclasses. // be added by all subclasses.
} }
// To be implemented on the extending class
// e.g. Api.gitlabCiYml(query.name, file => this.setEditorContent(file));
setEditorContent(file, { skipFocus } = {}) { setEditorContent(file, { skipFocus } = {}) {
if (!file) return; if (!file) return;
......
...@@ -250,71 +250,45 @@ describe('Api', () => { ...@@ -250,71 +250,45 @@ describe('Api', () => {
}); });
}); });
describe('licenseText', () => { describe('issueTemplate', () => {
it('fetches a license text', done => { it('fetches an issue template', done => {
const licenseKey = "driver's license"; const namespace = 'some namespace';
const data = { unused: 'option' }; const project = 'some project';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/licenses/${licenseKey}`; const templateKey = ' template #%?.key ';
const templateType = 'template type';
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(
templateKey,
)}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.licenseText(licenseKey, data, response => { Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); done();
}); });
}); });
}); });
describe('gitignoreText', () => { describe('projectTemplates', () => {
it('fetches a gitignore text', done => { it('fetches a list of templates', done => {
const gitignoreKey = 'ignore git'; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses`;
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitignores/${gitignoreKey}`;
mock.onGet(expectedUrl).reply(200, 'test');
Api.gitignoreText(gitignoreKey, response => {
expect(response).toBe('test');
done();
});
});
});
describe('gitlabCiYml', () => {
it('fetches a .gitlab-ci.yml', done => {
const gitlabCiYmlKey = 'Y CI ML';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitlab_ci_ymls/${gitlabCiYmlKey}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.gitlabCiYml(gitlabCiYmlKey, response => { Api.projectTemplates('gitlab-org/gitlab-ce', 'licenses', {}, response => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); done();
}); });
}); });
}); });
describe('dockerfileYml', () => { describe('projectTemplate', () => {
it('fetches a Dockerfile', done => { it('fetches a single template', done => {
const dockerfileYmlKey = 'a giant whale'; const data = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/dockerfiles/${dockerfileYmlKey}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses/test%20license`;
mock.onGet(expectedUrl).reply(200, 'test');
Api.dockerfileYml(dockerfileYmlKey, response => {
expect(response).toBe('test');
done();
});
});
});
describe('issueTemplate', () => {
it('fetches an issue template', done => {
const namespace = 'some namespace';
const project = 'some project';
const templateKey = ' template #%?.key ';
const templateType = 'template type';
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(
templateKey,
)}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => { Api.projectTemplate('gitlab-org/gitlab-ce', 'licenses', 'test license', data, response => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); done();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment