Adds action spec to cover 204

This commit is contained in:
Filipa Lacerda 2018-08-03 10:45:43 +01:00
parent 15511ed14f
commit 94981308a0
No known key found for this signature in database
GPG key ID: 9CA3FDE4D1E2F1C8
2 changed files with 21 additions and 7 deletions

View file

@ -43,7 +43,9 @@ export const fetchReports = ({ state, dispatch }) => {
},
data: state.endpoint,
method: 'getReports',
successCallback: (response) => dispatch('receiveReportsSuccess', response),
successCallback: ({ data, status }) => dispatch('receiveReportsSuccess', {
data, status,
}),
errorCallback: () => dispatch('receiveReportsError'),
});
@ -52,7 +54,7 @@ export const fetchReports = ({ state, dispatch }) => {
} else {
axios
.get(state.endpoint)
.then((response) => dispatch('receiveReportsSuccess', response))
.then(({ data, status }) => dispatch('receiveReportsSuccess', { data, status }))
.catch(() => dispatch('receiveReportsError'));
}

View file

@ -58,7 +58,9 @@ describe('Reports Store Actions', () => {
describe('success', () => {
it('dispatches requestReports and receiveReportsSuccess ', done => {
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { summary: {}, suites: [{ name: 'rspec' }] });
mock
.onGet(`${TEST_HOST}/endpoint.json`)
.replyOnce(200, { summary: {}, suites: [{ name: 'rspec' }] });
testAction(
fetchReports,
@ -70,7 +72,7 @@ describe('Reports Store Actions', () => {
type: 'requestReports',
},
{
payload: { summary: {}, suites: [{ name: 'rspec' }] },
payload: { data: { summary: {}, suites: [{ name: 'rspec' }] }, status: 200 },
type: 'receiveReportsSuccess',
},
],
@ -105,16 +107,27 @@ describe('Reports Store Actions', () => {
});
describe('receiveReportsSuccess', () => {
it('should commit RECEIVE_REPORTS_SUCCESS mutation', done => {
it('should commit RECEIVE_REPORTS_SUCCESS mutation with 200', done => {
testAction(
receiveReportsSuccess,
{ summary: {} },
{ data: { summary: {} }, status: 200 },
mockedState,
[{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }],
[],
done,
);
});
it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', done => {
testAction(
receiveReportsSuccess,
{ data: { summary: {} }, status: 204 },
mockedState,
[],
[],
done,
);
});
});
describe('receiveReportsError', () => {
@ -155,5 +168,4 @@ describe('Reports Store Actions', () => {
);
});
});
});