Commit 94981308 authored by Filipa Lacerda's avatar Filipa Lacerda

Adds action spec to cover 204

parent 15511ed1
...@@ -43,7 +43,9 @@ export const fetchReports = ({ state, dispatch }) => { ...@@ -43,7 +43,9 @@ export const fetchReports = ({ state, dispatch }) => {
}, },
data: state.endpoint, data: state.endpoint,
method: 'getReports', method: 'getReports',
successCallback: (response) => dispatch('receiveReportsSuccess', response), successCallback: ({ data, status }) => dispatch('receiveReportsSuccess', {
data, status,
}),
errorCallback: () => dispatch('receiveReportsError'), errorCallback: () => dispatch('receiveReportsError'),
}); });
...@@ -52,7 +54,7 @@ export const fetchReports = ({ state, dispatch }) => { ...@@ -52,7 +54,7 @@ export const fetchReports = ({ state, dispatch }) => {
} else { } else {
axios axios
.get(state.endpoint) .get(state.endpoint)
.then((response) => dispatch('receiveReportsSuccess', response)) .then(({ data, status }) => dispatch('receiveReportsSuccess', { data, status }))
.catch(() => dispatch('receiveReportsError')); .catch(() => dispatch('receiveReportsError'));
} }
......
...@@ -58,7 +58,9 @@ describe('Reports Store Actions', () => { ...@@ -58,7 +58,9 @@ describe('Reports Store Actions', () => {
describe('success', () => { describe('success', () => {
it('dispatches requestReports and receiveReportsSuccess ', done => { 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( testAction(
fetchReports, fetchReports,
...@@ -70,7 +72,7 @@ describe('Reports Store Actions', () => { ...@@ -70,7 +72,7 @@ describe('Reports Store Actions', () => {
type: 'requestReports', type: 'requestReports',
}, },
{ {
payload: { summary: {}, suites: [{ name: 'rspec' }] }, payload: { data: { summary: {}, suites: [{ name: 'rspec' }] }, status: 200 },
type: 'receiveReportsSuccess', type: 'receiveReportsSuccess',
}, },
], ],
...@@ -105,16 +107,27 @@ describe('Reports Store Actions', () => { ...@@ -105,16 +107,27 @@ describe('Reports Store Actions', () => {
}); });
describe('receiveReportsSuccess', () => { describe('receiveReportsSuccess', () => {
it('should commit RECEIVE_REPORTS_SUCCESS mutation', done => { it('should commit RECEIVE_REPORTS_SUCCESS mutation with 200', done => {
testAction( testAction(
receiveReportsSuccess, receiveReportsSuccess,
{ summary: {} }, { data: { summary: {} }, status: 200 },
mockedState, mockedState,
[{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }], [{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }],
[], [],
done, done,
); );
}); });
it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', done => {
testAction(
receiveReportsSuccess,
{ data: { summary: {} }, status: 204 },
mockedState,
[],
[],
done,
);
});
}); });
describe('receiveReportsError', () => { describe('receiveReportsError', () => {
...@@ -155,5 +168,4 @@ describe('Reports Store Actions', () => { ...@@ -155,5 +168,4 @@ describe('Reports Store Actions', () => {
); );
}); });
}); });
}); });
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