Commit 31fddefc authored by Chad Woolley's avatar Chad Woolley

Address review feedback

Improve tests and address other feedback
parent e2fb7374
......@@ -461,11 +461,12 @@ const Api = {
},
issueTemplate(namespacePath, projectPath, key, type, callback) {
const url = Api.buildUrl(Api.issuableTemplatePath)
.replace(':key', encodeURIComponent(key))
.replace(':type', type)
.replace(':project_path', projectPath)
.replace(':namespace_path', namespacePath);
const url = this.buildIssueTemplateUrl(
Api.issuableTemplatePath,
type,
projectPath,
namespacePath,
).replace(':key', encodeURIComponent(key));
return axios
.get(url)
.then(({ data }) => callback(null, data))
......@@ -473,16 +474,25 @@ const Api = {
},
issueTemplates(namespacePath, projectPath, type, callback) {
const url = Api.buildUrl(Api.issuableTemplatesPath)
.replace(':type', type)
.replace(':project_path', projectPath)
.replace(':namespace_path', namespacePath);
const url = this.buildIssueTemplateUrl(
Api.issuableTemplatesPath,
type,
projectPath,
namespacePath,
);
return axios
.get(url)
.then(({ data }) => callback(null, data))
.catch(callback);
},
buildIssueTemplateUrl(path, type, projectPath, namespacePath) {
return Api.buildUrl(path)
.replace(':type', type)
.replace(':project_path', projectPath)
.replace(':namespace_path', namespacePath);
},
users(query, options) {
const url = Api.buildUrl(this.usersPath);
return axios.get(url, {
......
......@@ -66,7 +66,8 @@ export default {
this.$refs.modal.hide();
},
initTemplates() {
Api.issueTemplates(this.namespace, this.project, ISSUABLE_TYPE, (err, templates) => {
const { namespace, project } = this;
Api.issueTemplates(namespace, project, ISSUABLE_TYPE, (err, templates) => {
if (err) return; // Error handled by global AJAX error handler
this.mergeRequestTemplates = templates;
});
......
......@@ -553,7 +553,6 @@ describe('Api', () => {
});
describe('issueTemplate', () => {
it('fetches an issue template', done => {
const namespace = 'some namespace';
const project = 'some project';
const templateKey = ' template #%?.key ';
......@@ -561,6 +560,8 @@ describe('Api', () => {
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(
templateKey,
)}`;
it('fetches an issue template', done => {
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => {
......@@ -568,14 +569,25 @@ describe('Api', () => {
done();
});
});
describe('when an error occurs while fetching an issue template', () => {
it('rejects the Promise', () => {
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
Api.issueTemplate(namespace, project, templateKey, templateType, () => {
expect(mock.history.get).toHaveLength(1);
});
});
});
});
describe('issueTemplates', () => {
it('fetches all templates by type', done => {
const namespace = 'some namespace';
const project = 'some project';
const templateType = 'template type';
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}`;
it('fetches all templates by type', done => {
const expectedData = [
{ key: 'Template1', name: 'Template 1', content: 'This is template 1!' },
];
......@@ -590,6 +602,16 @@ describe('Api', () => {
done();
});
});
describe('when an error occurs while fetching issue templates', () => {
it('rejects the Promise', () => {
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
Api.issueTemplates(namespace, project, templateType, () => {
expect(mock.history.get).toHaveLength(1);
});
});
});
});
describe('projectTemplates', () => {
......
......@@ -36,8 +36,9 @@ describe('~/static_site_editor/components/edit_meta_modal.vue', () => {
const buildMockAxios = () => {
mockAxios = new MockAdapter(axios);
const templatesMergeRequestsPath = `templates/merge_request`;
mockAxios
.onGet(`${namespace}/${project}/templates/merge_request`)
.onGet(`${namespace}/${project}/${templatesMergeRequestsPath}`)
.reply(200, mergeRequestTemplates);
};
......
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