Commit c2f29f4a authored by Tom Quirk's avatar Tom Quirk Committed by Nikola Milojevic

Address reviewer feedback

- test full Jira error messages (including links)
- Test Jira alert snapshots (frontend)
parent 4a4c9839
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ExternalIssuesListRoot error handling when request fails displays error alert with "API error" when API responds with "["API <a href=\\"gitlab.com\\">error</a>"]" 1`] = `"<span>API <a href=\\"gitlab.com\\">error</a></span>"`;
exports[`ExternalIssuesListRoot error handling when request fails displays error alert with "API error" when API responds with "["API error"]" 1`] = `"<span>API error</span>"`;
exports[`ExternalIssuesListRoot error handling when request fails displays error alert with "API" when API responds with "["API <script src=\\"hax0r.xyz\\">error</script>"]" 1`] = `"<span>API </span>"`;
exports[`ExternalIssuesListRoot error handling when request fails displays error alert with "An error occurred while loading issues" when API responds with "undefined" 1`] = `"<span>An error occurred while loading issues</span>"`;
exports[`ExternalIssuesListRoot when request succeeds renders issuable-list component with correct props 1`] = ` exports[`ExternalIssuesListRoot when request succeeds renders issuable-list component with correct props 1`] = `
Object { Object {
"currentPage": 1, "currentPage": 1,
......
...@@ -63,6 +63,7 @@ describe('ExternalIssuesListRoot', () => { ...@@ -63,6 +63,7 @@ describe('ExternalIssuesListRoot', () => {
const findIssuableList = () => wrapper.findComponent(IssuableList); const findIssuableList = () => wrapper.findComponent(IssuableList);
const findAlert = () => wrapper.findComponent(GlAlert); const findAlert = () => wrapper.findComponent(GlAlert);
const findAlertMessage = () => findAlert().find('span');
const createLabelFilterEvent = (data) => ({ type: 'labels', value: { data } }); const createLabelFilterEvent = (data) => ({ type: 'labels', value: { data } });
const createSearchFilterEvent = (data) => ({ type: 'filtered-search-term', value: { data } }); const createSearchFilterEvent = (data) => ({ type: 'filtered-search-term', value: { data } });
...@@ -319,14 +320,14 @@ describe('ExternalIssuesListRoot', () => { ...@@ -319,14 +320,14 @@ describe('ExternalIssuesListRoot', () => {
describe('when request fails', () => { describe('when request fails', () => {
it.each` it.each`
APIErrors | expectedRenderedErrorMessage APIErrors | expectedRenderedErrorText
${['API error']} | ${'API error'} ${['API error']} | ${'API error'}
${['API <a href="gitlab.com">error</a>']} | ${'API error'} ${['API <a href="gitlab.com">error</a>']} | ${'API error'}
${['API <script src="hax0r.xyz">error</script>']} | ${'API'} ${['API <script src="hax0r.xyz">error</script>']} | ${'API'}
${undefined} | ${i18n.errorFetchingIssues} ${undefined} | ${i18n.errorFetchingIssues}
`( `(
'displays error alert with "$expectedRenderedErrorMessage" when API responds with "$APIErrors"', 'displays error alert with "$expectedRenderedErrorText" when API responds with "$APIErrors"',
async ({ APIErrors, expectedRenderedErrorMessage }) => { async ({ APIErrors, expectedRenderedErrorText }) => {
jest.spyOn(axios, 'get'); jest.spyOn(axios, 'get');
mock mock
.onGet(mockProvide.issuesFetchPath) .onGet(mockProvide.issuesFetchPath)
...@@ -335,7 +336,8 @@ describe('ExternalIssuesListRoot', () => { ...@@ -335,7 +336,8 @@ describe('ExternalIssuesListRoot', () => {
createComponent(); createComponent();
await waitForPromises(); await waitForPromises();
expectErrorHandling(expectedRenderedErrorMessage); expectErrorHandling(expectedRenderedErrorText);
expect(findAlertMessage().html()).toMatchSnapshot();
}, },
); );
}); });
......
...@@ -90,7 +90,10 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do ...@@ -90,7 +90,10 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do
end end
it 'raises failure error' do it 'raises failure error' do
expect { resolve_jira_projects }.to raise_error(/^An error occurred while requesting data from Jira: Some failure\..*/) config_docs_link_url = Rails.application.routes.url_helpers.help_page_path('integration/jira/configure')
docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: config_docs_link_url }
error_message = 'An error occurred while requesting data from Jira: Some failure. Check your %{docs_link_start}Jira integration configuration</a> and try again.' % { docs_link_start: docs_link_start }
expect { resolve_jira_projects }.to raise_error(error_message)
end end
end end
end end
......
...@@ -31,6 +31,9 @@ RSpec.shared_examples 'a service that handles Jira API errors' do ...@@ -31,6 +31,9 @@ RSpec.shared_examples 'a service that handles Jira API errors' do
end end
context 'when the JSON in JIRA::HTTPError is unsafe' do context 'when the JSON in JIRA::HTTPError is unsafe' do
config_docs_link_url = Rails.application.routes.url_helpers.help_page_path('integration/jira/configure')
let(:docs_link_start) { '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: config_docs_link_url } }
before do before do
stub_client_and_raise(JIRA::HTTPError, error) stub_client_and_raise(JIRA::HTTPError, error)
end end
...@@ -39,7 +42,8 @@ RSpec.shared_examples 'a service that handles Jira API errors' do ...@@ -39,7 +42,8 @@ RSpec.shared_examples 'a service that handles Jira API errors' do
let(:error) { '{"errorMessages":' } let(:error) { '{"errorMessages":' }
it 'returns the default error message' do it 'returns the default error message' do
expect(subject.message).to start_with('An error occurred while requesting data from Jira.') error_message = 'An error occurred while requesting data from Jira. Check your %{docs_link_start}Jira integration configuration</a> and try again.' % { docs_link_start: docs_link_start }
expect(subject.message).to eq(error_message)
end end
end end
...@@ -47,7 +51,8 @@ RSpec.shared_examples 'a service that handles Jira API errors' do ...@@ -47,7 +51,8 @@ RSpec.shared_examples 'a service that handles Jira API errors' do
let(:error) { '{"errorMessages":["<script>alert(true)</script>foo"]}' } let(:error) { '{"errorMessages":["<script>alert(true)</script>foo"]}' }
it 'sanitizes it' do it 'sanitizes it' do
expect(subject.message).to start_with('An error occurred while requesting data from Jira: foo') error_message = 'An error occurred while requesting data from Jira: foo. Check your %{docs_link_start}Jira integration configuration</a> and try again.' % { docs_link_start: docs_link_start }
expect(subject.message).to eq(error_message)
end end
end end
end end
......
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