Commit 3112fdb6 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'vs/ee-remove-jest-test-callback' into 'master'

Remove Jest test callback in EE specs

See merge request gitlab-org/gitlab!84181
parents 25be580b a0cc00ea
---
extends: ../../../spec/frontend/.eslintrc.yml
rules:
jest/no-test-callback: error
......@@ -91,8 +91,8 @@ describe('Code review analytics mergeRequests actions', () => {
mock.onGet(/api\/(.*)\/analytics\/code_review/).replyOnce(500);
});
it('dispatches error', (done) => {
testAction(
it('dispatches error', async () => {
await testAction(
actions.fetchMergeRequests,
null,
state,
......@@ -104,11 +104,9 @@ describe('Code review analytics mergeRequests actions', () => {
},
],
[],
() => {
expect(createFlash).toHaveBeenCalled();
done();
},
);
expect(createFlash).toHaveBeenCalled();
});
});
});
......
......@@ -5,7 +5,7 @@ import testAction from 'helpers/vuex_action_helper';
describe('Productivity analytics actions', () => {
describe('setEndpoint', () => {
it('commits the SET_ENDPOINT mutation', (done) =>
it('commits the SET_ENDPOINT mutation', async () =>
testAction(
actions.setEndpoint,
'endpoint.json',
......@@ -17,7 +17,6 @@ describe('Productivity analytics actions', () => {
},
],
[],
done,
));
});
});
......@@ -72,7 +72,7 @@ describe('Productivity analytics chart actions', () => {
expect(axios.get).toHaveBeenCalledWith(mockedState.endpoint, { params: globalParams });
});
it('dispatches success with received data', (done) =>
it('dispatches success with received data', async () =>
testAction(
actions.fetchChartData,
chartKey,
......@@ -85,7 +85,6 @@ describe('Productivity analytics chart actions', () => {
payload: expect.objectContaining({ chartKey, data: mockHistogramData }),
},
],
done,
));
});
......@@ -94,8 +93,8 @@ describe('Productivity analytics chart actions', () => {
mock.onGet(mockedState.endpoint).replyOnce(200, mockScatterplotData);
});
it('dispatches success with received data and transformedData', (done) => {
testAction(
it('dispatches success with received data and transformedData', async () => {
await testAction(
actions.fetchChartData,
chartKeys.scatterplot,
mockedState,
......@@ -111,7 +110,6 @@ describe('Productivity analytics chart actions', () => {
},
},
],
done,
);
});
});
......@@ -122,8 +120,8 @@ describe('Productivity analytics chart actions', () => {
mock.onGet(mockedState.endpoint).replyOnce(500);
});
it('dispatches error', (done) => {
testAction(
it('dispatches error', async () => {
await testAction(
actions.fetchChartData,
chartKey,
mockedState,
......@@ -141,7 +139,6 @@ describe('Productivity analytics chart actions', () => {
},
},
],
done,
);
});
});
......@@ -149,14 +146,13 @@ describe('Productivity analytics chart actions', () => {
});
describe('requestChartData', () => {
it('should commit the request mutation', (done) => {
testAction(
it('should commit the request mutation', async () => {
await testAction(
actions.requestChartData,
chartKey,
mockedContext.state,
[{ type: types.REQUEST_CHART_DATA, payload: chartKey }],
[],
done,
);
});
......@@ -167,8 +163,8 @@ describe('Productivity analytics chart actions', () => {
mockedState.charts[disabledChartKey].enabled = false;
});
it('does not dispatch the requestChartData action', (done) => {
testAction(actions.fetchChartData, disabledChartKey, mockedState, [], [], done);
it('does not dispatch the requestChartData action', async () => {
await testAction(actions.fetchChartData, disabledChartKey, mockedState, [], []);
});
it('does not call the API', () => {
......@@ -180,8 +176,8 @@ describe('Productivity analytics chart actions', () => {
});
describe('receiveChartDataSuccess', () => {
it('should commit received data', (done) => {
testAction(
it('should commit received data', async () => {
await testAction(
actions.receiveChartDataSuccess,
{ chartKey, data: mockHistogramData },
mockedContext.state,
......@@ -192,15 +188,14 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
describe('receiveChartDataError', () => {
it('should commit error', (done) => {
it('should commit error', async () => {
const error = { response: { status: 500 } };
testAction(
await testAction(
actions.receiveChartDataError,
{ chartKey, error },
mockedContext.state,
......@@ -214,14 +209,13 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
describe('fetchSecondaryChartData', () => {
it('dispatches fetchChartData for all chart types except for the main chart', (done) => {
testAction(
it('dispatches fetchChartData for all chart types except for the main chart', async () => {
await testAction(
actions.fetchSecondaryChartData,
null,
mockedContext.state,
......@@ -231,7 +225,6 @@ describe('Productivity analytics chart actions', () => {
{ type: 'fetchChartData', payload: chartKeys.commitBasedHistogram },
{ type: 'fetchChartData', payload: chartKeys.scatterplot },
],
done,
);
});
});
......@@ -239,48 +232,45 @@ describe('Productivity analytics chart actions', () => {
describe('setMetricType', () => {
const metricType = 'time_to_merge';
it('should commit metricType', (done) => {
testAction(
it('should commit metricType', async () => {
await testAction(
actions.setMetricType,
{ chartKey, metricType },
mockedContext.state,
[{ type: types.SET_METRIC_TYPE, payload: { chartKey, metricType } }],
[{ type: 'fetchChartData', payload: chartKey }],
done,
);
});
});
describe('updateSelectedItems', () => {
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', (done) => {
testAction(
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', async () => {
await testAction(
actions.updateSelectedItems,
{ chartKey, item: 5 },
mockedContext.state,
[{ type: types.UPDATE_SELECTED_CHART_ITEMS, payload: { chartKey, item: 5 } }],
[{ type: 'fetchSecondaryChartData' }, { type: 'table/setPage', payload: 0 }],
done,
);
});
});
describe('resetMainChartSelection', () => {
describe('when skipReload is false (by default)', () => {
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', (done) => {
testAction(
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', async () => {
await testAction(
actions.resetMainChartSelection,
null,
mockedContext.state,
[{ type: types.UPDATE_SELECTED_CHART_ITEMS, payload: { chartKey, item: null } }],
[{ type: 'fetchSecondaryChartData' }, { type: 'table/setPage', payload: 0 }],
done,
);
});
});
describe('when skipReload is true', () => {
it('should commit selected chart and it should not dispatch any further actions', (done) => {
testAction(
it('should commit selected chart and it should not dispatch any further actions', async () => {
await testAction(
actions.resetMainChartSelection,
true,
mockedContext.state,
......@@ -291,15 +281,14 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
});
describe('setChartEnabled', () => {
it('should commit enabled state', (done) => {
testAction(
it('should commit enabled state', async () => {
await testAction(
actions.setChartEnabled,
{ chartKey: chartKeys.scatterplot, isEnabled: false },
mockedContext.state,
......@@ -310,7 +299,6 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -30,31 +30,26 @@ describe('Productivity analytics filter actions', () => {
});
describe('setInitialData', () => {
it('commits the SET_INITIAL_DATA mutation and fetches data by default', (done) => {
actions
.setInitialData(store, { data: initialData })
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_INITIAL_DATA, initialData);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_INITIAL_DATA mutation and fetches data by default', async () => {
await actions.setInitialData(store, { data: initialData });
expect(store.commit).toHaveBeenCalledWith(types.SET_INITIAL_DATA, initialData);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual(['table/setPage', 0, { root: true }]);
});
it("commits the SET_INITIAL_DATA mutation and doesn't fetch data when skipFetch=true", (done) =>
it("commits the SET_INITIAL_DATA mutation and doesn't fetch data when skipFetch=true", async () =>
testAction(
actions.setInitialData,
{ skipFetch: true, data: initialData },
......@@ -66,135 +61,114 @@ describe('Productivity analytics filter actions', () => {
},
],
[],
done,
));
});
describe('setGroupNamespace', () => {
it('commits the SET_GROUP_NAMESPACE mutation', (done) => {
actions
.setGroupNamespace(store, groupNamespace)
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_GROUP_NAMESPACE, groupNamespace);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_GROUP_NAMESPACE mutation', async () => {
await actions.setGroupNamespace(store, groupNamespace);
expect(store.commit).toHaveBeenCalledWith(types.SET_GROUP_NAMESPACE, groupNamespace);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
describe('setProjectPath', () => {
it('commits the SET_PROJECT_PATH mutation', (done) => {
actions
.setProjectPath(store, projectPath)
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_PROJECT_PATH, projectPath);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_PROJECT_PATH mutation', async () => {
await actions.setProjectPath(store, projectPath);
expect(store.commit).toHaveBeenCalledWith(types.SET_PROJECT_PATH, projectPath);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
describe('setFilters', () => {
it('commits the SET_FILTERS mutation', (done) => {
actions
.setFilters(store, { author_username: 'root' })
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_FILTERS, { authorUsername: 'root' });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_FILTERS mutation', async () => {
await actions.setFilters(store, { author_username: 'root' });
expect(store.commit).toHaveBeenCalledWith(types.SET_FILTERS, { authorUsername: 'root' });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
describe('setDateRange', () => {
it('commits the SET_DATE_RANGE mutation', (done) => {
actions
.setDateRange(store, { startDate, endDate })
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_DATE_RANGE, { startDate, endDate });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_DATE_RANGE mutation', async () => {
await actions.setDateRange(store, { startDate, endDate });
expect(store.commit).toHaveBeenCalledWith(types.SET_DATE_RANGE, { startDate, endDate });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
});
......@@ -104,7 +104,7 @@ describe('Productivity analytics table actions', () => {
});
});
it('dispatches success with received data', (done) =>
it('dispatches success with received data', async () =>
testAction(
actions.fetchMergeRequests,
null,
......@@ -117,7 +117,6 @@ describe('Productivity analytics table actions', () => {
payload: { data: mockMergeRequests, headers },
},
],
done,
));
});
......@@ -126,8 +125,8 @@ describe('Productivity analytics table actions', () => {
mock.onGet(mockedState.endpoint).replyOnce(500);
});
it('dispatches error', (done) => {
testAction(
it('dispatches error', async () => {
await testAction(
actions.fetchMergeRequests,
null,
mockedState,
......@@ -139,26 +138,24 @@ describe('Productivity analytics table actions', () => {
payload: new Error('Request failed with status code 500'),
},
],
done,
);
});
});
});
describe('requestMergeRequests', () => {
it('should commit the request mutation', (done) =>
it('should commit the request mutation', async () =>
testAction(
actions.requestMergeRequests,
null,
mockedContext.state,
[{ type: types.REQUEST_MERGE_REQUESTS }],
[],
done,
));
});
describe('receiveMergeRequestsSuccess', () => {
it('should commit received data', (done) =>
it('should commit received data', async () =>
testAction(
actions.receiveMergeRequestsSuccess,
{ headers, data: mockMergeRequests },
......@@ -170,24 +167,22 @@ describe('Productivity analytics table actions', () => {
},
],
[],
done,
));
});
describe('receiveMergeRequestsError', () => {
it('should commit error', (done) =>
it('should commit error', async () =>
testAction(
actions.receiveMergeRequestsError,
{ response: { status: 500 } },
mockedContext.state,
[{ type: types.RECEIVE_MERGE_REQUESTS_ERROR, payload: 500 }],
[],
done,
));
});
describe('setSortField', () => {
it('should commit setSortField', (done) =>
it('should commit setSortField', async () =>
testAction(
actions.setSortField,
'time_to_last_commit',
......@@ -197,53 +192,48 @@ describe('Productivity analytics table actions', () => {
{ type: 'setColumnMetric', payload: 'time_to_last_commit' },
{ type: 'fetchMergeRequests' },
],
done,
));
it('should not dispatch setColumnMetric when metric is "days_to_merge"', (done) =>
it('should not dispatch setColumnMetric when metric is "days_to_merge"', async () =>
testAction(
actions.setSortField,
'days_to_merge',
mockedContext.state,
[{ type: types.SET_SORT_FIELD, payload: 'days_to_merge' }],
[{ type: 'fetchMergeRequests' }],
done,
));
});
describe('toggleSortOrder', () => {
it('should commit toggleSortOrder', (done) =>
it('should commit toggleSortOrder', async () =>
testAction(
actions.toggleSortOrder,
null,
mockedContext.state,
[{ type: types.TOGGLE_SORT_ORDER }],
[{ type: 'fetchMergeRequests' }],
done,
));
});
describe('setColumnMetric', () => {
it('should commit setColumnMetric', (done) =>
it('should commit setColumnMetric', async () =>
testAction(
actions.setColumnMetric,
'time_to_first_comment',
mockedContext.state,
[{ type: types.SET_COLUMN_METRIC, payload: 'time_to_first_comment' }],
[],
done,
));
});
describe('setPage', () => {
it('should commit setPage', (done) =>
it('should commit setPage', async () =>
testAction(
actions.setPage,
2,
mockedContext.state,
[{ type: types.SET_PAGE, payload: 2 }],
[{ type: 'fetchMergeRequests' }],
done,
));
});
});
......@@ -43,7 +43,7 @@ describe('Api', () => {
});
describe('ldapGroups', () => {
it('calls callback on completion', (done) => {
it('calls callback on completion', async () => {
const query = 'query';
const provider = 'provider';
const callback = jest.fn();
......@@ -55,17 +55,13 @@ describe('Api', () => {
},
]);
Api.ldapGroups(query, provider, callback)
.then((response) => {
expect(callback).toHaveBeenCalledWith(response);
})
.then(done)
.catch(done.fail);
const response = await Api.ldapGroups(query, provider, callback);
expect(callback).toHaveBeenCalledWith(response);
});
});
describe('createChildEpic', () => {
it('calls `axios.post` using params `groupId`, `parentEpicIid` and title', (done) => {
it('calls `axios.post` using params `groupId`, `parentEpicIid` and title', async () => {
const groupId = 'gitlab-org';
const parentEpicId = 1;
const title = 'Sample epic';
......@@ -78,19 +74,15 @@ describe('Api', () => {
mock.onPost(expectedUrl).reply(httpStatus.OK, expectedRes);
Api.createChildEpic({ groupId, parentEpicId, title })
.then(({ data }) => {
expect(data.title).toBe(expectedRes.title);
expect(data.id).toBe(expectedRes.id);
expect(data.parentId).toBe(expectedRes.parentId);
})
.then(done)
.catch(done.fail);
const { data } = await Api.createChildEpic({ groupId, parentEpicId, title });
expect(data.title).toBe(expectedRes.title);
expect(data.id).toBe(expectedRes.id);
expect(data.parentId).toBe(expectedRes.parentId);
});
});
describe('groupEpics', () => {
it('calls `axios.get` using param `groupId`', (done) => {
it('calls `axios.get` using param `groupId`', async () => {
const groupId = 2;
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/epics`;
......@@ -103,20 +95,16 @@ describe('Api', () => {
})
.reply(httpStatus.OK, mockEpics);
Api.groupEpics({ groupId })
.then(({ data }) => {
data.forEach((epic, index) => {
expect(epic.id).toBe(mockEpics[index].id);
expect(epic.iid).toBe(mockEpics[index].iid);
expect(epic.group_id).toBe(mockEpics[index].group_id);
expect(epic.title).toBe(mockEpics[index].title);
});
})
.then(done)
.catch(done.fail);
const { data } = await Api.groupEpics({ groupId });
data.forEach((epic, index) => {
expect(epic.id).toBe(mockEpics[index].id);
expect(epic.iid).toBe(mockEpics[index].iid);
expect(epic.group_id).toBe(mockEpics[index].group_id);
expect(epic.title).toBe(mockEpics[index].title);
});
});
it('calls `axios.get` using param `search` when it is provided', (done) => {
it('calls `axios.get` using param `search` when it is provided', async () => {
const groupId = 2;
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/epics`;
......@@ -130,22 +118,18 @@ describe('Api', () => {
})
.reply(httpStatus.OK, mockEpics);
Api.groupEpics({ groupId, search: 'foo' })
.then(({ data }) => {
data.forEach((epic, index) => {
expect(epic.id).toBe(mockEpics[index].id);
expect(epic.iid).toBe(mockEpics[index].iid);
expect(epic.group_id).toBe(mockEpics[index].group_id);
expect(epic.title).toBe(mockEpics[index].title);
});
})
.then(done)
.catch(done.fail);
const { data } = await Api.groupEpics({ groupId, search: 'foo' });
data.forEach((epic, index) => {
expect(epic.id).toBe(mockEpics[index].id);
expect(epic.iid).toBe(mockEpics[index].iid);
expect(epic.group_id).toBe(mockEpics[index].group_id);
expect(epic.title).toBe(mockEpics[index].title);
});
});
});
describe('addEpicIssue', () => {
it('calls `axios.post` using params `groupId`, `epicIid` and `issueId`', (done) => {
it('calls `axios.post` using params `groupId`, `epicIid` and `issueId`', async () => {
const groupId = 2;
const mockIssue = {
id: 20,
......@@ -159,19 +143,19 @@ describe('Api', () => {
mock.onPost(expectedUrl).reply(httpStatus.OK, expectedRes);
Api.addEpicIssue({ groupId, epicIid: mockEpics[0].iid, issueId: mockIssue.id })
.then(({ data }) => {
expect(data.id).toBe(expectedRes.id);
expect(data.epic).toEqual(expect.objectContaining({ ...expectedRes.epic }));
expect(data.issue).toEqual(expect.objectContaining({ ...expectedRes.issue }));
})
.then(done)
.catch(done.fail);
const { data } = await Api.addEpicIssue({
groupId,
epicIid: mockEpics[0].iid,
issueId: mockIssue.id,
});
expect(data.id).toBe(expectedRes.id);
expect(data.epic).toEqual(expect.objectContaining({ ...expectedRes.epic }));
expect(data.issue).toEqual(expect.objectContaining({ ...expectedRes.issue }));
});
});
describe('removeEpicIssue', () => {
it('calls `axios.delete` using params `groupId`, `epicIid` and `epicIssueId`', (done) => {
it('calls `axios.delete` using params `groupId`, `epicIid` and `epicIssueId`', async () => {
const groupId = 2;
const mockIssue = {
id: 20,
......@@ -186,18 +170,14 @@ describe('Api', () => {
mock.onDelete(expectedUrl).reply(httpStatus.OK, expectedRes);
Api.removeEpicIssue({
const { data } = await Api.removeEpicIssue({
groupId,
epicIid: mockEpics[0].iid,
epicIssueId: mockIssue.epic_issue_id,
})
.then(({ data }) => {
expect(data.id).toBe(expectedRes.id);
expect(data.epic).toEqual(expect.objectContaining({ ...expectedRes.epic }));
expect(data.issue).toEqual(expect.objectContaining({ ...expectedRes.issue }));
})
.then(done)
.catch(done.fail);
});
expect(data.id).toBe(expectedRes.id);
expect(data.epic).toEqual(expect.objectContaining({ ...expectedRes.epic }));
expect(data.issue).toEqual(expect.objectContaining({ ...expectedRes.issue }));
});
});
......@@ -228,7 +208,7 @@ describe('Api', () => {
};
describe('cycleAnalyticsTasksByType', () => {
it('fetches tasks by type data', (done) => {
it('fetches tasks by type data', async () => {
const tasksByTypeResponse = [
{
label: {
......@@ -256,18 +236,17 @@ describe('Api', () => {
const expectedUrl = analyticsMockData.endpoints.tasksByTypeData;
mock.onGet(expectedUrl).reply(httpStatus.OK, tasksByTypeResponse);
Api.cycleAnalyticsTasksByType(groupId, params)
.then(({ data, config: { params: reqParams } }) => {
expect(data).toEqual(tasksByTypeResponse);
expect(reqParams).toEqual(params);
})
.then(done)
.catch(done.fail);
const {
data,
config: { params: reqParams },
} = await Api.cycleAnalyticsTasksByType(groupId, params);
expect(data).toEqual(tasksByTypeResponse);
expect(reqParams).toEqual(params);
});
});
describe('cycleAnalyticsTopLabels', () => {
it('fetches top group level labels', (done) => {
it('fetches top group level labels', async () => {
const response = [];
const labelIds = [10, 9, 8, 7];
const params = {
......@@ -280,89 +259,85 @@ describe('Api', () => {
const expectedUrl = analyticsMockData.endpoints.tasksByTypeTopLabelsData;
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsTopLabels(groupId, params)
.then(({ data, config: { url, params: reqParams } }) => {
expect(data).toEqual(response);
expect(url).toMatch(expectedUrl);
expect(reqParams).toEqual(params);
})
.then(done)
.catch(done.fail);
const {
data,
config: { url, params: reqParams },
} = await Api.cycleAnalyticsTopLabels(groupId, params);
expect(data).toEqual(response);
expect(url).toMatch(expectedUrl);
expect(reqParams).toEqual(params);
});
});
describe('cycleAnalyticsValueStreams', () => {
it('fetches custom value streams', (done) => {
it('fetches custom value streams', async () => {
const response = [{ name: 'value stream 1', id: 1 }];
const expectedUrl = valueStreamBaseUrl({ resource: 'value_streams' });
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsValueStreams(groupId)
.then((responseObj) =>
expectRequestWithCorrectParameters(responseObj, {
response,
expectedUrl,
}),
)
.then(done)
.catch(done.fail);
const responseObj = await Api.cycleAnalyticsValueStreams(groupId);
expectRequestWithCorrectParameters(responseObj, {
response,
expectedUrl,
});
});
});
describe('cycleAnalyticsCreateValueStream', () => {
it('submit the custom value stream data', (done) => {
it('submit the custom value stream data', async () => {
const response = {};
const customValueStream = { name: 'cool-value-stream-stage' };
const expectedUrl = valueStreamBaseUrl({ resource: 'value_streams' });
mock.onPost(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsCreateValueStream(groupId, customValueStream)
.then(({ data, config: { data: reqData, url } }) => {
expect(data).toEqual(response);
expect(JSON.parse(reqData)).toMatchObject(customValueStream);
expect(url).toEqual(expectedUrl);
})
.then(done)
.catch(done.fail);
const {
data,
config: { data: reqData, url },
} = await Api.cycleAnalyticsCreateValueStream(groupId, customValueStream);
expect(data).toEqual(response);
expect(JSON.parse(reqData)).toMatchObject(customValueStream);
expect(url).toEqual(expectedUrl);
});
});
describe('cycleAnalyticsUpdateValueStream', () => {
it('updates the custom value stream data', (done) => {
it('updates the custom value stream data', async () => {
const response = {};
const customValueStream = { name: 'cool-value-stream-stage', stages: [] };
const expectedUrl = valueStreamBaseUrl({ resource: `value_streams/${valueStreamId}` });
mock.onPut(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsUpdateValueStream({ groupId, valueStreamId, data: customValueStream })
.then(({ data, config: { data: reqData, url } }) => {
expect(data).toEqual(response);
expect(JSON.parse(reqData)).toMatchObject(customValueStream);
expect(url).toEqual(expectedUrl);
})
.then(done)
.catch(done.fail);
const {
data,
config: { data: reqData, url },
} = await Api.cycleAnalyticsUpdateValueStream({
groupId,
valueStreamId,
data: customValueStream,
});
expect(data).toEqual(response);
expect(JSON.parse(reqData)).toMatchObject(customValueStream);
expect(url).toEqual(expectedUrl);
});
});
describe('cycleAnalyticsDeleteValueStream', () => {
it('delete the custom value stream', (done) => {
it('delete the custom value stream', async () => {
const response = {};
const expectedUrl = valueStreamBaseUrl({ resource: `value_streams/${valueStreamId}` });
mock.onDelete(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsDeleteValueStream(groupId, valueStreamId)
.then(({ data, config: { url } }) => {
expect(data).toEqual(response);
expect(url).toEqual(expectedUrl);
})
.then(done)
.catch(done.fail);
const {
data,
config: { url },
} = await Api.cycleAnalyticsDeleteValueStream(groupId, valueStreamId);
expect(data).toEqual(response);
expect(url).toEqual(expectedUrl);
});
});
describe('cycleAnalyticsGroupStagesAndEvents', () => {
it('fetches custom stage events and all stages', (done) => {
it('fetches custom stage events and all stages', async () => {
const response = { events: [], stages: [] };
const params = {
group_id: groupId,
......@@ -372,21 +347,21 @@ describe('Api', () => {
const expectedUrl = valueStreamBaseUrl({ id: valueStreamId, resource: 'stages' });
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsGroupStagesAndEvents({ groupId, valueStreamId, params })
.then((responseObj) =>
expectRequestWithCorrectParameters(responseObj, {
response,
params,
expectedUrl,
}),
)
.then(done)
.catch(done.fail);
const responseObj = await Api.cycleAnalyticsGroupStagesAndEvents({
groupId,
valueStreamId,
params,
});
expectRequestWithCorrectParameters(responseObj, {
response,
params,
expectedUrl,
});
});
});
describe('cycleAnalyticsStageEvents', () => {
it('fetches stage events', (done) => {
it('fetches stage events', async () => {
const response = { events: [] };
const params = { ...defaultParams };
const expectedUrl = valueStreamBaseUrl({
......@@ -395,21 +370,22 @@ describe('Api', () => {
});
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsStageEvents({ groupId, valueStreamId, stageId, params })
.then((responseObj) =>
expectRequestWithCorrectParameters(responseObj, {
response,
params,
expectedUrl,
}),
)
.then(done)
.catch(done.fail);
const responseObj = await Api.cycleAnalyticsStageEvents({
groupId,
valueStreamId,
stageId,
params,
});
expectRequestWithCorrectParameters(responseObj, {
response,
params,
expectedUrl,
});
});
});
describe('cycleAnalyticsDurationChart', () => {
it('fetches stage duration data', (done) => {
it('fetches stage duration data', async () => {
const response = [];
const params = { ...defaultParams };
const expectedUrl = valueStreamBaseUrl({
......@@ -418,50 +394,49 @@ describe('Api', () => {
});
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsDurationChart({ groupId, valueStreamId, stageId, params })
.then((responseObj) =>
expectRequestWithCorrectParameters(responseObj, {
response,
params,
expectedUrl,
}),
)
.then(done)
.catch(done.fail);
const responseObj = await Api.cycleAnalyticsDurationChart({
groupId,
valueStreamId,
stageId,
params,
});
expectRequestWithCorrectParameters(responseObj, {
response,
params,
expectedUrl,
});
});
});
describe('cycleAnalyticsGroupLabels', () => {
it('fetches group level labels', (done) => {
it('fetches group level labels', async () => {
const response = [];
const expectedUrl = `${dummyUrlRoot}/groups/${groupId}/-/labels.json`;
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsGroupLabels(groupId)
.then(({ data, config: { url } }) => {
expect(data).toEqual(response);
expect(url).toEqual(expectedUrl);
})
.then(done)
.catch(done.fail);
const {
data,
config: { url },
} = await Api.cycleAnalyticsGroupLabels(groupId);
expect(data).toEqual(response);
expect(url).toEqual(expectedUrl);
});
});
describe('cycleAnalyticsUpdateAggregation', () => {
it('updates the aggregation enabled status', (done) => {
it('updates the aggregation enabled status', async () => {
const reqdata = { enabled: true };
const expectedUrl = `${dummyValueStreamAnalyticsUrlRoot}/use_aggregated_backend`;
mock.onPut(expectedUrl).reply(httpStatus.OK, reqdata);
Api.cycleAnalyticsUpdateAggregation(groupId, reqdata)
.then(({ data, config: { url } }) => {
expect(data).toEqual(reqdata);
expect(url).toEqual(expectedUrl);
})
.then(done)
.catch(done.fail);
const {
data,
config: { url },
} = await Api.cycleAnalyticsUpdateAggregation(groupId, reqdata);
expect(data).toEqual(reqdata);
expect(url).toEqual(expectedUrl);
});
});
});
......@@ -486,7 +461,7 @@ describe('Api', () => {
});
describe('groupActivityIssuesCount', () => {
it('fetches the number of issues created for a given group', () => {
it('fetches the number of issues created for a given group', async () => {
const response = { issues_count: 20 };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/analytics/group_activity/issues_count`;
......@@ -494,10 +469,9 @@ describe('Api', () => {
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, response);
return Api.groupActivityIssuesCount(groupId).then(({ data }) => {
expect(data).toEqual(response);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, { params: { group_path: groupId } });
});
const { data } = await Api.groupActivityIssuesCount(groupId);
expect(data).toEqual(response);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, { params: { group_path: groupId } });
});
});
......
......@@ -70,6 +70,7 @@ describe('Approvals ApproversSelect', () => {
$input = $(wrapper.vm.$refs.input);
};
const search = (term = '') => {
$input.select2('search', term);
jest.runOnlyPendingTimers();
......@@ -93,37 +94,30 @@ describe('Approvals ApproversSelect', () => {
expect(select2Container()).not.toBe(null);
});
it('queries and displays groups and users', async (done) => {
it('queries and displays groups and users', async () => {
await factory();
const expected = TEST_GROUPS.concat(TEST_USERS)
.map(({ id, ...obj }) => obj)
.map(({ username, ...obj }) => (!username ? obj : { ...obj, username: `@${username}` }));
waitForEvent($input, 'select2-loaded')
.then(() => {
const items = select2DropdownItems();
search();
expect(items).toEqual(expected);
})
.then(done)
.catch(done.fail);
await waitForEvent($input, 'select2-loaded');
const items = select2DropdownItems();
search();
expect(items).toEqual(expected);
});
describe('with search term', () => {
const term = 'lorem';
beforeEach(async (done) => {
beforeEach(async () => {
await factory();
waitForEvent($input, 'select2-loaded')
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
search(term);
await waitForEvent($input, 'select2-loaded');
});
it('fetches all available groups', () => {
......@@ -151,14 +145,11 @@ describe('Approvals ApproversSelect', () => {
});
});
it('fetches all available groups including non-visible shared groups', async (done) => {
waitForEvent($input, 'select2-loaded')
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
it('fetches all available groups including non-visible shared groups', async () => {
search();
await waitForEvent($input, 'select2-loaded');
expect(Api.projectGroups).toHaveBeenCalledWith(TEST_PROJECT_ID, {
skip_groups: [],
with_shared: true,
......@@ -172,7 +163,7 @@ describe('Approvals ApproversSelect', () => {
const skipGroupIds = [7, 8];
const skipUserIds = [9, 10];
beforeEach(async (done) => {
beforeEach(async () => {
await factory({
propsData: {
skipGroupIds,
......@@ -180,12 +171,10 @@ describe('Approvals ApproversSelect', () => {
},
});
waitForEvent($input, 'select2-loaded')
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
search();
await waitForEvent($input, 'select2-loaded');
jest.runOnlyPendingTimers();
});
it('skips groups and does not fetch all available', () => {
......@@ -202,7 +191,7 @@ describe('Approvals ApproversSelect', () => {
});
});
it('emits input when data changes', async (done) => {
it('emits input when data changes', async () => {
await factory();
const expectedFinal = [
......@@ -211,24 +200,14 @@ describe('Approvals ApproversSelect', () => {
];
const expected = expectedFinal.map((x, idx) => [expectedFinal.slice(0, idx + 1)]);
waitForEvent($input, 'select2-loaded')
.then(() => {
const options = select2DropdownOptions();
$(options[TEST_GROUPS.length]).trigger('mouseup');
$(options[0]).trigger('mouseup');
})
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
waitForEvent($input, 'change')
.then(jest.runOnlyPendingTimers)
.then(() => {
expect(wrapper.emitted().input).toEqual(expected);
})
.then(done)
.catch(done.fail);
search();
await waitForPromises();
const options = select2DropdownOptions();
$(options[TEST_GROUPS.length]).trigger('mouseup');
$(options[0]).trigger('mouseup');
await waitForPromises();
expect(wrapper.emitted().input).toEqual(expected);
});
});
......@@ -82,7 +82,7 @@ describe('EE approvals license-compliance actions', () => {
});
describe('postRule', () => {
it('posts correct data and dispatches "fetchRules" when request is successful', () => {
it('posts correct data and dispatches "fetchRules" when request is successful', async () => {
const rule = {
name: 'Foo',
approvalsRequired: 1,
......@@ -91,7 +91,7 @@ describe('EE approvals license-compliance actions', () => {
};
axiosMock.onPost(mocks.state.rulesPath).replyOnce(200);
return testAction(
await testAction(
actions.postRule,
rule,
state,
......@@ -101,11 +101,9 @@ describe('EE approvals license-compliance actions', () => {
type: 'fetchRules',
},
],
() => {
expect(axiosMock.history.post[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
},
);
expect(axiosMock.history.post[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
});
......@@ -122,7 +120,7 @@ describe('EE approvals license-compliance actions', () => {
const id = 4;
const putUrl = `${mocks.state.rulesPath}/${4}`;
it('puts correct data and dispatches "fetchRules" when request is successful', () => {
it('puts correct data and dispatches "fetchRules" when request is successful', async () => {
const payload = {
id,
name: 'Foo',
......@@ -132,7 +130,7 @@ describe('EE approvals license-compliance actions', () => {
};
axiosMock.onPut(putUrl).replyOnce(200);
return testAction(
await testAction(
actions.putRule,
payload,
state,
......@@ -142,11 +140,9 @@ describe('EE approvals license-compliance actions', () => {
type: 'fetchRules',
},
],
() => {
expect(axiosMock.history.put[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
},
);
expect(axiosMock.history.put[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
});
......
......@@ -4,21 +4,20 @@ import testAction from 'helpers/vuex_action_helper';
describe('Approval MR edit module actions', () => {
describe('setTargetBranch', () => {
it('commits SET_TARGET_BRANCH', (done) => {
testAction(
it('commits SET_TARGET_BRANCH', async () => {
await testAction(
actions.setTargetBranch,
'main',
{},
[{ type: types.SET_TARGET_BRANCH, payload: 'main' }],
[],
done,
);
});
});
describe('undoRulesChange', () => {
it('commits UNDO_RULES', (done) => {
testAction(actions.undoRulesChange, null, {}, [{ type: types.UNDO_RULES }], [], done);
it('commits UNDO_RULES', async () => {
await testAction(actions.undoRulesChange, null, {}, [{ type: types.UNDO_RULES }], []);
});
});
});
......@@ -239,10 +239,10 @@ describe('fetchEpicsSwimlanes', () => {
},
};
it('should commit mutation RECEIVE_EPICS_SUCCESS on success', (done) => {
it('should commit mutation RECEIVE_EPICS_SUCCESS on success', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{},
state,
......@@ -253,14 +253,13 @@ describe('fetchEpicsSwimlanes', () => {
},
],
[],
done,
);
});
it('should commit mutation REQUEST_MORE_EPICS when fetchNext is true', (done) => {
it('should commit mutation REQUEST_MORE_EPICS when fetchNext is true', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{ fetchNext: true },
state,
......@@ -272,14 +271,13 @@ describe('fetchEpicsSwimlanes', () => {
},
],
[],
done,
);
});
it('should commit mutation RECEIVE_EPICS_SUCCESS on success with hasMoreEpics when hasNextPage', (done) => {
it('should commit mutation RECEIVE_EPICS_SUCCESS on success with hasMoreEpics when hasNextPage', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponseWithNextPage);
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{},
state,
......@@ -294,20 +292,18 @@ describe('fetchEpicsSwimlanes', () => {
},
],
[],
done,
);
});
it('should commit mutation RECEIVE_SWIMLANES_FAILURE on failure', (done) => {
it('should commit mutation RECEIVE_SWIMLANES_FAILURE on failure', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{},
state,
[{ type: types.RECEIVE_SWIMLANES_FAILURE }],
[],
done,
);
});
});
......@@ -368,14 +364,14 @@ describe('fetchItemsForList', () => {
});
});
it('add epicWildcardId with NONE as value when noEpicIssues is true', () => {
it('add epicWildcardId with NONE as value when noEpicIssues is true', async () => {
state = {
...state,
isShowingEpicsSwimlanes: true,
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchItemsForList,
{ listId, noEpicIssues: true },
state,
......@@ -390,27 +386,25 @@ describe('fetchItemsForList', () => {
},
],
[],
() => {
expect(gqlClient.query).toHaveBeenCalledWith({
query: listsIssuesQuery,
variables: {
boardId: 'gid://gitlab/Board/1',
filters: {
epicWildcardId: 'NONE',
},
fullPath: 'gitlab-org',
id: 'gid://gitlab/List/1',
isGroup: true,
isProject: false,
after: undefined,
first: 10,
},
context: {
isSingleRequest: true,
},
});
},
);
expect(gqlClient.query).toHaveBeenCalledWith({
query: listsIssuesQuery,
variables: {
boardId: 'gid://gitlab/Board/1',
filters: {
epicWildcardId: 'NONE',
},
fullPath: 'gitlab-org',
id: 'gid://gitlab/List/1',
isGroup: true,
isProject: false,
after: undefined,
first: 10,
},
context: {
isSingleRequest: true,
},
});
});
});
......@@ -428,11 +422,11 @@ describe('updateBoardEpicUserPreferences', () => {
},
});
it('should send mutation', (done) => {
it('should send mutation', async () => {
const collapsed = true;
jest.spyOn(gqlClient, 'mutate').mockResolvedValue(queryResponse(collapsed));
testAction(
await testAction(
actions.updateBoardEpicUserPreferences,
{ epicId: mockEpic.id, collapsed },
state,
......@@ -448,24 +442,22 @@ describe('updateBoardEpicUserPreferences', () => {
},
],
[],
done,
);
});
});
describe('setShowLabels', () => {
it('should commit mutation SET_SHOW_LABELS', (done) => {
it('should commit mutation SET_SHOW_LABELS', async () => {
const state = {
isShowingLabels: true,
};
testAction(
await testAction(
actions.setShowLabels,
false,
state,
[{ type: types.SET_SHOW_LABELS, payload: false }],
[],
done,
);
});
});
......@@ -561,10 +553,10 @@ describe('fetchIssuesForEpic', () => {
const formattedIssues = formatListIssues(queryResponse.data.group.board.lists);
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_SUCCESS on success', (done) => {
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_SUCCESS on success', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchIssuesForEpic,
epicId,
state,
......@@ -573,14 +565,13 @@ describe('fetchIssuesForEpic', () => {
{ type: types.RECEIVE_ISSUES_FOR_EPIC_SUCCESS, payload: { ...formattedIssues, epicId } },
],
[],
done,
);
});
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_FAILURE on failure', (done) => {
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_FAILURE on failure', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
testAction(
await testAction(
actions.fetchIssuesForEpic,
epicId,
state,
......@@ -589,13 +580,12 @@ describe('fetchIssuesForEpic', () => {
{ type: types.RECEIVE_ISSUES_FOR_EPIC_FAILURE, payload: epicId },
],
[],
done,
);
});
});
describe('toggleEpicSwimlanes', () => {
it('should commit mutation TOGGLE_EPICS_SWIMLANES', () => {
it('should commit mutation TOGGLE_EPICS_SWIMLANES', async () => {
const startURl = `${TEST_HOST}/groups/gitlab-org/-/boards/1?group_by=epic`;
setWindowLocation(startURl);
......@@ -687,14 +677,14 @@ describe('setActiveItemWeight', () => {
const testWeight = mockIssue.weight + 1;
const input = { weight: testWeight, id: mockIssue.id };
it('should commit weight', (done) => {
it('should commit weight', async () => {
const payload = {
itemId: getters.activeBoardItem.id,
prop: 'weight',
value: testWeight,
};
testAction(
await testAction(
actions.setActiveItemWeight,
input,
{ ...state, ...getters },
......@@ -705,7 +695,6 @@ describe('setActiveItemWeight', () => {
},
],
[],
done,
);
});
......@@ -1280,10 +1269,10 @@ describe('fetchSubGroups', () => {
},
};
it('should commit mutations REQUEST_SUB_GROUPS, RECEIVE_SUB_GROUPS_SUCCESS, and SET_SELECTED_GROUP on success', (done) => {
it('should commit mutations REQUEST_SUB_GROUPS, RECEIVE_SUB_GROUPS_SUCCESS, and SET_SELECTED_GROUP on success', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchSubGroups,
{},
state,
......@@ -1302,14 +1291,13 @@ describe('fetchSubGroups', () => {
},
],
[],
done,
);
});
it('should commit mutations REQUEST_SUB_GROUPS and RECEIVE_SUB_GROUPS_FAILURE on failure', (done) => {
it('should commit mutations REQUEST_SUB_GROUPS and RECEIVE_SUB_GROUPS_FAILURE on failure', async () => {
jest.spyOn(gqlClient, 'query').mockRejectedValue();
testAction(
await testAction(
actions.fetchSubGroups,
{},
state,
......@@ -1323,14 +1311,13 @@ describe('fetchSubGroups', () => {
},
],
[],
done,
);
});
});
describe('setSelectedGroup', () => {
it('should commit mutation SET_SELECTED_GROUP', (done) => {
testAction(
it('should commit mutation SET_SELECTED_GROUP', async () => {
await testAction(
actions.setSelectedGroup,
mockGroup0,
{},
......@@ -1341,7 +1328,6 @@ describe('setSelectedGroup', () => {
},
],
[],
done,
);
});
});
......
......@@ -34,21 +34,14 @@ describe('Codequality report actions', () => {
});
describe('setPage', () => {
it('sets the page number', (done) => {
return testAction(
actions.setPage,
12,
state,
[{ type: types.SET_PAGE, payload: 12 }],
[],
done,
);
it('sets the page number', async () => {
await testAction(actions.setPage, 12, state, [{ type: types.SET_PAGE, payload: 12 }], []);
});
});
describe('requestReport', () => {
it('sets the loading flag', (done) => {
testAction(actions.requestReport, null, state, [{ type: types.REQUEST_REPORT }], [], done);
it('sets the loading flag', async () => {
await testAction(actions.requestReport, null, state, [{ type: types.REQUEST_REPORT }], []);
});
it('tracks a service ping event', () => {
......@@ -59,27 +52,25 @@ describe('Codequality report actions', () => {
});
describe('receiveReportSuccess', () => {
it('parses the list of issues from the report', (done) => {
return testAction(
it('parses the list of issues from the report', async () => {
await testAction(
actions.receiveReportSuccess,
unparsedIssues,
{ blobPath: '/root/test-codequality/blob/feature-branch', ...state },
[{ type: types.RECEIVE_REPORT_SUCCESS, payload: parsedIssues }],
[],
done,
);
});
});
describe('receiveReportError', () => {
it('accepts a report error', (done) => {
testAction(
it('accepts a report error', async () => {
await testAction(
actions.receiveReportError,
'error',
state,
[{ type: types.RECEIVE_REPORT_ERROR, payload: 'error' }],
[],
done,
);
});
});
......@@ -89,47 +80,40 @@ describe('Codequality report actions', () => {
mock.onGet(endpoint).replyOnce(200, unparsedIssues);
});
it('fetches the report', (done) => {
return testAction(
it('fetches the report', async () => {
await testAction(
actions.fetchReport,
null,
{ blobPath: 'blah', ...state },
[],
[{ type: 'requestReport' }, { type: 'receiveReportSuccess', payload: unparsedIssues }],
done,
);
});
it('shows a flash message when there is an error', (done) => {
testAction(
it('shows a flash message when there is an error', async () => {
await testAction(
actions.fetchReport,
'error',
state,
[],
[{ type: 'requestReport' }, { type: 'receiveReportError', payload: expect.any(Error) }],
() => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
done();
},
);
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
});
it('shows an error when blob path is missing', (done) => {
testAction(
it('shows an error when blob path is missing', async () => {
await testAction(
actions.fetchReport,
null,
state,
[],
[{ type: 'requestReport' }, { type: 'receiveReportError', payload: expect.any(Error) }],
() => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
done();
},
);
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
});
});
});
......@@ -17,16 +17,15 @@ jest.mock('~/flash');
describe('EE DiffsStoreActions', () => {
describe('setCodequalityEndpoint', () => {
it('should set given endpoint', (done) => {
it('should set given endpoint', async () => {
const endpoint = '/codequality_mr_diff.json';
testAction(
await testAction(
setCodequalityEndpoint,
{ endpoint },
{},
[{ type: types.SET_CODEQUALITY_ENDPOINT, payload: { endpoint } }],
[],
done,
);
});
});
......@@ -44,20 +43,19 @@ describe('EE DiffsStoreActions', () => {
clearCodequalityPoll();
});
it('should commit SET_CODEQUALITY_DATA with received response and stop polling', (done) => {
it('should commit SET_CODEQUALITY_DATA with received response and stop polling', async () => {
const data = {
files: { 'app.js': [{ line: 1, description: 'Unexpected alert.', severity: 'minor' }] },
};
mock.onGet(endpointCodequality).reply(200, { data });
testAction(
await testAction(
fetchCodequality,
{},
{ endpointCodequality },
[{ type: types.SET_CODEQUALITY_DATA, payload: { data } }],
[{ type: 'stopCodequalityPolling' }],
done,
);
});
......@@ -72,63 +70,57 @@ describe('EE DiffsStoreActions', () => {
mock.onGet(endpointCodequality).reply(400);
});
it('should not show a flash message', (done) => {
testAction(fetchCodequality, {}, { endpointCodequality }, [], [], () => {
expect(createFlash).not.toHaveBeenCalled();
done();
});
it('should not show a flash message', async () => {
await testAction(fetchCodequality, {}, { endpointCodequality }, [], []);
expect(createFlash).not.toHaveBeenCalled();
});
it('should retry five times with a delay, then stop polling', (done) => {
testAction(fetchCodequality, {}, { endpointCodequality }, [], [], () => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(RETRY_DELAY);
waitForPromises()
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(2);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(5);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => {
expect(pollStop).toHaveBeenCalledTimes(1);
})
.then(done)
.catch(done.fail);
});
it('should retry five times with a delay, then stop polling', async () => {
await testAction(fetchCodequality, {}, { endpointCodequality }, [], []);
expect(pollDelayedRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(RETRY_DELAY);
return waitForPromises()
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(2);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(5);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => {
expect(pollStop).toHaveBeenCalledTimes(1);
});
});
});
it('with unexpected error should stop polling and show a flash message', (done) => {
it('with unexpected error should stop polling and show a flash message', async () => {
mock.onGet(endpointCodequality).reply(500);
testAction(
await testAction(
fetchCodequality,
{},
{ endpointCodequality },
[],
[{ type: 'stopCodequalityPolling' }],
() => {
expect(createFlash).toHaveBeenCalledTimes(1);
expect(createFlash).toHaveBeenCalledWith({
message: 'An unexpected error occurred while loading the code quality diff.',
});
done();
},
);
expect(createFlash).toHaveBeenCalledTimes(1);
expect(createFlash).toHaveBeenCalledWith({
message: 'An unexpected error occurred while loading the code quality diff.',
});
});
});
});
......@@ -22,27 +22,25 @@ describe('Epic Store Actions', () => {
});
describe('setEpicMeta', () => {
it('should set received Epic meta', (done) => {
testAction(
it('should set received Epic meta', async () => {
await testAction(
actions.setEpicMeta,
mockEpicMeta,
{},
[{ type: 'SET_EPIC_META', payload: mockEpicMeta }],
[],
done,
);
});
});
describe('setEpicData', () => {
it('should set received Epic data', (done) => {
testAction(
it('should set received Epic data', async () => {
await testAction(
actions.setEpicData,
mockEpicData,
{},
[{ type: 'SET_EPIC_DATA', payload: mockEpicData }],
[],
done,
);
});
});
......@@ -101,7 +99,7 @@ describe('Epic Store Actions', () => {
mock.restore();
});
it('dispatches setEpicData when request is successful', (done) => {
it('dispatches setEpicData when request is successful', async () => {
mock.onPut(/(.*)/).replyOnce(200, {});
jest.spyOn(epicUtils.gqClient, 'query').mockReturnValue(
Promise.resolve({
......@@ -109,7 +107,7 @@ describe('Epic Store Actions', () => {
}),
);
testAction(
await testAction(
actions.fetchEpicDetails,
payload,
state,
......@@ -120,15 +118,14 @@ describe('Epic Store Actions', () => {
payload: { participants: formattedParticipants },
},
],
done,
);
});
it('dispatches requestEpicParticipantsFailure when request fails', (done) => {
it('dispatches requestEpicParticipantsFailure when request fails', async () => {
mock.onPut(/(.*)/).replyOnce(500, {});
jest.spyOn(epicUtils.gqClient, 'query').mockReturnValue(Promise.resolve({}));
testAction(
await testAction(
actions.fetchEpicDetails,
payload,
state,
......@@ -138,14 +135,13 @@ describe('Epic Store Actions', () => {
type: 'requestEpicParticipantsFailure',
},
],
done,
);
});
});
describe('requestEpicParticipantsFailure', () => {
it('does not invoke any mutations or actions', (done) => {
testAction(actions.requestEpicParticipantsFailure, {}, state, [], [], done);
it('does not invoke any mutations or actions', async () => {
await testAction(actions.requestEpicParticipantsFailure, {}, state, [], []);
});
it('shows flash error', () => {
......@@ -158,40 +154,37 @@ describe('Epic Store Actions', () => {
});
describe('requestEpicStatusChange', () => {
it('should set status change flag', (done) => {
testAction(
it('should set status change flag', async () => {
await testAction(
actions.requestEpicStatusChange,
{},
state,
[{ type: 'REQUEST_EPIC_STATUS_CHANGE' }],
[],
done,
);
});
});
describe('requestEpicStatusChangeSuccess', () => {
it('should set epic state type', (done) => {
testAction(
it('should set epic state type', async () => {
await testAction(
actions.requestEpicStatusChangeSuccess,
{ state: statusType.close },
state,
[{ type: 'REQUEST_EPIC_STATUS_CHANGE_SUCCESS', payload: { state: statusType.close } }],
[],
done,
);
});
});
describe('requestEpicStatusChangeFailure', () => {
it('should set status change flag', (done) => {
testAction(
it('should set status change flag', async () => {
await testAction(
actions.requestEpicStatusChangeFailure,
{},
state,
[{ type: 'REQUEST_EPIC_STATUS_CHANGE_FAILURE' }],
[],
done,
);
});
......@@ -235,12 +228,12 @@ describe('Epic Store Actions', () => {
});
describe('success', () => {
it('dispatches requestEpicStatusChange and requestEpicStatusChangeSuccess when request is complete', (done) => {
it('dispatches requestEpicStatusChange and requestEpicStatusChangeSuccess when request is complete', async () => {
mock.onPut(/(.*)/).replyOnce(200, {
state: statusType.close,
});
testAction(
await testAction(
actions.toggleEpicStatus,
null,
state,
......@@ -258,16 +251,15 @@ describe('Epic Store Actions', () => {
payload: { isEpicOpen: true },
},
],
done,
);
});
});
describe('failure', () => {
it('dispatches requestEpicStatusChange and requestEpicStatusChangeFailure when request fails', (done) => {
it('dispatches requestEpicStatusChange and requestEpicStatusChangeFailure when request fails', async () => {
mock.onPut(/(.*)/).replyOnce(500, {});
testAction(
await testAction(
actions.toggleEpicStatus,
null,
state,
......@@ -284,23 +276,21 @@ describe('Epic Store Actions', () => {
payload: { isEpicOpen: true },
},
],
done,
);
});
});
});
describe('toggleSidebarFlag', () => {
it('should call `TOGGLE_SIDEBAR` mutation with param `sidebarCollapsed`', (done) => {
it('should call `TOGGLE_SIDEBAR` mutation with param `sidebarCollapsed`', async () => {
const sidebarCollapsed = true;
testAction(
await testAction(
actions.toggleSidebarFlag,
sidebarCollapsed,
state,
[{ type: 'TOGGLE_SIDEBAR', payload: sidebarCollapsed }],
[],
done,
);
});
});
......@@ -329,10 +319,10 @@ describe('Epic Store Actions', () => {
});
describe('toggleSidebar', () => {
it('dispatches toggleContainerClassAndCookie and toggleSidebarFlag actions with opposite value of `isSidebarCollapsed` param', (done) => {
it('dispatches toggleContainerClassAndCookie and toggleSidebarFlag actions with opposite value of `isSidebarCollapsed` param', async () => {
const sidebarCollapsed = true;
testAction(
await testAction(
actions.toggleSidebar,
{ sidebarCollapsed },
state,
......@@ -347,46 +337,42 @@ describe('Epic Store Actions', () => {
payload: !sidebarCollapsed,
},
],
done,
);
});
});
describe('requestEpicTodoToggle', () => {
it('should set `state.epicTodoToggleInProgress` flag to `true`', (done) => {
testAction(
it('should set `state.epicTodoToggleInProgress` flag to `true`', async () => {
await testAction(
actions.requestEpicTodoToggle,
{},
state,
[{ type: 'REQUEST_EPIC_TODO_TOGGLE' }],
[],
done,
);
});
});
describe('requestEpicTodoToggleSuccess', () => {
it('should set epic state type', (done) => {
testAction(
it('should set epic state type', async () => {
await testAction(
actions.requestEpicTodoToggleSuccess,
{ todoDeletePath: '/foo/bar' },
state,
[{ type: 'REQUEST_EPIC_TODO_TOGGLE_SUCCESS', payload: { todoDeletePath: '/foo/bar' } }],
[],
done,
);
});
});
describe('requestEpicTodoToggleFailure', () => {
it('Should set `state.epicTodoToggleInProgress` flag to `false`', (done) => {
testAction(
it('Should set `state.epicTodoToggleInProgress` flag to `false`', async () => {
await testAction(
actions.requestEpicTodoToggleFailure,
{},
state,
[{ type: 'REQUEST_EPIC_TODO_TOGGLE_FAILURE', payload: {} }],
[],
done,
);
});
......@@ -440,13 +426,13 @@ describe('Epic Store Actions', () => {
});
describe('when `state.togoExists` is false', () => {
it('dispatches requestEpicTodoToggle, triggerTodoToggleEvent and requestEpicTodoToggleSuccess when request is successful', (done) => {
it('dispatches requestEpicTodoToggle, triggerTodoToggleEvent and requestEpicTodoToggleSuccess when request is successful', async () => {
mock.onPost(/(.*)/).replyOnce(200, {
count: 5,
delete_path: '/foo/bar',
});
testAction(
await testAction(
actions.toggleTodo,
null,
{ todoExists: false },
......@@ -464,14 +450,13 @@ describe('Epic Store Actions', () => {
payload: { todoDeletePath: '/foo/bar' },
},
],
done,
);
});
it('dispatches requestEpicTodoToggle and requestEpicTodoToggleFailure when request fails', (done) => {
it('dispatches requestEpicTodoToggle and requestEpicTodoToggleFailure when request fails', async () => {
mock.onPost(/(.*)/).replyOnce(500, {});
testAction(
await testAction(
actions.toggleTodo,
null,
{ todoExists: false },
......@@ -484,18 +469,17 @@ describe('Epic Store Actions', () => {
type: 'requestEpicTodoToggleFailure',
},
],
done,
);
});
});
describe('when `state.togoExists` is true', () => {
it('dispatches requestEpicTodoToggle, triggerTodoToggleEvent and requestEpicTodoToggleSuccess when request is successful', (done) => {
it('dispatches requestEpicTodoToggle, triggerTodoToggleEvent and requestEpicTodoToggleSuccess when request is successful', async () => {
mock.onDelete(/(.*)/).replyOnce(200, {
count: 5,
});
testAction(
await testAction(
actions.toggleTodo,
null,
{ todoExists: true },
......@@ -513,14 +497,13 @@ describe('Epic Store Actions', () => {
payload: { todoDeletePath: undefined },
},
],
done,
);
});
it('dispatches requestEpicTodoToggle and requestEpicTodoToggleFailure when request fails', (done) => {
it('dispatches requestEpicTodoToggle and requestEpicTodoToggleFailure when request fails', async () => {
mock.onDelete(/(.*)/).replyOnce(500, {});
testAction(
await testAction(
actions.toggleTodo,
null,
{ todoExists: true },
......@@ -533,114 +516,107 @@ describe('Epic Store Actions', () => {
type: 'requestEpicTodoToggleFailure',
},
],
done,
);
});
});
});
describe('toggleStartDateType', () => {
it('should set `state.startDateIsFixed` flag to `true`', (done) => {
it('should set `state.startDateIsFixed` flag to `true`', async () => {
const dateTypeIsFixed = true;
testAction(
await testAction(
actions.toggleStartDateType,
{ dateTypeIsFixed },
state,
[{ type: 'TOGGLE_EPIC_START_DATE_TYPE', payload: { dateTypeIsFixed } }],
[],
done,
);
});
});
describe('toggleDueDateType', () => {
it('should set `state.dueDateIsFixed` flag to `true`', (done) => {
it('should set `state.dueDateIsFixed` flag to `true`', async () => {
const dateTypeIsFixed = true;
testAction(
await testAction(
actions.toggleDueDateType,
{ dateTypeIsFixed },
state,
[{ type: 'TOGGLE_EPIC_DUE_DATE_TYPE', payload: { dateTypeIsFixed } }],
[],
done,
);
});
});
describe('requestEpicDateSave', () => {
it('should set `state.epicStartDateSaveInProgress` flag to `true` when called with `dateType` as `start`', (done) => {
it('should set `state.epicStartDateSaveInProgress` flag to `true` when called with `dateType` as `start`', async () => {
const dateType = dateTypes.start;
testAction(
await testAction(
actions.requestEpicDateSave,
{ dateType },
state,
[{ type: 'REQUEST_EPIC_DATE_SAVE', payload: { dateType } }],
[],
done,
);
});
it('should set `state.epicDueDateSaveInProgress` flag to `true` when called with `dateType` as `due`', (done) => {
it('should set `state.epicDueDateSaveInProgress` flag to `true` when called with `dateType` as `due`', async () => {
const dateType = dateTypes.due;
testAction(
await testAction(
actions.requestEpicDateSave,
{ dateType },
state,
[{ type: 'REQUEST_EPIC_DATE_SAVE', payload: { dateType } }],
[],
done,
);
});
});
describe('requestEpicDateSaveSuccess', () => {
it('should set `state.epicStartDateSaveInProgress` flag to `false` and set values of `startDateIsFixed` & `startDate` with params `dateTypeIsFixed` & `newDate` when called with `dateType` as `start`', (done) => {
it('should set `state.epicStartDateSaveInProgress` flag to `false` and set values of `startDateIsFixed` & `startDate` with params `dateTypeIsFixed` & `newDate` when called with `dateType` as `start`', async () => {
const data = {
dateType: dateTypes.start,
dateTypeIsFixed: true,
mewDate: '2018-1-1',
};
testAction(
await testAction(
actions.requestEpicDateSaveSuccess,
data,
state,
[{ type: 'REQUEST_EPIC_DATE_SAVE_SUCCESS', payload: { ...data } }],
[],
done,
);
});
it('should set `state.epicDueDateSaveInProgress` flag to `false` and set values of `dueDateIsFixed` & `dueDate` with params `dateTypeIsFixed` & `newDate` when called with `dateType` as `due`', (done) => {
it('should set `state.epicDueDateSaveInProgress` flag to `false` and set values of `dueDateIsFixed` & `dueDate` with params `dateTypeIsFixed` & `newDate` when called with `dateType` as `due`', async () => {
const data = {
dateType: dateTypes.due,
dateTypeIsFixed: true,
mewDate: '2018-1-1',
};
testAction(
await testAction(
actions.requestEpicDateSaveSuccess,
data,
state,
[{ type: 'REQUEST_EPIC_DATE_SAVE_SUCCESS', payload: { ...data } }],
[],
done,
);
});
});
describe('requestEpicDateSaveFailure', () => {
it('should set `state.epicStartDateSaveInProgress` flag to `false` and set value of `startDateIsFixed` to that of param `dateTypeIsFixed` when called with `dateType` as `start`', (done) => {
it('should set `state.epicStartDateSaveInProgress` flag to `false` and set value of `startDateIsFixed` to that of param `dateTypeIsFixed` when called with `dateType` as `start`', async () => {
const data = {
dateType: dateTypes.start,
dateTypeIsFixed: true,
};
testAction(
await testAction(
actions.requestEpicDateSaveFailure,
data,
state,
......@@ -651,17 +627,16 @@ describe('Epic Store Actions', () => {
},
],
[],
done,
);
});
it('should set `state.epicDueDateSaveInProgress` flag to `false` and set value of `dueDateIsFixed` to that of param `dateTypeIsFixed` when called with `dateType` as `due`', (done) => {
it('should set `state.epicDueDateSaveInProgress` flag to `false` and set value of `dueDateIsFixed` to that of param `dateTypeIsFixed` when called with `dateType` as `due`', async () => {
const data = {
dateType: dateTypes.due,
dateTypeIsFixed: true,
};
testAction(
await testAction(
actions.requestEpicDateSaveFailure,
data,
state,
......@@ -672,7 +647,6 @@ describe('Epic Store Actions', () => {
},
],
[],
done,
);
});
......@@ -727,7 +701,7 @@ describe('Epic Store Actions', () => {
mock.restore();
});
it('dispatches requestEpicDateSave and requestEpicDateSaveSuccess when request is successful', (done) => {
it('dispatches requestEpicDateSave and requestEpicDateSaveSuccess when request is successful', async () => {
mock.onPut(/(.*)/).replyOnce(200, {});
jest.spyOn(epicUtils.gqClient, 'mutate').mockReturnValue(
Promise.resolve({
......@@ -735,7 +709,7 @@ describe('Epic Store Actions', () => {
}),
);
testAction(
await testAction(
actions.saveDate,
{ ...data },
state,
......@@ -750,11 +724,10 @@ describe('Epic Store Actions', () => {
payload: { ...data },
},
],
done,
);
});
it('dispatches requestEpicDateSave and requestEpicDateSaveFailure when request fails', (done) => {
it('dispatches requestEpicDateSave and requestEpicDateSaveFailure when request fails', async () => {
mock.onPut(/(.*)/).replyOnce(500, {});
jest.spyOn(epicUtils.gqClient, 'mutate').mockReturnValue(
Promise.resolve({
......@@ -767,7 +740,7 @@ describe('Epic Store Actions', () => {
}),
);
testAction(
await testAction(
actions.saveDate,
{ ...data },
state,
......@@ -782,32 +755,30 @@ describe('Epic Store Actions', () => {
payload: { dateType: data.dateType, dateTypeIsFixed: !data.dateTypeIsFixed },
},
],
done,
);
});
});
describe('requestEpicLabelsSelect', () => {
it('should set `state.epicLabelsSelectInProgress` flag to `true`', (done) => {
testAction(
it('should set `state.epicLabelsSelectInProgress` flag to `true`', async () => {
await testAction(
actions.requestEpicLabelsSelect,
{},
state,
[{ type: 'REQUEST_EPIC_LABELS_SELECT' }],
[],
done,
);
});
});
describe('receiveEpicLabelsSelectSuccess', () => {
it('should set provided labels param to `state.labels`', (done) => {
it('should set provided labels param to `state.labels`', async () => {
const labels = [
{ id: 1, set: false },
{ id: 2, set: true },
];
testAction(
await testAction(
actions.receiveEpicLabelsSelectSuccess,
labels,
state,
......@@ -818,20 +789,18 @@ describe('Epic Store Actions', () => {
},
],
[],
done,
);
});
});
describe('receiveEpicLabelsSelectFailure', () => {
it('should set `state.epicLabelsSelectInProgress` flag to `false`', (done) => {
testAction(
it('should set `state.epicLabelsSelectInProgress` flag to `false`', async () => {
await testAction(
actions.receiveEpicLabelsSelectFailure,
{},
state,
[{ type: 'RECEIVE_EPIC_LABELS_SELECT_FAILURE' }],
[],
done,
);
});
......@@ -855,7 +824,7 @@ describe('Epic Store Actions', () => {
{ id: 2, set: true },
];
it('dispatches `requestEpicLabelsSelect` and `receiveEpicLabelsSelectSuccess` actions when request succeeds', (done) => {
it('dispatches `requestEpicLabelsSelect` and `receiveEpicLabelsSelectSuccess` actions when request succeeds', async () => {
jest.spyOn(epicUtils.gqClient, 'mutate').mockReturnValue(
Promise.resolve({
data: {
......@@ -866,7 +835,7 @@ describe('Epic Store Actions', () => {
}),
);
testAction(
await testAction(
actions.updateEpicLabels,
labels,
state,
......@@ -880,11 +849,10 @@ describe('Epic Store Actions', () => {
payload: labels,
},
],
done,
);
});
it('dispatches `requestEpicLabelsSelect` and `receiveEpicLabelsSelectFailure` actions when request fails', (done) => {
it('dispatches `requestEpicLabelsSelect` and `receiveEpicLabelsSelectFailure` actions when request fails', async () => {
jest.spyOn(epicUtils.gqClient, 'mutate').mockReturnValue(
Promise.resolve({
data: {
......@@ -895,7 +863,7 @@ describe('Epic Store Actions', () => {
}),
);
testAction(
await testAction(
actions.updateEpicLabels,
labels,
state,
......@@ -908,31 +876,29 @@ describe('Epic Store Actions', () => {
type: 'receiveEpicLabelsSelectFailure',
},
],
done,
);
});
});
describe('requestEpicSubscriptionToggle', () => {
it('should set `state.epicSubscriptionToggleInProgress` flag to `true`', (done) => {
testAction(
it('should set `state.epicSubscriptionToggleInProgress` flag to `true`', async () => {
await testAction(
actions.requestEpicSubscriptionToggle,
{},
state,
[{ type: 'REQUEST_EPIC_SUBSCRIPTION_TOGGLE' }],
[],
done,
);
});
});
describe('requestEpicSubscriptionToggleSuccess', () => {
it('should set `state.requestEpicSubscriptionToggleSuccess` flag to `false` and passes opposite of the value of `subscribed` as param', (done) => {
it('should set `state.requestEpicSubscriptionToggleSuccess` flag to `false` and passes opposite of the value of `subscribed` as param', async () => {
const stateSubscribed = {
subscribed: false,
};
testAction(
await testAction(
actions.requestEpicSubscriptionToggleSuccess,
{ subscribed: !stateSubscribed.subscribed },
stateSubscribed,
......@@ -943,20 +909,18 @@ describe('Epic Store Actions', () => {
},
],
[],
done,
);
});
});
describe('requestEpicSubscriptionToggleFailure', () => {
it('should set `state.requestEpicSubscriptionToggleFailure` flag to `false`', (done) => {
testAction(
it('should set `state.requestEpicSubscriptionToggleFailure` flag to `false`', async () => {
await testAction(
actions.requestEpicSubscriptionToggleFailure,
{},
state,
[{ type: 'REQUEST_EPIC_SUBSCRIPTION_TOGGLE_FAILURE' }],
[],
done,
);
});
......@@ -1015,7 +979,7 @@ describe('Epic Store Actions', () => {
});
describe('success', () => {
it('dispatches requestEpicSubscriptionToggle and requestEpicSubscriptionToggleSuccess with param `subscribed` when request is complete', (done) => {
it('dispatches requestEpicSubscriptionToggle and requestEpicSubscriptionToggleSuccess with param `subscribed` when request is complete', async () => {
mock.onPost(/(.*)/).replyOnce(200, {});
jest.spyOn(epicUtils.gqClient, 'mutate').mockReturnValue(
Promise.resolve({
......@@ -1023,7 +987,7 @@ describe('Epic Store Actions', () => {
}),
);
testAction(
await testAction(
actions.toggleEpicSubscription,
{ subscribed: !state.subscribed },
state,
......@@ -1037,27 +1001,23 @@ describe('Epic Store Actions', () => {
payload: { subscribed: !state.subscribed },
},
],
() => {
expect(epicUtils.gqClient.mutate).toHaveBeenCalledWith(
expect.objectContaining({
variables: expect.objectContaining({
epicSetSubscriptionInput: {
iid: `${state.epicIid}`,
groupPath: state.fullPath,
subscribedState: !state.subscribed,
},
}),
}),
);
done();
},
);
expect(epicUtils.gqClient.mutate).toHaveBeenCalledWith(
expect.objectContaining({
variables: expect.objectContaining({
epicSetSubscriptionInput: {
iid: `${state.epicIid}`,
groupPath: state.fullPath,
subscribedState: !state.subscribed,
},
}),
}),
);
});
});
describe('failure', () => {
it('dispatches requestEpicSubscriptionToggle and requestEpicSubscriptionToggleFailure when request fails', (done) => {
it('dispatches requestEpicSubscriptionToggle and requestEpicSubscriptionToggleFailure when request fails', async () => {
mock.onPost(/(.*)/).replyOnce(500, {});
jest.spyOn(epicUtils.gqClient, 'mutate').mockReturnValue(
Promise.resolve({
......@@ -1070,7 +1030,7 @@ describe('Epic Store Actions', () => {
}),
);
testAction(
await testAction(
actions.toggleEpicSubscription,
{ subscribed: !state.subscribed },
state,
......@@ -1083,68 +1043,63 @@ describe('Epic Store Actions', () => {
type: 'requestEpicSubscriptionToggleFailure',
},
],
done,
);
});
});
});
describe('setEpicCreateTitle', () => {
it('should set `state.newEpicTitle` value to the value of `newEpicTitle` param', (done) => {
it('should set `state.newEpicTitle` value to the value of `newEpicTitle` param', async () => {
const data = {
newEpicTitle: 'foobar',
};
testAction(
await testAction(
actions.setEpicCreateTitle,
data,
{ newEpicTitle: '' },
[{ type: 'SET_EPIC_CREATE_TITLE', payload: { ...data } }],
[],
done,
);
});
});
describe('setEpicCreateConfidential', () => {
it('should set `state.newEpicConfidential` value to the value of `newEpicConfidential` param', (done) => {
it('should set `state.newEpicConfidential` value to the value of `newEpicConfidential` param', async () => {
const data = {
newEpicConfidential: true,
};
testAction(
await testAction(
actions.setEpicCreateConfidential,
data,
{ newEpicConfidential: true },
[{ type: 'SET_EPIC_CREATE_CONFIDENTIAL', payload: { ...data } }],
[],
done,
);
});
});
describe('requestEpicCreate', () => {
it('should set `state.epicCreateInProgress` flag to `true`', (done) => {
testAction(
it('should set `state.epicCreateInProgress` flag to `true`', async () => {
await testAction(
actions.requestEpicCreate,
{},
{ epicCreateInProgress: false },
[{ type: 'REQUEST_EPIC_CREATE' }],
[],
done,
);
});
});
describe('requestEpicCreateFailure', () => {
it('should set `state.epicCreateInProgress` flag to `false`', (done) => {
testAction(
it('should set `state.epicCreateInProgress` flag to `false`', async () => {
await testAction(
actions.requestEpicCreateFailure,
{},
{ epicCreateInProgress: true },
[{ type: 'REQUEST_EPIC_CREATE_FAILURE' }],
[],
done,
);
});
......@@ -1173,10 +1128,10 @@ describe('Epic Store Actions', () => {
});
describe('success', () => {
it('dispatches requestEpicCreate when request is complete', (done) => {
it('dispatches requestEpicCreate when request is complete', async () => {
mock.onPost(/(.*)/).replyOnce(200, {});
testAction(
await testAction(
actions.createEpic,
{ ...stateCreateEpic },
stateCreateEpic,
......@@ -1189,16 +1144,15 @@ describe('Epic Store Actions', () => {
type: 'requestEpicCreateSuccess',
},
],
done,
);
});
});
describe('failure', () => {
it('dispatches requestEpicCreate and requestEpicCreateFailure when request fails', (done) => {
it('dispatches requestEpicCreate and requestEpicCreateFailure when request fails', async () => {
mock.onPost(/(.*)/).replyOnce(500, {});
testAction(
await testAction(
actions.createEpic,
{ ...stateCreateEpic },
stateCreateEpic,
......@@ -1211,22 +1165,20 @@ describe('Epic Store Actions', () => {
type: 'requestEpicCreateFailure',
},
],
done,
);
});
});
});
describe('updateConfidentialityOnIssuable', () => {
it('should commit `SET_EPIC_CONFIDENTIAL` mutation with param `sidebarCollapsed', (done) => {
it('should commit `SET_EPIC_CONFIDENTIAL` mutation with param `sidebarCollapsed', async () => {
const confidential = true;
testAction(
await testAction(
actions.updateConfidentialityOnIssuable,
confidential,
state,
[{ payload: true, type: 'SET_EPIC_CONFIDENTIAL' }],
[],
done,
);
});
});
......
......@@ -41,21 +41,20 @@ describe('GeoReplicable Store Actions', () => {
});
describe('requestReplicableItems', () => {
it('should commit mutation REQUEST_REPLICABLE_ITEMS', (done) => {
testAction(
it('should commit mutation REQUEST_REPLICABLE_ITEMS', async () => {
await testAction(
actions.requestReplicableItems,
null,
state,
[{ type: types.REQUEST_REPLICABLE_ITEMS }],
[],
done,
);
});
});
describe('receiveReplicableItemsSuccess', () => {
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_SUCCESS', (done) => {
testAction(
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_SUCCESS', async () => {
await testAction(
actions.receiveReplicableItemsSuccess,
{ data: MOCK_BASIC_FETCH_DATA_MAP, pagination: MOCK_RESTFUL_PAGINATION_DATA },
state,
......@@ -66,14 +65,13 @@ describe('GeoReplicable Store Actions', () => {
},
],
[],
done,
);
});
});
describe('receiveReplicableItemsError', () => {
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_ERROR', () => {
testAction(
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_ERROR', async () => {
await testAction(
actions.receiveReplicableItemsError,
null,
state,
......@@ -92,8 +90,8 @@ describe('GeoReplicable Store Actions', () => {
state.useGraphQl = true;
});
it('calls fetchReplicableItemsGraphQl', (done) => {
testAction(
it('calls fetchReplicableItemsGraphQl', async () => {
await testAction(
actions.fetchReplicableItems,
null,
state,
......@@ -102,7 +100,6 @@ describe('GeoReplicable Store Actions', () => {
{ type: 'requestReplicableItems' },
{ type: 'fetchReplicableItemsGraphQl', payload: null },
],
done,
);
});
});
......@@ -112,14 +109,13 @@ describe('GeoReplicable Store Actions', () => {
state.useGraphQl = false;
});
it('calls fetchReplicableItemsRestful', (done) => {
testAction(
it('calls fetchReplicableItemsRestful', async () => {
await testAction(
actions.fetchReplicableItems,
null,
state,
[],
[{ type: 'requestReplicableItems' }, { type: 'fetchReplicableItemsRestful' }],
done,
);
});
});
......@@ -278,14 +274,13 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(mockGeoGqClient, 'query').mockRejectedValue();
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.fetchReplicableItemsGraphQl,
null,
state,
[],
[{ type: 'receiveReplicableItemsError' }],
done,
);
});
});
......@@ -366,35 +361,33 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(Api, 'getGeoReplicableItems').mockRejectedValue(new Error(500));
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.fetchReplicableItemsRestful,
{},
state,
[],
[{ type: 'receiveReplicableItemsError' }],
done,
);
});
});
});
describe('requestInitiateAllReplicableSyncs', () => {
it('should commit mutation REQUEST_INITIATE_ALL_REPLICABLE_SYNCS', (done) => {
testAction(
it('should commit mutation REQUEST_INITIATE_ALL_REPLICABLE_SYNCS', async () => {
await testAction(
actions.requestInitiateAllReplicableSyncs,
null,
state,
[{ type: types.REQUEST_INITIATE_ALL_REPLICABLE_SYNCS }],
[],
done,
);
});
});
describe('receiveInitiateAllReplicableSyncsSuccess', () => {
it('should commit mutation RECEIVE_INITIATE_ALL_REPLICABLE_SYNCS_SUCCESS and call fetchReplicableItems and toast', () => {
testAction(
it('should commit mutation RECEIVE_INITIATE_ALL_REPLICABLE_SYNCS_SUCCESS and call fetchReplicableItems and toast', async () => {
await testAction(
actions.receiveInitiateAllReplicableSyncsSuccess,
{ action: ACTION_TYPES.RESYNC },
state,
......@@ -460,8 +453,8 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(Api, 'initiateAllGeoReplicableSyncs').mockRejectedValue(new Error(500));
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.initiateAllReplicableSyncs,
action,
state,
......@@ -470,53 +463,47 @@ describe('GeoReplicable Store Actions', () => {
{ type: 'requestInitiateAllReplicableSyncs' },
{ type: 'receiveInitiateAllReplicableSyncsError' },
],
done,
);
});
});
});
describe('requestInitiateReplicableSync', () => {
it('should commit mutation REQUEST_INITIATE_REPLICABLE_SYNC', (done) => {
testAction(
it('should commit mutation REQUEST_INITIATE_REPLICABLE_SYNC', async () => {
await testAction(
actions.requestInitiateReplicableSync,
null,
state,
[{ type: types.REQUEST_INITIATE_REPLICABLE_SYNC }],
[],
done,
);
});
});
describe('receiveInitiateReplicableSyncSuccess', () => {
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_SUCCESS and call fetchReplicableItems and toast', () => {
testAction(
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_SUCCESS and call fetchReplicableItems and toast', async () => {
await testAction(
actions.receiveInitiateReplicableSyncSuccess,
{ action: ACTION_TYPES.RESYNC, projectName: 'test' },
state,
[{ type: types.RECEIVE_INITIATE_REPLICABLE_SYNC_SUCCESS }],
[{ type: 'fetchReplicableItems' }],
() => {
expect(toast).toHaveBeenCalledTimes(1);
toast.mockClear();
},
);
expect(toast).toHaveBeenCalledTimes(1);
toast.mockClear();
});
});
describe('receiveInitiateReplicableSyncError', () => {
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_ERROR', () => {
testAction(
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_ERROR', async () => {
await testAction(
actions.receiveInitiateReplicableSyncError,
{ action: ACTION_TYPES.RESYNC, projectId: 1, projectName: 'test' },
state,
[{ type: types.RECEIVE_INITIATE_REPLICABLE_SYNC_ERROR }],
[],
() => {
expect(createFlash).toHaveBeenCalledTimes(1);
},
);
expect(createFlash).toHaveBeenCalledTimes(1);
});
});
......@@ -543,13 +530,11 @@ describe('GeoReplicable Store Actions', () => {
{ type: 'requestInitiateReplicableSync' },
{ type: 'receiveInitiateReplicableSyncSuccess', payload: { name, action } },
],
() => {
expect(Api.initiateGeoReplicableSync).toHaveBeenCalledWith(MOCK_REPLICABLE_TYPE, {
projectId,
action,
});
},
);
expect(Api.initiateGeoReplicableSync).toHaveBeenCalledWith(MOCK_REPLICABLE_TYPE, {
projectId,
action,
});
});
});
......@@ -561,8 +546,8 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(Api, 'initiateGeoReplicableSync').mockRejectedValue(new Error(500));
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.initiateReplicableSync,
{ projectId, name, action },
state,
......@@ -574,55 +559,51 @@ describe('GeoReplicable Store Actions', () => {
payload: { name: 'test' },
},
],
done,
);
});
});
});
describe('setFilter', () => {
it('should commit mutation SET_FILTER', (done) => {
it('should commit mutation SET_FILTER', async () => {
const testValue = 1;
testAction(
await testAction(
actions.setFilter,
testValue,
state,
[{ type: types.SET_FILTER, payload: testValue }],
[],
done,
);
});
});
describe('setSearch', () => {
it('should commit mutation SET_SEARCH', (done) => {
it('should commit mutation SET_SEARCH', async () => {
const testValue = 'Test Search';
testAction(
await testAction(
actions.setSearch,
testValue,
state,
[{ type: types.SET_SEARCH, payload: testValue }],
[],
done,
);
});
});
describe('setPage', () => {
it('should commit mutation SET_PAGE', (done) => {
it('should commit mutation SET_PAGE', async () => {
state.paginationData.page = 1;
const testValue = 2;
testAction(
await testAction(
actions.setPage,
testValue,
state,
[{ type: types.SET_PAGE, payload: testValue }],
[],
done,
);
});
});
......
......@@ -70,41 +70,29 @@ describe('GroupMemberStore', () => {
mock.restore();
});
it('calls service.getContributedMembers and sets response to the store on success', (done) => {
it('calls service.getContributedMembers and sets response to the store on success', async () => {
mock.onGet(contributionsPath).reply(200, rawMembers);
jest.spyOn(store, 'setColumns').mockImplementation(() => {});
jest.spyOn(store, 'setMembers').mockImplementation(() => {});
store
.fetchContributedMembers()
.then(() => {
expect(store.isLoading).toBe(false);
expect(store.setColumns).toHaveBeenCalledWith(expect.any(Object));
expect(store.setMembers).toHaveBeenCalledWith(rawMembers);
done();
})
.catch(done.fail);
expect(store.isLoading).toBe(true);
await store.fetchContributedMembers();
expect(store.isLoading).toBe(false);
expect(store.setColumns).toHaveBeenCalledWith(expect.any(Object));
expect(store.setMembers).toHaveBeenCalledWith(rawMembers);
});
it('calls service.getContributedMembers and sets `isLoading` to false and shows flash message if request failed', (done) => {
it('calls service.getContributedMembers and sets `isLoading` to false and shows flash message if request failed', async () => {
mock.onGet(contributionsPath).reply(500, {});
store
.fetchContributedMembers()
.then(() => done.fail('Expected error to be thrown!'))
.catch((e) => {
expect(e.message).toBe('Request failed with status code 500');
expect(store.isLoading).toBe(false);
expect(createFlash).toHaveBeenCalledWith({
message: 'Something went wrong while fetching group member contributions',
});
})
.then(done)
.catch(done.fail);
expect(store.isLoading).toBe(true);
await expect(store.fetchContributedMembers()).rejects.toEqual(
new Error('Request failed with status code 500'),
);
expect(store.isLoading).toBe(false);
expect(createFlash).toHaveBeenCalledWith({
message: 'Something went wrong while fetching group member contributions',
});
});
});
});
......@@ -23,7 +23,7 @@ describe('saml_members actions', () => {
});
describe('fetchPage', () => {
it('should commit RECEIVE_SAML_MEMBERS_SUCCESS mutation on correct data', (done) => {
it('should commit RECEIVE_SAML_MEMBERS_SUCCESS mutation on correct data', async () => {
const members = [
{ id: 1, name: 'user 1', group_saml_identity: null },
{ id: 2, name: 'user 2', group_saml_identity: { extern_uid: 'a' } },
......@@ -57,7 +57,7 @@ describe('saml_members actions', () => {
previousPage: 1,
};
testAction(
await testAction(
fetchPage,
undefined,
state,
......@@ -68,16 +68,14 @@ describe('saml_members actions', () => {
},
],
[],
done,
);
});
it('should show flash on wrong data', (done) => {
it('should show flash on wrong data', async () => {
Api.groupMembers.mockReturnValue(Promise.reject(new Error()));
testAction(fetchPage, undefined, state, [], [], () => {
expect(createFlash).toHaveBeenCalledTimes(1);
done();
});
await testAction(fetchPage, undefined, state, [], []);
expect(createFlash).toHaveBeenCalledTimes(1);
});
});
});
......@@ -1648,15 +1648,12 @@ describe('RelatedItemTree', () => {
requestSpy.mockReturnValue([500, '']);
});
it('fails and shows flash message', (done) => {
return actions
.createNewIssue(context, payload)
.then(() => done.fail('expected action to throw error!'))
.catch(() => {
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
expect(context.dispatch).toHaveBeenCalledWith('receiveCreateIssueFailure');
done();
});
it('fails and shows flash message', async () => {
await expect(actions.createNewIssue(context, payload)).rejects.toEqual(
new Error('Request failed with status code 500'),
);
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
expect(context.dispatch).toHaveBeenCalledWith('receiveCreateIssueFailure');
});
});
});
......
......@@ -17,8 +17,8 @@ describe('pipeling jobs actions', () => {
describe('setPipelineJobsPath', () => {
const pipelineJobsPath = 123;
it('should commit the SET_PIPELINE_JOBS_PATH mutation', (done) => {
testAction(
it('should commit the SET_PIPELINE_JOBS_PATH mutation', async () => {
await testAction(
actions.setPipelineJobsPath,
pipelineJobsPath,
state,
......@@ -29,7 +29,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -37,8 +36,8 @@ describe('pipeling jobs actions', () => {
describe('setProjectId', () => {
const projectId = 123;
it('should commit the SET_PIPELINE_JOBS_PATH mutation', (done) => {
testAction(
it('should commit the SET_PIPELINE_JOBS_PATH mutation', async () => {
await testAction(
actions.setProjectId,
projectId,
state,
......@@ -49,7 +48,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -57,8 +55,8 @@ describe('pipeling jobs actions', () => {
describe('setPipelineId', () => {
const pipelineId = 123;
it('should commit the SET_PIPELINE_ID mutation', (done) => {
testAction(
it('should commit the SET_PIPELINE_ID mutation', async () => {
await testAction(
actions.setPipelineId,
pipelineId,
state,
......@@ -69,7 +67,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -92,8 +89,8 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(200, jobs);
});
it('should commit the request and success mutations', (done) => {
testAction(
it('should commit the request and success mutations', async () => {
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -105,7 +102,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -115,12 +111,12 @@ describe('pipeling jobs actions', () => {
mock.onGet('/api/undefined/projects/123/pipelines/321/jobs').replyOnce(200, jobs);
});
it('should commit the request and success mutations', (done) => {
it('should commit the request and success mutations', async () => {
state.pipelineJobsPath = '';
state.projectId = 123;
state.pipelineId = 321;
testAction(
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -132,7 +128,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -142,10 +137,10 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(200, jobs);
});
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', (done) => {
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', async () => {
state.pipelineJobsPath = '';
testAction(
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -155,7 +150,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -165,12 +159,12 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(200, jobs);
});
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', (done) => {
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', async () => {
state.pipelineJobsPath = '';
state.projectId = undefined;
state.pipelineId = undefined;
testAction(
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -180,7 +174,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -190,8 +183,8 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(404);
});
it('should commit REQUEST_PIPELINE_JOBS and RECEIVE_PIPELINE_JOBS_ERROR mutation', (done) => {
testAction(
it('should commit REQUEST_PIPELINE_JOBS and RECEIVE_PIPELINE_JOBS_ERROR mutation', async () => {
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -202,7 +195,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -45,10 +45,10 @@ describe('EE projectSelector actions', () => {
});
describe('toggleSelectedProject', () => {
it('adds a project to selectedProjects if it does not already exist in the list', (done) => {
it('adds a project to selectedProjects if it does not already exist in the list', async () => {
const payload = getMockProjects(1);
testAction(
await testAction(
actions.toggleSelectedProject,
payload,
state,
......@@ -59,15 +59,14 @@ describe('EE projectSelector actions', () => {
},
],
[],
done,
);
});
it('removes a project from selectedProjects if it already exist in the list', () => {
it('removes a project from selectedProjects if it already exist in the list', async () => {
const payload = getMockProjects(1)[0];
state.selectedProjects = getMockProjects(1);
return testAction(
await testAction(
actions.toggleSelectedProject,
payload,
state,
......@@ -102,12 +101,12 @@ describe('EE projectSelector actions', () => {
});
});
it('dispatches the correct actions when the request is successful', () => {
it('dispatches the correct actions when the request is successful', async () => {
state.projectEndpoints.add = mockAddEndpoint;
mockAxios.onPost(mockAddEndpoint).replyOnce(200, mockResponse);
return testAction(
await testAction(
actions.addProjects,
null,
state,
......
......@@ -43,8 +43,8 @@ describe('projects actions', () => {
});
});
it('should dispatch the request and success actions', (done) => {
testAction(
it('should dispatch the request and success actions', async () => {
await testAction(
actions.fetchProjects,
{},
state,
......@@ -56,7 +56,6 @@ describe('projects actions', () => {
payload: { projects: data },
},
],
done,
);
});
});
......@@ -70,8 +69,8 @@ describe('projects actions', () => {
mock.onGet(state.projectsEndpoint, { page: '2' }).replyOnce(200, [2]);
});
it('should dispatch the request and success actions', (done) => {
testAction(
it('should dispatch the request and success actions', async () => {
await testAction(
actions.fetchProjects,
{},
state,
......@@ -83,7 +82,6 @@ describe('projects actions', () => {
payload: { projects: [1, 2] },
},
],
done,
);
});
});
......@@ -93,14 +91,13 @@ describe('projects actions', () => {
mock.onGet(state.projectsEndpoint).replyOnce(404, {});
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.fetchProjects,
{},
state,
[],
[{ type: 'requestProjects' }, { type: 'receiveProjectsError' }],
done,
);
});
});
......@@ -110,17 +107,17 @@ describe('projects actions', () => {
state.projectsEndpoint = '';
});
it('should not do anything', (done) => {
testAction(actions.fetchProjects, {}, state, [], [], done);
it('should not do anything', async () => {
await testAction(actions.fetchProjects, {}, state, [], []);
});
});
});
describe('receiveProjectsSuccess', () => {
it('should commit the success mutation', (done) => {
it('should commit the success mutation', async () => {
const state = createState();
testAction(
await testAction(
actions.receiveProjectsSuccess,
{ projects: data },
state,
......@@ -131,39 +128,37 @@ describe('projects actions', () => {
},
],
[],
done,
);
});
});
describe('receiveProjectsError', () => {
it('should commit the error mutation', (done) => {
it('should commit the error mutation', async () => {
const state = createState();
testAction(
await testAction(
actions.receiveProjectsError,
{},
state,
[{ type: types.RECEIVE_PROJECTS_ERROR }],
[],
done,
);
});
});
describe('requestProjects', () => {
it('should commit the request mutation', (done) => {
it('should commit the request mutation', async () => {
const state = createState();
testAction(actions.requestProjects, {}, state, [{ type: types.REQUEST_PROJECTS }], [], done);
await testAction(actions.requestProjects, {}, state, [{ type: types.REQUEST_PROJECTS }], []);
});
});
describe('setProjectsEndpoint', () => {
it('should commit the correct mutuation', (done) => {
it('should commit the correct mutuation', async () => {
const state = createState();
testAction(
await testAction(
actions.setProjectsEndpoint,
endpoint,
state,
......@@ -174,7 +169,6 @@ describe('projects actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -98,22 +98,20 @@ describe('Status Page actions', () => {
});
describe('receiveStatusPageSettingsUpdateSuccess', () => {
it('should handle successful settings update', (done) => {
testAction(actions.receiveStatusPageSettingsUpdateSuccess, null, null, [], [], () => {
expect(refreshCurrentPage).toHaveBeenCalledTimes(1);
done();
});
it('should handle successful settings update', async () => {
await testAction(actions.receiveStatusPageSettingsUpdateSuccess, null, null, [], []);
expect(refreshCurrentPage).toHaveBeenCalledTimes(1);
});
});
describe('receiveStatusPageSettingsUpdateError', () => {
const error = { response: { data: { message: 'Update error' } } };
it('should handle error update', (done) => {
testAction(actions.receiveStatusPageSettingsUpdateError, error, null, [], [], () => {
it('should handle error update', async () => {
await testAction(actions.receiveStatusPageSettingsUpdateError, error, null, [], [], () => {
expect(createFlash).toHaveBeenCalledWith({
message: `There was an error saving your changes. ${error.response.data.message}`,
});
done();
});
});
});
......
......@@ -4,10 +4,6 @@ import ApprovalsAuth from 'ee/vue_merge_request_widget/components/approvals/appr
const TEST_PASSWORD = 'password';
// For some reason, the `Promise.resolve` needs to be deferred
// or the timing doesn't work.
const waitForTick = (done) => Promise.resolve().then(done).catch(done.fail);
describe('Approval auth component', () => {
let wrapper;
......@@ -22,16 +18,14 @@ describe('Approval auth component', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
const findInput = () => wrapper.find('input[type=password]');
const findErrorMessage = () => wrapper.find('.gl-field-error');
describe('when created', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent();
waitForTick(done);
});
it('password input control is rendered', () => {
......@@ -54,24 +48,21 @@ describe('Approval auth component', () => {
});
describe('when approve clicked', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent();
waitForTick(done);
});
it('emits the approve event', (done) => {
it('emits the approve event', async () => {
findInput().setValue(TEST_PASSWORD);
wrapper.findComponent(GlModal).vm.$emit('ok', { preventDefault: () => null });
waitForTick(done);
expect(wrapper.emitted().approve).toEqual([[TEST_PASSWORD]]);
});
});
describe('when isApproving is true', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent({ isApproving: true });
waitForTick(done);
});
it('disables the approve button', () => {
......@@ -82,9 +73,8 @@ describe('Approval auth component', () => {
});
describe('when hasError is true', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent({ hasError: true });
waitForTick(done);
});
it('shows the invalid password message', () => {
......
......@@ -27,7 +27,7 @@ describe('EpicsSelect', () => {
});
describe('setInitialData', () => {
it('should set initial data on state', (done) => {
it('should set initial data on state', async () => {
const mockInitialConfig = {
groupId: mockEpic1.group_id,
issueId: mockIssue.id,
......@@ -35,90 +35,84 @@ describe('EpicsSelect', () => {
selectedEpicIssueId: mockIssue.epic_issue_id,
};
testAction(
await testAction(
actions.setInitialData,
mockInitialConfig,
state,
[{ type: types.SET_INITIAL_DATA, payload: mockInitialConfig }],
[],
done,
);
});
});
describe('setIssueId', () => {
it('should set `issueId` on state', (done) => {
it('should set `issueId` on state', async () => {
const issueId = mockIssue.id;
testAction(
await testAction(
actions.setIssueId,
issueId,
state,
[{ type: types.SET_ISSUE_ID, payload: issueId }],
[],
done,
);
});
});
describe('setSearchQuery', () => {
it('should set `searchQuery` param on state', (done) => {
it('should set `searchQuery` param on state', async () => {
const searchQuery = 'foo';
testAction(
await testAction(
actions.setSearchQuery,
searchQuery,
state,
[{ type: types.SET_SEARCH_QUERY, payload: searchQuery }],
[],
done,
);
});
});
describe('setSelectedEpic', () => {
it('should set `selectedEpic` param on state', (done) => {
testAction(
it('should set `selectedEpic` param on state', async () => {
await testAction(
actions.setSelectedEpic,
mockEpic1,
state,
[{ type: types.SET_SELECTED_EPIC, payload: mockEpic1 }],
[],
done,
);
});
});
describe('setSelectedEpicIssueId', () => {
it('should set `selectedEpicIssueId` param on state', (done) => {
testAction(
it('should set `selectedEpicIssueId` param on state', async () => {
await testAction(
actions.setSelectedEpicIssueId,
mockIssue.epic_issue_id,
state,
[{ type: types.SET_SELECTED_EPIC_ISSUE_ID, payload: mockIssue.epic_issue_id }],
[],
done,
);
});
});
describe('requestEpics', () => {
it('should set `state.epicsFetchInProgress` to true', (done) => {
testAction(actions.requestEpics, {}, state, [{ type: types.REQUEST_EPICS }], [], done);
it('should set `state.epicsFetchInProgress` to true', async () => {
await testAction(actions.requestEpics, {}, state, [{ type: types.REQUEST_EPICS }], []);
});
});
describe('receiveEpicsSuccess', () => {
it('should set processed Epics array to `state.epics`', (done) => {
it('should set processed Epics array to `state.epics`', async () => {
state.groupId = mockEpic1.group_id;
testAction(
await testAction(
actions.receiveEpicsSuccess,
mockEpics,
state,
[{ type: types.RECEIVE_EPICS_SUCCESS, payload: { epics: normalizedEpics } }],
[],
done,
);
});
});
......@@ -134,14 +128,13 @@ describe('EpicsSelect', () => {
});
});
it('should set `state.epicsFetchInProgress` to false', (done) => {
testAction(
it('should set `state.epicsFetchInProgress` to false', async () => {
await testAction(
actions.receiveEpicsFailure,
{},
state,
[{ type: types.RECEIVE_EPICS_FAILURE }],
[],
done,
);
});
});
......@@ -151,14 +144,14 @@ describe('EpicsSelect', () => {
state.groupId = mockEpic1.group_id;
});
it('should dispatch `requestEpics` & call `Api.groupEpics` and then dispatch `receiveEpicsSuccess` on request success', (done) => {
it('should dispatch `requestEpics` & call `Api.groupEpics` and then dispatch `receiveEpicsSuccess` on request success', async () => {
jest.spyOn(Api, 'groupEpics').mockReturnValue(
Promise.resolve({
data: mockEpics,
}),
);
testAction(
await testAction(
actions.fetchEpics,
mockEpics,
state,
......@@ -172,14 +165,13 @@ describe('EpicsSelect', () => {
payload: mockEpics,
},
],
done,
);
});
it('should dispatch `requestEpics` & call `Api.groupEpics` and then dispatch `receiveEpicsFailure` on request failure', (done) => {
it('should dispatch `requestEpics` & call `Api.groupEpics` and then dispatch `receiveEpicsFailure` on request failure', async () => {
jest.spyOn(Api, 'groupEpics').mockReturnValue(Promise.reject());
testAction(
await testAction(
actions.fetchEpics,
mockEpics,
state,
......@@ -192,7 +184,6 @@ describe('EpicsSelect', () => {
type: 'receiveEpicsFailure',
},
],
done,
);
});
......@@ -221,23 +212,22 @@ describe('EpicsSelect', () => {
});
describe('requestIssueUpdate', () => {
it('should set `state.epicSelectInProgress` to true', (done) => {
testAction(
it('should set `state.epicSelectInProgress` to true', async () => {
await testAction(
actions.requestIssueUpdate,
{},
state,
[{ type: types.REQUEST_ISSUE_UPDATE }],
[],
done,
);
});
});
describe('receiveIssueUpdateSuccess', () => {
it('should set updated selectedEpic with passed Epic instance to state when payload has matching Epic and Issue IDs', (done) => {
it('should set updated selectedEpic with passed Epic instance to state when payload has matching Epic and Issue IDs', async () => {
state.issueId = mockIssue.id;
testAction(
await testAction(
actions.receiveIssueUpdateSuccess,
{
data: mockAssignRemoveRes,
......@@ -254,14 +244,13 @@ describe('EpicsSelect', () => {
},
],
[],
done,
);
});
it('should set updated selectedEpic with noneEpic to state when payload has matching Epic and Issue IDs and isRemoval param is true', (done) => {
it('should set updated selectedEpic with noneEpic to state when payload has matching Epic and Issue IDs and isRemoval param is true', async () => {
state.issueId = mockIssue.id;
testAction(
await testAction(
actions.receiveIssueUpdateSuccess,
{
data: mockAssignRemoveRes,
......@@ -279,12 +268,11 @@ describe('EpicsSelect', () => {
},
],
[],
done,
);
});
it('should not do any mutation to the state whe payload does not have matching Epic and Issue IDs', (done) => {
testAction(
it('should not do any mutation to the state whe payload does not have matching Epic and Issue IDs', async () => {
await testAction(
actions.receiveIssueUpdateSuccess,
{
data: mockAssignRemoveRes,
......@@ -293,7 +281,6 @@ describe('EpicsSelect', () => {
state,
[],
[],
done,
);
});
});
......@@ -311,14 +298,13 @@ describe('EpicsSelect', () => {
expect(createFlash).toHaveBeenCalledWith({ message });
});
it('should set `state.epicSelectInProgress` to false', (done) => {
testAction(
it('should set `state.epicSelectInProgress` to false', async () => {
await testAction(
actions.receiveIssueUpdateFailure,
{},
state,
[{ type: types.RECEIVE_ISSUE_UPDATE_FAILURE }],
[],
done,
);
});
});
......@@ -328,14 +314,14 @@ describe('EpicsSelect', () => {
state.issueId = mockIssue.id;
});
it('should dispatch `requestIssueUpdate` & call `Api.addEpicIssue` and then dispatch `receiveIssueUpdateSuccess` on request success', (done) => {
it('should dispatch `requestIssueUpdate` & call `Api.addEpicIssue` and then dispatch `receiveIssueUpdateSuccess` on request success', async () => {
jest.spyOn(Api, 'addEpicIssue').mockReturnValue(
Promise.resolve({
data: mockAssignRemoveRes,
}),
);
testAction(
await testAction(
actions.assignIssueToEpic,
normalizedEpics[0],
state,
......@@ -349,14 +335,13 @@ describe('EpicsSelect', () => {
payload: { data: mockAssignRemoveRes, epic: normalizedEpics[0] },
},
],
done,
);
});
it('should dispatch `requestIssueUpdate` & call `Api.addEpicIssue` and then dispatch `receiveIssueUpdateFailure` on request failure', (done) => {
it('should dispatch `requestIssueUpdate` & call `Api.addEpicIssue` and then dispatch `receiveIssueUpdateFailure` on request failure', async () => {
jest.spyOn(Api, 'addEpicIssue').mockReturnValue(Promise.reject());
testAction(
await testAction(
actions.assignIssueToEpic,
normalizedEpics[0],
state,
......@@ -370,7 +355,6 @@ describe('EpicsSelect', () => {
payload: 'Something went wrong while assigning issue to epic.',
},
],
done,
);
});
......@@ -402,14 +386,14 @@ describe('EpicsSelect', () => {
state.selectedEpicIssueId = mockIssue.epic_issue_id;
});
it('should dispatch `requestIssueUpdate` & call `Api.removeEpicIssue` and then dispatch `receiveIssueUpdateSuccess` on request success', (done) => {
it('should dispatch `requestIssueUpdate` & call `Api.removeEpicIssue` and then dispatch `receiveIssueUpdateSuccess` on request success', async () => {
jest.spyOn(Api, 'removeEpicIssue').mockReturnValue(
Promise.resolve({
data: mockAssignRemoveRes,
}),
);
testAction(
await testAction(
actions.removeIssueFromEpic,
normalizedEpics[0],
state,
......@@ -423,14 +407,13 @@ describe('EpicsSelect', () => {
payload: { data: mockAssignRemoveRes, epic: normalizedEpics[0], isRemoval: true },
},
],
done,
);
});
it('should dispatch `requestIssueUpdate` & call `Api.removeEpicIssue` and then dispatch `receiveIssueUpdateFailure` on request failure', (done) => {
it('should dispatch `requestIssueUpdate` & call `Api.removeEpicIssue` and then dispatch `receiveIssueUpdateFailure` on request failure', async () => {
jest.spyOn(Api, 'removeEpicIssue').mockReturnValue(Promise.reject());
testAction(
await testAction(
actions.removeIssueFromEpic,
normalizedEpics[0],
state,
......@@ -444,7 +427,6 @@ describe('EpicsSelect', () => {
payload: 'Something went wrong while removing issue from epic.',
},
],
done,
);
});
......
......@@ -46,7 +46,7 @@ describe('AddLicenseFormDropdown', () => {
expect(vm.$el.value).toContain(value);
});
it('shows all defined licenses', async (done) => {
it('shows all defined licenses', async () => {
await createComponent();
const element = $(vm.$el);
......@@ -58,7 +58,6 @@ describe('AddLicenseFormDropdown', () => {
options.each((index, optionEl) => {
expect(KNOWN_LICENSES).toContain($(optionEl).text());
});
done();
});
element.select2('open');
......
......@@ -46,74 +46,64 @@ describe('License store actions', () => {
});
describe('setAPISettings', () => {
it('commits SET_API_SETTINGS', (done) => {
it('commits SET_API_SETTINGS', async () => {
const payload = { apiUrlManageLicenses };
testAction(
await testAction(
actions.setAPISettings,
payload,
state,
[{ type: mutationTypes.SET_API_SETTINGS, payload }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('setKnownLicenses', () => {
it('commits SET_KNOWN_LICENSES', (done) => {
it('commits SET_KNOWN_LICENSES', async () => {
const payload = [{ name: 'BSD' }, { name: 'Apache' }];
testAction(
await testAction(
actions.setKnownLicenses,
payload,
state,
[{ type: mutationTypes.SET_KNOWN_LICENSES, payload }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('setLicenseInModal', () => {
it('commits SET_LICENSE_IN_MODAL with license', (done) => {
testAction(
it('commits SET_LICENSE_IN_MODAL with license', async () => {
await testAction(
actions.setLicenseInModal,
allowedLicense,
state,
[{ type: mutationTypes.SET_LICENSE_IN_MODAL, payload: allowedLicense }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('setIsAdmin', () => {
it('commits SET_IS_ADMIN', (done) => {
testAction(
it('commits SET_IS_ADMIN', async () => {
await testAction(
actions.setIsAdmin,
false,
state,
[{ type: mutationTypes.SET_IS_ADMIN, payload: false }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('resetLicenseInModal', () => {
it('commits RESET_LICENSE_IN_MODAL', (done) => {
testAction(
it('commits RESET_LICENSE_IN_MODAL', async () => {
await testAction(
actions.resetLicenseInModal,
null,
state,
[{ type: mutationTypes.RESET_LICENSE_IN_MODAL }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
......@@ -129,16 +119,14 @@ describe('License store actions', () => {
});
describe('receiveDeleteLicenseError', () => {
it('commits RESET_LICENSE_IN_MODAL', (done) => {
testAction(
it('commits RESET_LICENSE_IN_MODAL', async () => {
await testAction(
actions.receiveDeleteLicenseError,
null,
state,
[{ type: mutationTypes.RESET_LICENSE_IN_MODAL }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
......@@ -179,8 +167,8 @@ describe('License store actions', () => {
describe('receiveSetLicenseApproval', () => {
describe('given the licensesApiPath is provided', () => {
it('commits RESET_LICENSE_IN_MODAL and dispatches licenseList/fetchLicenses and fetchParsedLicenseReport', (done) => {
testAction(
it('commits RESET_LICENSE_IN_MODAL and dispatches licenseList/fetchLicenses and fetchParsedLicenseReport', async () => {
await testAction(
actions.receiveSetLicenseApproval,
null,
{ ...state, licensesApiPath },
......@@ -189,9 +177,7 @@ describe('License store actions', () => {
{ type: `licenseList/fetchLicenses`, payload: null },
{ type: 'fetchParsedLicenseReport' },
],
)
.then(done)
.catch(done.fail);
);
});
});
......@@ -208,16 +194,14 @@ describe('License store actions', () => {
});
describe('receiveSetLicenseApprovalError', () => {
it('commits RESET_LICENSE_IN_MODAL', (done) => {
testAction(
it('commits RESET_LICENSE_IN_MODAL', async () => {
await testAction(
actions.receiveSetLicenseApprovalError,
null,
state,
[{ type: mutationTypes.RESET_LICENSE_IN_MODAL }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
......@@ -310,116 +294,102 @@ describe('License store actions', () => {
describe('allowLicense', () => {
const newStatus = LICENSE_APPROVAL_STATUS.ALLOWED;
it('dispatches setLicenseApproval for un-allowed licenses', (done) => {
it('dispatches setLicenseApproval for un-allowed licenses', async () => {
const license = { name: 'FOO' };
testAction(
await testAction(
actions.allowLicense,
license,
state,
[],
[{ type: 'setLicenseApproval', payload: { license, newStatus } }],
)
.then(done)
.catch(done.fail);
);
});
it('dispatches setLicenseApproval for denied licenses', (done) => {
it('dispatches setLicenseApproval for denied licenses', async () => {
const license = deniedLicense;
testAction(
await testAction(
actions.allowLicense,
license,
state,
[],
[{ type: 'setLicenseApproval', payload: { license, newStatus } }],
)
.then(done)
.catch(done.fail);
);
});
it('does not dispatch setLicenseApproval for allowed licenses', (done) => {
testAction(actions.allowLicense, allowedLicense, state, [], []).then(done).catch(done.fail);
it('does not dispatch setLicenseApproval for allowed licenses', async () => {
await testAction(actions.allowLicense, allowedLicense, state, [], []);
});
});
describe('denyLicense', () => {
const newStatus = LICENSE_APPROVAL_STATUS.DENIED;
it('dispatches setLicenseApproval for un-allowed licenses', (done) => {
it('dispatches setLicenseApproval for un-allowed licenses', async () => {
const license = { name: 'FOO' };
testAction(
await testAction(
actions.denyLicense,
license,
state,
[],
[{ type: 'setLicenseApproval', payload: { license, newStatus } }],
)
.then(done)
.catch(done.fail);
);
});
it('dispatches setLicenseApproval for allowed licenses', (done) => {
it('dispatches setLicenseApproval for allowed licenses', async () => {
const license = allowedLicense;
testAction(
await testAction(
actions.denyLicense,
license,
state,
[],
[{ type: 'setLicenseApproval', payload: { license, newStatus } }],
)
.then(done)
.catch(done.fail);
);
});
it('does not dispatch setLicenseApproval for denied licenses', (done) => {
testAction(actions.denyLicense, deniedLicense, state, [], []).then(done).catch(done.fail);
it('does not dispatch setLicenseApproval for denied licenses', async () => {
await testAction(actions.denyLicense, deniedLicense, state, [], []);
});
});
describe('requestManagedLicenses', () => {
it('commits REQUEST_MANAGED_LICENSES', (done) => {
testAction(
it('commits REQUEST_MANAGED_LICENSES', async () => {
await testAction(
actions.requestManagedLicenses,
null,
state,
[{ type: mutationTypes.REQUEST_MANAGED_LICENSES }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('receiveManagedLicensesSuccess', () => {
it('commits RECEIVE_MANAGED_LICENSES_SUCCESS', (done) => {
it('commits RECEIVE_MANAGED_LICENSES_SUCCESS', async () => {
const payload = [allowedLicense];
testAction(
await testAction(
actions.receiveManagedLicensesSuccess,
payload,
state,
[{ type: mutationTypes.RECEIVE_MANAGED_LICENSES_SUCCESS, payload }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('receiveManagedLicensesError', () => {
it('commits RECEIVE_MANAGED_LICENSES_ERROR', (done) => {
it('commits RECEIVE_MANAGED_LICENSES_ERROR', async () => {
const error = new Error('Test');
testAction(
await testAction(
actions.receiveManagedLicensesError,
error,
state,
[{ type: mutationTypes.RECEIVE_MANAGED_LICENSES_ERROR }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
......@@ -430,45 +400,41 @@ describe('License store actions', () => {
endpointMock = axiosMock.onGet(apiUrlManageLicenses, { params: { per_page: 100 } });
});
it('dispatches requestManagedLicenses and receiveManagedLicensesSuccess for successful response', (done) => {
it('dispatches requestManagedLicenses and receiveManagedLicensesSuccess for successful response', async () => {
const payload = [{ name: 'foo', approval_status: LICENSE_APPROVAL_STATUS.DENIED }];
endpointMock.replyOnce(() => [200, payload]);
testAction(
await testAction(
actions.fetchManagedLicenses,
null,
state,
[],
[{ type: 'requestManagedLicenses' }, { type: 'receiveManagedLicensesSuccess', payload }],
)
.then(done)
.catch(done.fail);
);
});
it('dispatches requestManagedLicenses and receiveManagedLicensesError for error response', (done) => {
it('dispatches requestManagedLicenses and receiveManagedLicensesError for error response', async () => {
endpointMock.replyOnce(() => [500, '']);
testAction(
await testAction(
actions.fetchManagedLicenses,
null,
state,
[],
[{ type: 'requestManagedLicenses' }, { type: 'receiveManagedLicensesError' }],
)
.then(done)
.catch(done.fail);
);
});
});
describe('fetchLicenseCheckApprovalRule ', () => {
it('dispatches request/receive with detected approval rule', (done) => {
it('dispatches request/receive with detected approval rule', async () => {
const APPROVAL_RULE_RESPONSE = {
approval_rules_left: [{ name: LICENSE_CHECK_NAME }],
};
axiosMock.onGet(approvalsApiPath).replyOnce(200, APPROVAL_RULE_RESPONSE);
testAction(
await testAction(
actions.fetchLicenseCheckApprovalRule,
null,
state,
......@@ -480,18 +446,17 @@ describe('License store actions', () => {
payload: { hasLicenseCheckApprovalRule: true },
},
],
done,
);
});
it('dispatches request/receive without detected approval rule', (done) => {
it('dispatches request/receive without detected approval rule', async () => {
const APPROVAL_RULE_RESPONSE = {
approval_rules_left: [{ name: 'Another Approval Rule' }],
};
axiosMock.onGet(approvalsApiPath).replyOnce(200, APPROVAL_RULE_RESPONSE);
testAction(
await testAction(
actions.fetchLicenseCheckApprovalRule,
null,
state,
......@@ -503,15 +468,14 @@ describe('License store actions', () => {
payload: { hasLicenseCheckApprovalRule: false },
},
],
done,
);
});
it('dispatches request/receive error when no approvalsAPiPath is provided', (done) => {
it('dispatches request/receive error when no approvalsAPiPath is provided', async () => {
const error = new Error('approvalsApiPath not provided');
axiosMock.onGet(approvalsApiPath).replyOnce(500);
testAction(
await testAction(
actions.fetchLicenseCheckApprovalRule,
null,
{ ...state, approvalsApiPath: '' },
......@@ -520,15 +484,14 @@ describe('License store actions', () => {
{ type: 'requestLicenseCheckApprovalRule' },
{ type: 'receiveLicenseCheckApprovalRuleError', payload: error },
],
done,
);
});
it('dispatches request/receive on error', (done) => {
it('dispatches request/receive on error', async () => {
const error = new Error('Request failed with status code 500');
axiosMock.onGet(approvalsApiPath).replyOnce(500);
testAction(
await testAction(
actions.fetchLicenseCheckApprovalRule,
null,
state,
......@@ -537,30 +500,27 @@ describe('License store actions', () => {
{ type: 'requestLicenseCheckApprovalRule' },
{ type: 'receiveLicenseCheckApprovalRuleError', payload: error },
],
done,
);
});
});
describe('requestLicenseCheckApprovalRule', () => {
it('commits REQUEST_LICENSE_CHECK_APPROVAL_RULE', (done) => {
testAction(
it('commits REQUEST_LICENSE_CHECK_APPROVAL_RULE', async () => {
await testAction(
actions.requestLicenseCheckApprovalRule,
null,
state,
[{ type: mutationTypes.REQUEST_LICENSE_CHECK_APPROVAL_RULE }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('receiveLicenseCheckApprovalRuleSuccess', () => {
it('commits REQUEST_LICENSE_CHECK_APPROVAL_RULE', (done) => {
it('commits REQUEST_LICENSE_CHECK_APPROVAL_RULE', async () => {
const hasLicenseCheckApprovalRule = true;
testAction(
await testAction(
actions.receiveLicenseCheckApprovalRuleSuccess,
{ hasLicenseCheckApprovalRule },
state,
......@@ -571,71 +531,61 @@ describe('License store actions', () => {
},
],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('receiveLicenseCheckApprovalRuleError', () => {
it('commits RECEIVE_LICENSE_CHECK_APPROVAL_RULE_ERROR', (done) => {
it('commits RECEIVE_LICENSE_CHECK_APPROVAL_RULE_ERROR', async () => {
const error = new Error('Error');
testAction(
await testAction(
actions.receiveLicenseCheckApprovalRuleError,
error,
state,
[{ type: mutationTypes.RECEIVE_LICENSE_CHECK_APPROVAL_RULE_ERROR, payload: error }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('requestParsedLicenseReport', () => {
it(`should commit ${mutationTypes.REQUEST_PARSED_LICENSE_REPORT}`, (done) => {
testAction(
it(`should commit ${mutationTypes.REQUEST_PARSED_LICENSE_REPORT}`, async () => {
await testAction(
actions.requestParsedLicenseReport,
null,
state,
[{ type: mutationTypes.REQUEST_PARSED_LICENSE_REPORT }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('receiveParsedLicenseReportSuccess', () => {
it(`should commit ${mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS} with the correct payload`, (done) => {
it(`should commit ${mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS} with the correct payload`, async () => {
const payload = { newLicenses: [{ name: 'foo' }] };
testAction(
await testAction(
actions.receiveParsedLicenseReportSuccess,
payload,
state,
[{ type: mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS, payload }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
describe('receiveParsedLicenseReportError', () => {
it(`should commit ${mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_ERROR}`, (done) => {
it(`should commit ${mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_ERROR}`, async () => {
const payload = new Error('Test');
testAction(
await testAction(
actions.receiveParsedLicenseReportError,
payload,
state,
[{ type: mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_ERROR, payload }],
[],
)
.then(done)
.catch(done.fail);
);
});
});
......@@ -664,7 +614,7 @@ describe('License store actions', () => {
];
});
it('should fetch, parse, and dispatch the new licenses on a successful request', (done) => {
it('should fetch, parse, and dispatch the new licenses on a successful request', async () => {
licensesApiMock.replyOnce(() => [200, rawLicenseReport]);
const parsedLicenses = {
......@@ -680,7 +630,7 @@ describe('License store actions', () => {
],
};
testAction(
await testAction(
actions.fetchParsedLicenseReport,
null,
state,
......@@ -689,15 +639,13 @@ describe('License store actions', () => {
{ type: 'requestParsedLicenseReport' },
{ type: 'receiveParsedLicenseReportSuccess', payload: parsedLicenses },
],
)
.then(done)
.catch(done.fail);
);
});
it('should send an error on an unsuccesful request', (done) => {
it('should send an error on an unsuccesful request', async () => {
licensesApiMock.replyOnce(400);
testAction(
await testAction(
actions.fetchParsedLicenseReport,
null,
state,
......@@ -706,9 +654,7 @@ describe('License store actions', () => {
{ type: 'requestParsedLicenseReport' },
{ type: 'receiveParsedLicenseReportError', payload: expect.any(Error) },
],
)
.then(done)
.catch(done.fail);
);
});
});
......@@ -752,7 +698,7 @@ describe('License store actions', () => {
};
});
it('should fetch, parse, and dispatch the new licenses on a successful request', (done) => {
it('should fetch, parse, and dispatch the new licenses on a successful request', async () => {
licensesApiMock.replyOnce(() => [200, rawLicenseReport]);
const parsedLicenses = {
......@@ -783,7 +729,7 @@ describe('License store actions', () => {
],
};
testAction(
await testAction(
actions.fetchParsedLicenseReport,
null,
state,
......@@ -792,9 +738,7 @@ describe('License store actions', () => {
{ type: 'requestParsedLicenseReport' },
{ type: 'receiveParsedLicenseReportSuccess', payload: parsedLicenses },
],
)
.then(done)
.catch(done.fail);
);
});
});
});
......
import MockAdapter from 'axios-mock-adapter';
import {
setHeadBlobPath,
setBaseBlobPath,
setCanReadVulnerabilityFeedback,
setVulnerabilityFeedbackPath,
setPipelineId,
requestContainerScanningDiff,
requestDastDiff,
requestDependencyScanningDiff,
requestCoverageFuzzingDiff,
setModalData,
requestDismissVulnerability,
receiveDismissVulnerability,
receiveDismissVulnerabilityError,
dismissVulnerability,
revertDismissVulnerability,
requestCreateIssue,
receiveCreateIssue,
receiveCreateIssueError,
createNewIssue,
downloadPatch,
requestCreateMergeRequest,
receiveCreateMergeRequestSuccess,
receiveCreateMergeRequestError,
createMergeRequest,
updateDependencyScanningIssue,
updateContainerScanningIssue,
updateDastIssue,
updateCoverageFuzzingIssue,
addDismissalComment,
receiveAddDismissalCommentError,
receiveAddDismissalCommentSuccess,
requestAddDismissalComment,
deleteDismissalComment,
receiveDeleteDismissalCommentError,
receiveDeleteDismissalCommentSuccess,
requestDeleteDismissalComment,
showDismissalDeleteButtons,
hideDismissalDeleteButtons,
setContainerScanningDiffEndpoint,
receiveContainerScanningDiffSuccess,
receiveContainerScanningDiffError,
fetchContainerScanningDiff,
setDependencyScanningDiffEndpoint,
receiveDependencyScanningDiffSuccess,
receiveDependencyScanningDiffError,
fetchDependencyScanningDiff,
setDastDiffEndpoint,
receiveDastDiffSuccess,
receiveDastDiffError,
fetchDastDiff,
setCoverageFuzzingDiffEndpoint,
receiveCoverageFuzzingDiffSuccess,
receiveCoverageFuzzingDiffError,
fetchCoverageFuzzingDiff,
} from 'ee/vue_shared/security_reports/store/actions';
import * as securityReportsAction from 'ee/vue_shared/security_reports/store/actions';
import * as types from 'ee/vue_shared/security_reports/store/mutation_types';
import state from 'ee/vue_shared/security_reports/store/state';
import testAction from 'helpers/vuex_action_helper';
......@@ -115,9 +60,9 @@ describe('security reports actions', () => {
});
describe('setHeadBlobPath', () => {
it('should commit set head blob path', (done) => {
testAction(
setHeadBlobPath,
it('should commit set head blob path', async () => {
await testAction(
securityReportsAction.setHeadBlobPath,
'path',
mockedState,
[
......@@ -127,15 +72,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('setBaseBlobPath', () => {
it('should commit set head blob path', (done) => {
testAction(
setBaseBlobPath,
it('should commit set head blob path', async () => {
await testAction(
securityReportsAction.setBaseBlobPath,
'path',
mockedState,
[
......@@ -145,15 +89,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('setCanReadVulnerabilityFeedback', () => {
it('should commit set vulnerabulity feedback path', (done) => {
testAction(
setCanReadVulnerabilityFeedback,
it('should commit set vulnerabulity feedback path', async () => {
await testAction(
securityReportsAction.setCanReadVulnerabilityFeedback,
true,
mockedState,
[
......@@ -163,15 +106,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('setVulnerabilityFeedbackPath', () => {
it('should commit set vulnerabulity feedback path', (done) => {
testAction(
setVulnerabilityFeedbackPath,
it('should commit set vulnerabulity feedback path', async () => {
await testAction(
securityReportsAction.setVulnerabilityFeedbackPath,
'path',
mockedState,
[
......@@ -181,15 +123,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('setPipelineId', () => {
it('should commit set vulnerability feedback path', (done) => {
testAction(
setPipelineId,
it('should commit set vulnerability feedback path', async () => {
await testAction(
securityReportsAction.setPipelineId,
123,
mockedState,
[
......@@ -199,15 +140,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('requestContainerScanningDiff', () => {
it('should commit request mutation', (done) => {
testAction(
requestContainerScanningDiff,
it('should commit request mutation', async () => {
await testAction(
securityReportsAction.requestContainerScanningDiff,
null,
mockedState,
[
......@@ -216,15 +156,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('requestDastDiff', () => {
it('should commit request mutation', (done) => {
testAction(
requestDastDiff,
it('should commit request mutation', async () => {
await testAction(
securityReportsAction.requestDastDiff,
null,
mockedState,
[
......@@ -233,15 +172,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('requestDependencyScanningDiff', () => {
it('should commit request mutation', (done) => {
testAction(
requestDependencyScanningDiff,
it('should commit request mutation', async () => {
await testAction(
securityReportsAction.requestDependencyScanningDiff,
null,
mockedState,
[
......@@ -250,15 +188,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('requestCoverageFuzzingDiff', () => {
it('should commit request mutation', (done) => {
testAction(
requestCoverageFuzzingDiff,
it('should commit request mutation', async () => {
await testAction(
securityReportsAction.requestCoverageFuzzingDiff,
null,
mockedState,
[
......@@ -267,15 +204,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('setModalData', () => {
it('commits set issue modal data', (done) => {
testAction(
setModalData,
it('commits set issue modal data', async () => {
await testAction(
securityReportsAction.setModalData,
{ issue: { id: 1 }, status: 'success' },
mockedState,
[
......@@ -285,15 +221,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('requestDismissVulnerability', () => {
it('commits request dismiss issue', (done) => {
testAction(
requestDismissVulnerability,
it('commits request dismiss issue', async () => {
await testAction(
securityReportsAction.requestDismissVulnerability,
null,
mockedState,
[
......@@ -302,17 +237,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDismissVulnerability', () => {
it(`should pass the payload to the ${types.RECEIVE_DISMISS_VULNERABILITY_SUCCESS} mutation`, (done) => {
it(`should pass the payload to the ${types.RECEIVE_DISMISS_VULNERABILITY_SUCCESS} mutation`, async () => {
const payload = createDismissedVulnerability();
testAction(
receiveDismissVulnerability,
await testAction(
securityReportsAction.receiveDismissVulnerability,
payload,
mockedState,
[
......@@ -322,15 +256,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDismissVulnerabilityError', () => {
it('commits receive dismiss issue error with payload', (done) => {
testAction(
receiveDismissVulnerabilityError,
it('commits receive dismiss issue error with payload', async () => {
await testAction(
securityReportsAction.receiveDismissVulnerabilityError,
'error',
mockedState,
[
......@@ -340,7 +273,6 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
......@@ -362,9 +294,9 @@ describe('security reports actions', () => {
mockedState.createVulnerabilityFeedbackDismissalPath = 'dismiss_vulnerability_path';
});
it(`should dispatch receiveDismissVulnerability`, (done) => {
testAction(
dismissVulnerability,
it(`should dispatch receiveDismissVulnerability`, async () => {
await testAction(
securityReportsAction.dismissVulnerability,
payload,
mockedState,
[],
......@@ -380,18 +312,12 @@ describe('security reports actions', () => {
payload,
},
],
done,
);
});
it('show dismiss vulnerability toast message', (done) => {
const checkToastMessage = () => {
expect(toasted).toHaveBeenCalledTimes(1);
done();
};
testAction(
dismissVulnerability,
it('show dismiss vulnerability toast message', async () => {
await testAction(
securityReportsAction.dismissVulnerability,
payload,
mockedState,
[],
......@@ -407,8 +333,9 @@ describe('security reports actions', () => {
payload,
},
],
checkToastMessage,
);
expect(toasted).toHaveBeenCalledTimes(1);
});
});
......@@ -422,13 +349,13 @@ describe('security reports actions', () => {
mockedState.canReadVulnerabilityFeedback = true;
});
it('should dispatch `receiveDismissVulnerabilityError` with the correct payload', (done) => {
it('should dispatch `receiveDismissVulnerabilityError` with the correct payload', async () => {
mock
.onPost(mockedState.createVulnerabilityFeedbackDismissalPath)
.replyOnce(httpStatusErrorCode);
testAction(
dismissVulnerability,
await testAction(
securityReportsAction.dismissVulnerability,
null,
mockedState,
[],
......@@ -441,7 +368,6 @@ describe('security reports actions', () => {
payload: expectedErrorMessage,
},
],
done,
);
});
});
......@@ -462,9 +388,9 @@ describe('security reports actions', () => {
mock.onPatch(url).replyOnce(200, data);
});
it('should dispatch the request and success actions', (done) => {
testAction(
addDismissalComment,
it('should dispatch the request and success actions', async () => {
await testAction(
securityReportsAction.addDismissalComment,
{ comment },
{ modal: { vulnerability } },
[],
......@@ -476,18 +402,12 @@ describe('security reports actions', () => {
payload: { data },
},
],
done,
);
});
it('should show added dismissal comment toast message', (done) => {
const checkToastMessage = () => {
expect(toasted).toHaveBeenCalledTimes(1);
done();
};
testAction(
addDismissalComment,
it('should show added dismissal comment toast message', async () => {
await testAction(
securityReportsAction.addDismissalComment,
{ comment },
{ modal: { vulnerability } },
[],
......@@ -499,8 +419,9 @@ describe('security reports actions', () => {
payload: { data },
},
],
checkToastMessage,
);
expect(toasted).toHaveBeenCalledTimes(1);
});
});
......@@ -509,9 +430,9 @@ describe('security reports actions', () => {
mock.onPatch(url).replyOnce(404);
});
it('should dispatch the request and error actions', (done) => {
testAction(
addDismissalComment,
it('should dispatch the request and error actions', async () => {
await testAction(
securityReportsAction.addDismissalComment,
{ comment },
{ modal: { vulnerability } },
[],
......@@ -522,28 +443,26 @@ describe('security reports actions', () => {
payload: 'There was an error adding the comment.',
},
],
done,
);
});
});
describe('receiveAddDismissalCommentSuccess', () => {
it('should commit the success mutation', (done) => {
testAction(
receiveAddDismissalCommentSuccess,
it('should commit the success mutation', async () => {
await testAction(
securityReportsAction.receiveAddDismissalCommentSuccess,
{ data },
state,
[{ type: types.RECEIVE_ADD_DISMISSAL_COMMENT_SUCCESS, payload: { data } }],
[],
done,
);
});
});
describe('receiveAddDismissalCommentError', () => {
it('should commit the error mutation', (done) => {
testAction(
receiveAddDismissalCommentError,
it('should commit the error mutation', async () => {
await testAction(
securityReportsAction.receiveAddDismissalCommentError,
{},
state,
[
......@@ -553,20 +472,18 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('requestAddDismissalComment', () => {
it('should commit the request mutation', (done) => {
testAction(
requestAddDismissalComment,
it('should commit the request mutation', async () => {
await testAction(
securityReportsAction.requestAddDismissalComment,
{},
state,
[{ type: types.REQUEST_ADD_DISMISSAL_COMMENT }],
[],
done,
);
});
});
......@@ -587,9 +504,9 @@ describe('security reports actions', () => {
mock.onPatch(url).replyOnce(200, data);
});
it('should dispatch the request and success actions', (done) => {
testAction(
deleteDismissalComment,
it('should dispatch the request and success actions', async () => {
await testAction(
securityReportsAction.deleteDismissalComment,
{ comment },
{ modal: { vulnerability } },
[],
......@@ -601,18 +518,12 @@ describe('security reports actions', () => {
payload: { data },
},
],
done,
);
});
it('should show deleted dismissal comment toast message', (done) => {
const checkToastMessage = () => {
expect(toasted).toHaveBeenCalledTimes(1);
done();
};
testAction(
deleteDismissalComment,
it('should show deleted dismissal comment toast message', async () => {
await testAction(
securityReportsAction.deleteDismissalComment,
{ comment },
{ modal: { vulnerability } },
[],
......@@ -624,8 +535,9 @@ describe('security reports actions', () => {
payload: { data },
},
],
checkToastMessage,
);
expect(toasted).toHaveBeenCalledTimes(1);
});
});
......@@ -634,9 +546,9 @@ describe('security reports actions', () => {
mock.onPatch(url).replyOnce(404);
});
it('should dispatch the request and error actions', (done) => {
testAction(
deleteDismissalComment,
it('should dispatch the request and error actions', async () => {
await testAction(
securityReportsAction.deleteDismissalComment,
{ comment },
{ modal: { vulnerability } },
[],
......@@ -647,28 +559,26 @@ describe('security reports actions', () => {
payload: 'There was an error deleting the comment.',
},
],
done,
);
});
});
describe('receiveDeleteDismissalCommentSuccess', () => {
it('should commit the success mutation', (done) => {
testAction(
receiveDeleteDismissalCommentSuccess,
it('should commit the success mutation', async () => {
await testAction(
securityReportsAction.receiveDeleteDismissalCommentSuccess,
{ data },
state,
[{ type: types.RECEIVE_DELETE_DISMISSAL_COMMENT_SUCCESS, payload: { data } }],
[],
done,
);
});
});
describe('receiveDeleteDismissalCommentError', () => {
it('should commit the error mutation', (done) => {
testAction(
receiveDeleteDismissalCommentError,
it('should commit the error mutation', async () => {
await testAction(
securityReportsAction.receiveDeleteDismissalCommentError,
{},
state,
[
......@@ -678,29 +588,27 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('requestDeleteDismissalComment', () => {
it('should commit the request mutation', (done) => {
testAction(
requestDeleteDismissalComment,
it('should commit the request mutation', async () => {
await testAction(
securityReportsAction.requestDeleteDismissalComment,
{},
state,
[{ type: types.REQUEST_DELETE_DISMISSAL_COMMENT }],
[],
done,
);
});
});
});
describe('showDismissalDeleteButtons', () => {
it('commits show dismissal delete buttons', (done) => {
testAction(
showDismissalDeleteButtons,
it('commits show dismissal delete buttons', async () => {
await testAction(
securityReportsAction.showDismissalDeleteButtons,
null,
mockedState,
[
......@@ -709,15 +617,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('hideDismissalDeleteButtons', () => {
it('commits hide dismissal delete buttons', (done) => {
testAction(
hideDismissalDeleteButtons,
it('commits hide dismissal delete buttons', async () => {
await testAction(
securityReportsAction.hideDismissalDeleteButtons,
null,
mockedState,
[
......@@ -726,7 +633,6 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
......@@ -744,9 +650,9 @@ describe('security reports actions', () => {
payload = createNonDismissedVulnerability({ ...mockedState.modal.vulnerability });
});
it('should dispatch `receiveDismissVulnerability`', (done) => {
testAction(
revertDismissVulnerability,
it('should dispatch `receiveDismissVulnerability`', async () => {
await testAction(
securityReportsAction.revertDismissVulnerability,
payload,
mockedState,
[],
......@@ -759,18 +665,17 @@ describe('security reports actions', () => {
payload,
},
],
done,
);
});
});
it('with error should dispatch `receiveDismissVulnerabilityError`', (done) => {
it('with error should dispatch `receiveDismissVulnerabilityError`', async () => {
mock.onDelete('dismiss_vulnerability_path/123').reply(500, {});
mockedState.modal.vulnerability.dismissalFeedback = { id: 123 };
mockedState.createVulnerabilityFeedbackDismissalPath = 'dismiss_vulnerability_path';
testAction(
revertDismissVulnerability,
await testAction(
securityReportsAction.revertDismissVulnerability,
null,
mockedState,
[],
......@@ -783,15 +688,14 @@ describe('security reports actions', () => {
payload: 'There was an error reverting the dismissal. Please try again.',
},
],
done,
);
});
});
describe('requestCreateIssue', () => {
it('commits request create issue', (done) => {
testAction(
requestCreateIssue,
it('commits request create issue', async () => {
await testAction(
securityReportsAction.requestCreateIssue,
null,
mockedState,
[
......@@ -800,15 +704,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveCreateIssue', () => {
it('commits receive create issue', (done) => {
testAction(
receiveCreateIssue,
it('commits receive create issue', async () => {
await testAction(
securityReportsAction.receiveCreateIssue,
null,
mockedState,
[
......@@ -817,15 +720,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveCreateIssueError', () => {
it('commits receive create issue error with payload', (done) => {
testAction(
receiveCreateIssueError,
it('commits receive create issue error with payload', async () => {
await testAction(
securityReportsAction.receiveCreateIssueError,
'error',
mockedState,
[
......@@ -835,18 +737,17 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('createNewIssue', () => {
it('with success should dispatch `requestCreateIssue` and `receiveCreateIssue`', (done) => {
it('with success should dispatch `requestCreateIssue` and `receiveCreateIssue`', async () => {
mock.onPost('create_issue_path').reply(200, { issue_path: 'new_issue' });
mockedState.createVulnerabilityFeedbackIssuePath = 'create_issue_path';
testAction(
createNewIssue,
await testAction(
securityReportsAction.createNewIssue,
null,
mockedState,
[],
......@@ -858,17 +759,16 @@ describe('security reports actions', () => {
type: 'receiveCreateIssue',
},
],
done,
);
});
it('with error should dispatch `receiveCreateIssueError`', (done) => {
it('with error should dispatch `receiveCreateIssueError`', async () => {
mock.onPost('create_issue_path').reply(500, {});
mockedState.vulnerabilityFeedbackPath = 'create_issue_path';
mockedState.canReadVulnerabilityFeedback = true;
testAction(
createNewIssue,
await testAction(
securityReportsAction.createNewIssue,
null,
mockedState,
[],
......@@ -881,7 +781,6 @@ describe('security reports actions', () => {
payload: 'There was an error creating the issue. Please try again.',
},
],
done,
);
});
});
......@@ -891,7 +790,7 @@ describe('security reports actions', () => {
const a = { click: jest.fn() };
jest.spyOn(document, 'createElement').mockImplementation(() => a);
downloadPatch({
securityReportsAction.downloadPatch({
state: {
modal: {
vulnerability: {
......@@ -914,9 +813,9 @@ describe('security reports actions', () => {
});
describe('requestCreateMergeRequest', () => {
it('commits request create merge request', (done) => {
testAction(
requestCreateMergeRequest,
it('commits request create merge request', async () => {
await testAction(
securityReportsAction.requestCreateMergeRequest,
null,
mockedState,
[
......@@ -925,17 +824,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveCreateMergeRequestSuccess', () => {
it('commits receive create merge request', (done) => {
it('commits receive create merge request', async () => {
const data = { foo: 'bar' };
testAction(
receiveCreateMergeRequestSuccess,
await testAction(
securityReportsAction.receiveCreateMergeRequestSuccess,
data,
mockedState,
[
......@@ -945,15 +843,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveCreateMergeRequestError', () => {
it('commits receive create merge request error', (done) => {
testAction(
receiveCreateMergeRequestError,
it('commits receive create merge request error', async () => {
await testAction(
securityReportsAction.receiveCreateMergeRequestError,
'',
mockedState,
[
......@@ -962,19 +859,18 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('createMergeRequest', () => {
it('with success should dispatch `receiveCreateMergeRequestSuccess`', (done) => {
it('with success should dispatch `receiveCreateMergeRequestSuccess`', async () => {
const data = { merge_request_path: 'fakepath.html' };
mockedState.createVulnerabilityFeedbackMergeRequestPath = 'create_merge_request_path';
mock.onPost('create_merge_request_path').reply(200, data);
testAction(
createMergeRequest,
await testAction(
securityReportsAction.createMergeRequest,
null,
mockedState,
[],
......@@ -987,17 +883,16 @@ describe('security reports actions', () => {
payload: data,
},
],
done,
);
});
it('with error should dispatch `receiveCreateMergeRequestError`', (done) => {
it('with error should dispatch `receiveCreateMergeRequestError`', async () => {
mock.onPost('create_merge_request_path').reply(500, {});
mockedState.vulnerabilityFeedbackPath = 'create_merge_request_path';
mockedState.canReadVulnerabilityFeedback = true;
testAction(
createMergeRequest,
await testAction(
securityReportsAction.createMergeRequest,
null,
mockedState,
[],
......@@ -1010,17 +905,16 @@ describe('security reports actions', () => {
payload: 'There was an error creating the merge request. Please try again.',
},
],
done,
);
});
});
describe('updateDependencyScanningIssue', () => {
it('commits update dependency scanning issue', (done) => {
it('commits update dependency scanning issue', async () => {
const payload = { foo: 'bar' };
testAction(
updateDependencyScanningIssue,
await testAction(
securityReportsAction.updateDependencyScanningIssue,
payload,
mockedState,
[
......@@ -1030,17 +924,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('updateContainerScanningIssue', () => {
it('commits update container scanning issue', (done) => {
it('commits update container scanning issue', async () => {
const payload = { foo: 'bar' };
testAction(
updateContainerScanningIssue,
await testAction(
securityReportsAction.updateContainerScanningIssue,
payload,
mockedState,
[
......@@ -1050,17 +943,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('updateDastIssue', () => {
it('commits update dast issue', (done) => {
it('commits update dast issue', async () => {
const payload = { foo: 'bar' };
testAction(
updateDastIssue,
await testAction(
securityReportsAction.updateDastIssue,
payload,
mockedState,
[
......@@ -1070,17 +962,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('updateCoverageFuzzingIssue', () => {
it('commits update coverageFuzzing issue', (done) => {
it('commits update coverageFuzzing issue', async () => {
const payload = { foo: 'bar' };
testAction(
updateCoverageFuzzingIssue,
await testAction(
securityReportsAction.updateCoverageFuzzingIssue,
payload,
mockedState,
[
......@@ -1090,17 +981,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('setContainerScanningDiffEndpoint', () => {
it('should pass down the endpoint to the mutation', (done) => {
it('should pass down the endpoint to the mutation', async () => {
const payload = '/container_scanning_endpoint.json';
testAction(
setContainerScanningDiffEndpoint,
await testAction(
securityReportsAction.setContainerScanningDiffEndpoint,
payload,
mockedState,
[
......@@ -1110,17 +1000,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveContainerScanningDiffSuccess', () => {
it('should pass down the response to the mutation', (done) => {
it('should pass down the response to the mutation', async () => {
const payload = { data: 'Effort yields its own rewards.' };
testAction(
receiveContainerScanningDiffSuccess,
await testAction(
securityReportsAction.receiveContainerScanningDiffSuccess,
payload,
mockedState,
[
......@@ -1130,15 +1019,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveContainerScanningDiffError', () => {
it('should commit container diff error mutation', (done) => {
testAction(
receiveContainerScanningDiffError,
it('should commit container diff error mutation', async () => {
await testAction(
securityReportsAction.receiveContainerScanningDiffError,
undefined,
mockedState,
[
......@@ -1147,7 +1035,6 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
......@@ -1163,7 +1050,7 @@ describe('security reports actions', () => {
});
describe('on success', () => {
it('should dispatch `receiveContainerScanningDiffSuccess`', (done) => {
it('should dispatch `receiveContainerScanningDiffSuccess`', async () => {
mock.onGet(endpoint).reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1173,8 +1060,8 @@ describe('security reports actions', () => {
})
.reply(200, containerScanningFeedbacks);
testAction(
fetchContainerScanningDiff,
await testAction(
securityReportsAction.fetchContainerScanningDiff,
null,
mockedState,
[],
......@@ -1190,7 +1077,6 @@ describe('security reports actions', () => {
},
},
],
done,
);
});
});
......@@ -1201,9 +1087,9 @@ describe('security reports actions', () => {
mock.onGet(endpoint).reply(200, diff);
});
it('should dispatch `receiveContainerScanningDiffSuccess`', (done) => {
testAction(
fetchContainerScanningDiff,
it('should dispatch `receiveContainerScanningDiffSuccess`', async () => {
await testAction(
securityReportsAction.fetchContainerScanningDiff,
null,
mockedState,
[],
......@@ -1219,13 +1105,12 @@ describe('security reports actions', () => {
},
},
],
done,
);
});
});
describe('when vulnerabilities path errors', () => {
it('should dispatch `receiveContainerScanningError`', (done) => {
it('should dispatch `receiveContainerScanningError`', async () => {
mock.onGet(endpoint).reply(500);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1235,8 +1120,8 @@ describe('security reports actions', () => {
})
.reply(200, containerScanningFeedbacks);
testAction(
fetchContainerScanningDiff,
await testAction(
securityReportsAction.fetchContainerScanningDiff,
null,
mockedState,
[],
......@@ -1248,13 +1133,12 @@ describe('security reports actions', () => {
type: 'receiveContainerScanningDiffError',
},
],
done,
);
});
});
describe('when feedback path errors', () => {
it('should dispatch `receiveContainerScanningError`', (done) => {
it('should dispatch `receiveContainerScanningError`', async () => {
mock.onGet(endpoint).reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1264,8 +1148,8 @@ describe('security reports actions', () => {
})
.reply(500);
testAction(
fetchContainerScanningDiff,
await testAction(
securityReportsAction.fetchContainerScanningDiff,
null,
mockedState,
[],
......@@ -1277,18 +1161,17 @@ describe('security reports actions', () => {
type: 'receiveContainerScanningDiffError',
},
],
done,
);
});
});
});
describe('setDependencyScanningDiffEndpoint', () => {
it('should pass down the endpoint to the mutation', (done) => {
it('should pass down the endpoint to the mutation', async () => {
const payload = '/dependency_scanning_endpoint.json';
testAction(
setDependencyScanningDiffEndpoint,
await testAction(
securityReportsAction.setDependencyScanningDiffEndpoint,
payload,
mockedState,
[
......@@ -1298,17 +1181,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDependencyScanningDiffSuccess', () => {
it('should pass down the response to the mutation', (done) => {
it('should pass down the response to the mutation', async () => {
const payload = { data: 'Effort yields its own rewards.' };
testAction(
receiveDependencyScanningDiffSuccess,
await testAction(
securityReportsAction.receiveDependencyScanningDiffSuccess,
payload,
mockedState,
[
......@@ -1318,15 +1200,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDependencyScanningDiffError', () => {
it('should commit dependency scanning diff error mutation', (done) => {
testAction(
receiveDependencyScanningDiffError,
it('should commit dependency scanning diff error mutation', async () => {
await testAction(
securityReportsAction.receiveDependencyScanningDiffError,
undefined,
mockedState,
[
......@@ -1335,7 +1216,6 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
......@@ -1350,7 +1230,7 @@ describe('security reports actions', () => {
});
describe('on success', () => {
it('should dispatch `receiveDependencyScanningDiffSuccess`', (done) => {
it('should dispatch `receiveDependencyScanningDiffSuccess`', async () => {
mock.onGet('dependency_scanning_diff.json').reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1360,8 +1240,8 @@ describe('security reports actions', () => {
})
.reply(200, dependencyScanningFeedbacks);
testAction(
fetchDependencyScanningDiff,
await testAction(
securityReportsAction.fetchDependencyScanningDiff,
null,
mockedState,
[],
......@@ -1377,7 +1257,6 @@ describe('security reports actions', () => {
},
},
],
done,
);
});
});
......@@ -1388,9 +1267,9 @@ describe('security reports actions', () => {
mock.onGet('dependency_scanning_diff.json').reply(200, diff);
});
it('should dispatch `receiveDependencyScanningDiffSuccess`', (done) => {
testAction(
fetchDependencyScanningDiff,
it('should dispatch `receiveDependencyScanningDiffSuccess`', async () => {
await testAction(
securityReportsAction.fetchDependencyScanningDiff,
null,
mockedState,
[],
......@@ -1406,13 +1285,12 @@ describe('security reports actions', () => {
},
},
],
done,
);
});
});
describe('when vulnerabilities path errors', () => {
it('should dispatch `receiveDependencyScanningError`', (done) => {
it('should dispatch `receiveDependencyScanningError`', async () => {
mock.onGet('dependency_scanning_diff.json').reply(500);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1422,8 +1300,8 @@ describe('security reports actions', () => {
})
.reply(200, dependencyScanningFeedbacks);
testAction(
fetchDependencyScanningDiff,
await testAction(
securityReportsAction.fetchDependencyScanningDiff,
null,
mockedState,
[],
......@@ -1435,13 +1313,12 @@ describe('security reports actions', () => {
type: 'receiveDependencyScanningDiffError',
},
],
done,
);
});
});
describe('when feedback path errors', () => {
it('should dispatch `receiveDependencyScanningError`', (done) => {
it('should dispatch `receiveDependencyScanningError`', async () => {
mock.onGet('dependency_scanning_diff.json').reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1451,8 +1328,8 @@ describe('security reports actions', () => {
})
.reply(500);
testAction(
fetchDependencyScanningDiff,
await testAction(
securityReportsAction.fetchDependencyScanningDiff,
null,
mockedState,
[],
......@@ -1464,18 +1341,17 @@ describe('security reports actions', () => {
type: 'receiveDependencyScanningDiffError',
},
],
done,
);
});
});
});
describe('setDastDiffEndpoint', () => {
it('should pass down the endpoint to the mutation', (done) => {
it('should pass down the endpoint to the mutation', async () => {
const payload = '/dast_endpoint.json';
testAction(
setDastDiffEndpoint,
await testAction(
securityReportsAction.setDastDiffEndpoint,
payload,
mockedState,
[
......@@ -1485,17 +1361,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDastDiffSuccess', () => {
it('should pass down the response to the mutation', (done) => {
it('should pass down the response to the mutation', async () => {
const payload = { data: 'Effort yields its own rewards.' };
testAction(
receiveDastDiffSuccess,
await testAction(
securityReportsAction.receiveDastDiffSuccess,
payload,
mockedState,
[
......@@ -1505,15 +1380,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDastDiffError', () => {
it('should commit dast diff error mutation', (done) => {
testAction(
receiveDastDiffError,
it('should commit dast diff error mutation', async () => {
await testAction(
securityReportsAction.receiveDastDiffError,
undefined,
mockedState,
[
......@@ -1522,7 +1396,6 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
......@@ -1537,7 +1410,7 @@ describe('security reports actions', () => {
});
describe('on success', () => {
it('should dispatch `receiveDastDiffSuccess`', (done) => {
it('should dispatch `receiveDastDiffSuccess`', async () => {
mock.onGet('dast_diff.json').reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1547,8 +1420,8 @@ describe('security reports actions', () => {
})
.reply(200, dastFeedbacks);
testAction(
fetchDastDiff,
await testAction(
securityReportsAction.fetchDastDiff,
null,
mockedState,
[],
......@@ -1564,7 +1437,6 @@ describe('security reports actions', () => {
},
},
],
done,
);
});
});
......@@ -1575,9 +1447,9 @@ describe('security reports actions', () => {
mock.onGet('dast_diff.json').reply(200, diff);
});
it('should dispatch `receiveDastDiffSuccess`', (done) => {
testAction(
fetchDastDiff,
it('should dispatch `receiveDastDiffSuccess`', async () => {
await testAction(
securityReportsAction.fetchDastDiff,
null,
mockedState,
[],
......@@ -1593,13 +1465,12 @@ describe('security reports actions', () => {
},
},
],
done,
);
});
});
describe('when vulnerabilities path errors', () => {
it('should dispatch `receiveDastError`', (done) => {
it('should dispatch `receiveDastError`', async () => {
mock.onGet('dast_diff.json').reply(500);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1609,8 +1480,8 @@ describe('security reports actions', () => {
})
.reply(200, dastFeedbacks);
testAction(
fetchDastDiff,
await testAction(
securityReportsAction.fetchDastDiff,
null,
mockedState,
[],
......@@ -1622,13 +1493,12 @@ describe('security reports actions', () => {
type: 'receiveDastDiffError',
},
],
done,
);
});
});
describe('when feedback path errors', () => {
it('should dispatch `receiveDastError`', (done) => {
it('should dispatch `receiveDastError`', async () => {
mock.onGet('dast_diff.json').reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1638,8 +1508,8 @@ describe('security reports actions', () => {
})
.reply(500);
testAction(
fetchDastDiff,
await testAction(
securityReportsAction.fetchDastDiff,
null,
mockedState,
[],
......@@ -1651,18 +1521,17 @@ describe('security reports actions', () => {
type: 'receiveDastDiffError',
},
],
done,
);
});
});
});
describe('setCoverageFuzzingDiffEndpoint', () => {
it('should pass down the endpoint to the mutation', (done) => {
it('should pass down the endpoint to the mutation', async () => {
const payload = '/coverage_fuzzing_endpoint.json';
testAction(
setCoverageFuzzingDiffEndpoint,
await testAction(
securityReportsAction.setCoverageFuzzingDiffEndpoint,
payload,
mockedState,
[
......@@ -1672,17 +1541,16 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveCoverageFuzzingDiffSuccess', () => {
it('should pass down the response to the mutation', (done) => {
it('should pass down the response to the mutation', async () => {
const payload = { data: 'Effort yields its own rewards.' };
testAction(
receiveCoverageFuzzingDiffSuccess,
await testAction(
securityReportsAction.receiveCoverageFuzzingDiffSuccess,
payload,
mockedState,
[
......@@ -1692,15 +1560,14 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
describe('receiveCoverageFuzzingDiffError', () => {
it('should commit coverage fuzzing diff error mutation', (done) => {
testAction(
receiveCoverageFuzzingDiffError,
it('should commit coverage fuzzing diff error mutation', async () => {
await testAction(
securityReportsAction.receiveCoverageFuzzingDiffError,
undefined,
mockedState,
[
......@@ -1709,7 +1576,6 @@ describe('security reports actions', () => {
},
],
[],
done,
);
});
});
......@@ -1723,7 +1589,7 @@ describe('security reports actions', () => {
});
describe('on success', () => {
it('should dispatch `receiveCoverageFuzzingDiffSuccess`', (done) => {
it('should dispatch `receiveCoverageFuzzingDiffSuccess`', async () => {
mock.onGet('coverage_fuzzing_diff.json').reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1733,8 +1599,8 @@ describe('security reports actions', () => {
})
.reply(200, coverageFuzzingFeedbacks);
testAction(
fetchCoverageFuzzingDiff,
await testAction(
securityReportsAction.fetchCoverageFuzzingDiff,
null,
mockedState,
[],
......@@ -1750,13 +1616,12 @@ describe('security reports actions', () => {
},
},
],
done,
);
});
});
describe('when vulnerabilities path errors', () => {
it('should dispatch `receiveCoverageFuzzingError`', (done) => {
it('should dispatch `receiveCoverageFuzzingError`', async () => {
mock.onGet('coverage_fuzzing_diff.json').reply(500);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1766,8 +1631,8 @@ describe('security reports actions', () => {
})
.reply(200, coverageFuzzingFeedbacks);
testAction(
fetchCoverageFuzzingDiff,
await testAction(
securityReportsAction.fetchCoverageFuzzingDiff,
null,
mockedState,
[],
......@@ -1779,13 +1644,12 @@ describe('security reports actions', () => {
type: 'receiveCoverageFuzzingDiffError',
},
],
done,
);
});
});
describe('when feedback path errors', () => {
it('should dispatch `receiveCoverageFuzzingError`', (done) => {
it('should dispatch `receiveCoverageFuzzingError`', async () => {
mock.onGet('coverage_fuzzing_diff.json').reply(200, diff);
mock
.onGet('vulnerabilities_feedback', {
......@@ -1795,8 +1659,8 @@ describe('security reports actions', () => {
})
.reply(500);
testAction(
fetchCoverageFuzzingDiff,
await testAction(
securityReportsAction.fetchCoverageFuzzingDiff,
null,
mockedState,
[],
......@@ -1808,7 +1672,6 @@ describe('security reports actions', () => {
type: 'receiveCoverageFuzzingDiffError',
},
],
done,
);
});
});
......
......@@ -25,8 +25,8 @@ describe('EE api fuzzing report actions', () => {
});
describe('updateVulnerability', () => {
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, (done) => {
testAction(
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, async () => {
await testAction(
actions.updateVulnerability,
issue,
state,
......@@ -37,14 +37,13 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
describe('setDiffEndpoint', () => {
it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, (done) => {
testAction(
it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, async () => {
await testAction(
actions.setDiffEndpoint,
diffEndpoint,
state,
......@@ -55,20 +54,19 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
describe('requestDiff', () => {
it(`should commit ${types.REQUEST_DIFF}`, (done) => {
testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], [], done);
it(`should commit ${types.REQUEST_DIFF}`, async () => {
await testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], []);
});
});
describe('receiveDiffSuccess', () => {
it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, (done) => {
testAction(
it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, async () => {
await testAction(
actions.receiveDiffSuccess,
reports,
state,
......@@ -79,14 +77,13 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDiffError', () => {
it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, (done) => {
testAction(
it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, async () => {
await testAction(
actions.receiveDiffError,
error,
state,
......@@ -97,7 +94,6 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
......@@ -124,9 +120,9 @@ describe('EE api fuzzing report actions', () => {
.replyOnce(200, reports.enrichData);
});
it('should dispatch the `receiveDiffSuccess` action', (done) => {
it('should dispatch the `receiveDiffSuccess` action', async () => {
const { diff, enrichData } = reports;
testAction(
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
......@@ -141,7 +137,6 @@ describe('EE api fuzzing report actions', () => {
},
},
],
done,
);
});
});
......@@ -152,10 +147,10 @@ describe('EE api fuzzing report actions', () => {
mock.onGet(diffEndpoint).replyOnce(200, reports.diff);
});
it('should dispatch the `receiveDiffSuccess` action with empty enrich data', (done) => {
it('should dispatch the `receiveDiffSuccess` action with empty enrich data', async () => {
const { diff } = reports;
const enrichData = [];
testAction(
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
......@@ -170,7 +165,6 @@ describe('EE api fuzzing report actions', () => {
},
},
],
done,
);
});
});
......@@ -184,14 +178,13 @@ describe('EE api fuzzing report actions', () => {
.replyOnce(404);
});
it('should dispatch the `receiveError` action', (done) => {
testAction(
it('should dispatch the `receiveError` action', async () => {
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
);
});
});
......@@ -205,14 +198,13 @@ describe('EE api fuzzing report actions', () => {
.replyOnce(200, reports.enrichData);
});
it('should dispatch the `receiveDiffError` action', (done) => {
testAction(
it('should dispatch the `receiveDiffError` action', async () => {
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
);
});
});
......
......@@ -14,8 +14,8 @@ describe('EE sast report actions', () => {
});
describe('updateVulnerability', () => {
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, (done) => {
testAction(
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, async () => {
await testAction(
actions.updateVulnerability,
issue,
state,
......@@ -26,7 +26,6 @@ describe('EE sast report actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -14,8 +14,8 @@ describe('EE secret detection report actions', () => {
});
describe('updateVulnerability', () => {
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, (done) => {
testAction(
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, async () => {
await testAction(
actions.updateVulnerability,
issue,
state,
......@@ -26,7 +26,6 @@ describe('EE secret detection report actions', () => {
},
],
[],
done,
);
});
});
......
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