Commit 65e7054f authored by Filipa Lacerda's avatar Filipa Lacerda

Check if location key is present and improves tests

parent 7e26a4b6
...@@ -76,15 +76,18 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -76,15 +76,18 @@ export default class MergeRequestStore extends CEMergeRequestStore {
static addPathToIssues(issues, path) { static addPathToIssues(issues, path) {
return issues.map((issue) => { return issues.map((issue) => {
let parsedUrl = `${path}/${issue.location.path}`; if (issue.location) {
let parsedUrl = `${path}/${issue.location.path}`;
if (issue.location.lines && issue.location.lines.begin) { if (issue.location.lines && issue.location.lines.begin) {
parsedUrl += `#L${issue.location.lines.begin}`; parsedUrl += `#L${issue.location.lines.begin}`;
} }
return Object.assign({}, issue, { return Object.assign({}, issue, {
location: Object.assign({}, issue.location, { urlPath: parsedUrl }), location: Object.assign({}, issue.location, { urlPath: parsedUrl }),
}); });
}
return issue;
}); });
} }
} }
......
...@@ -76,5 +76,11 @@ describe('MergeRequestStore', () => { ...@@ -76,5 +76,11 @@ describe('MergeRequestStore', () => {
MergeRequestStore.addPathToIssues(headIssues, 'path')[0].location.urlPath, MergeRequestStore.addPathToIssues(headIssues, 'path')[0].location.urlPath,
).toEqual(`path/${headIssues[0].location.path}#L${headIssues[0].location.lines.begin}`); ).toEqual(`path/${headIssues[0].location.path}#L${headIssues[0].location.lines.begin}`);
}); });
it('should return the same object whe there is no locaiton', () => {
expect(
MergeRequestStore.addPathToIssues([{ check_name: 'foo' }], 'path'),
).toEqual([{ check_name: 'foo' }]);
});
}); });
}); });
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