Commit 77e043e2 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Remove jest test callbacks from specs

Jest 27 does not support the test callback anymore so
the following code is no longer valid:

```
it('test', (done) => { /* code */ })
```
parent fc416b60
......@@ -89,11 +89,9 @@ describe('Badge component', () => {
});
describe('behavior', () => {
beforeEach((done) => {
beforeEach(() => {
setFixtures('<div id="dummy-element"></div>');
createComponent({ ...dummyProps }, '#dummy-element')
.then(done)
.catch(done.fail);
return createComponent({ ...dummyProps }, '#dummy-element');
});
it('shows a badge image after loading', () => {
......
This diff is collapsed.
......@@ -29,53 +29,56 @@ describe('Batch comments store actions', () => {
});
describe('addDraftToDiscussion', () => {
it('commits ADD_NEW_DRAFT if no errors returned', (done) => {
it('commits ADD_NEW_DRAFT if no errors returned', () => {
res = { id: 1 };
mock.onAny().reply(200, res);
testAction(
return testAction(
actions.addDraftToDiscussion,
{ endpoint: TEST_HOST, data: 'test' },
null,
[{ type: 'ADD_NEW_DRAFT', payload: res }],
[],
done,
);
});
it('does not commit ADD_NEW_DRAFT if errors returned', (done) => {
it('does not commit ADD_NEW_DRAFT if errors returned', () => {
mock.onAny().reply(500);
testAction(
return testAction(
actions.addDraftToDiscussion,
{ endpoint: TEST_HOST, data: 'test' },
null,
[],
[],
done,
);
});
});
describe('createNewDraft', () => {
it('commits ADD_NEW_DRAFT if no errors returned', (done) => {
it('commits ADD_NEW_DRAFT if no errors returned', () => {
res = { id: 1 };
mock.onAny().reply(200, res);
testAction(
return testAction(
actions.createNewDraft,
{ endpoint: TEST_HOST, data: 'test' },
null,
[{ type: 'ADD_NEW_DRAFT', payload: res }],
[],
done,
);
});
it('does not commit ADD_NEW_DRAFT if errors returned', (done) => {
it('does not commit ADD_NEW_DRAFT if errors returned', () => {
mock.onAny().reply(500);
testAction(actions.createNewDraft, { endpoint: TEST_HOST, data: 'test' }, null, [], [], done);
return testAction(
actions.createNewDraft,
{ endpoint: TEST_HOST, data: 'test' },
null,
[],
[],
);
});
});
......@@ -90,7 +93,7 @@ describe('Batch comments store actions', () => {
};
});
it('commits DELETE_DRAFT if no errors returned', (done) => {
it('commits DELETE_DRAFT if no errors returned', () => {
const commit = jest.fn();
const context = {
getters,
......@@ -99,16 +102,12 @@ describe('Batch comments store actions', () => {
res = { id: 1 };
mock.onAny().reply(200);
actions
.deleteDraft(context, { id: 1 })
.then(() => {
expect(commit).toHaveBeenCalledWith('DELETE_DRAFT', 1);
})
.then(done)
.catch(done.fail);
return actions.deleteDraft(context, { id: 1 }).then(() => {
expect(commit).toHaveBeenCalledWith('DELETE_DRAFT', 1);
});
});
it('does not commit DELETE_DRAFT if errors returned', (done) => {
it('does not commit DELETE_DRAFT if errors returned', () => {
const commit = jest.fn();
const context = {
getters,
......@@ -116,13 +115,9 @@ describe('Batch comments store actions', () => {
};
mock.onAny().reply(500);
actions
.deleteDraft(context, { id: 1 })
.then(() => {
expect(commit).not.toHaveBeenCalledWith('DELETE_DRAFT', 1);
})
.then(done)
.catch(done.fail);
return actions.deleteDraft(context, { id: 1 }).then(() => {
expect(commit).not.toHaveBeenCalledWith('DELETE_DRAFT', 1);
});
});
});
......@@ -137,7 +132,7 @@ describe('Batch comments store actions', () => {
};
});
it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', (done) => {
it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', () => {
const commit = jest.fn();
const dispatch = jest.fn();
const context = {
......@@ -151,14 +146,10 @@ describe('Batch comments store actions', () => {
res = { id: 1 };
mock.onAny().reply(200, res);
actions
.fetchDrafts(context)
.then(() => {
expect(commit).toHaveBeenCalledWith('SET_BATCH_COMMENTS_DRAFTS', { id: 1 });
expect(dispatch).toHaveBeenCalledWith('convertToDiscussion', '1', { root: true });
})
.then(done)
.catch(done.fail);
return actions.fetchDrafts(context).then(() => {
expect(commit).toHaveBeenCalledWith('SET_BATCH_COMMENTS_DRAFTS', { id: 1 });
expect(dispatch).toHaveBeenCalledWith('convertToDiscussion', '1', { root: true });
});
});
});
......@@ -177,32 +168,24 @@ describe('Batch comments store actions', () => {
rootGetters = { discussionsStructuredByLineCode: 'discussions' };
});
it('dispatches actions & commits', (done) => {
it('dispatches actions & commits', () => {
mock.onAny().reply(200);
actions
.publishReview({ dispatch, commit, getters, rootGetters })
.then(() => {
expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.mock.calls[1]).toEqual(['RECEIVE_PUBLISH_REVIEW_SUCCESS']);
return actions.publishReview({ dispatch, commit, getters, rootGetters }).then(() => {
expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.mock.calls[1]).toEqual(['RECEIVE_PUBLISH_REVIEW_SUCCESS']);
expect(dispatch.mock.calls[0]).toEqual(['updateDiscussionsAfterPublish']);
})
.then(done)
.catch(done.fail);
expect(dispatch.mock.calls[0]).toEqual(['updateDiscussionsAfterPublish']);
});
});
it('dispatches error commits', (done) => {
it('dispatches error commits', () => {
mock.onAny().reply(500);
actions
.publishReview({ dispatch, commit, getters, rootGetters })
.then(() => {
expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.mock.calls[1]).toEqual(['RECEIVE_PUBLISH_REVIEW_ERROR']);
})
.then(done)
.catch(done.fail);
return actions.publishReview({ dispatch, commit, getters, rootGetters }).then(() => {
expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.mock.calls[1]).toEqual(['RECEIVE_PUBLISH_REVIEW_ERROR']);
});
});
});
......@@ -262,7 +245,7 @@ describe('Batch comments store actions', () => {
});
describe('expandAllDiscussions', () => {
it('dispatches expandDiscussion for all drafts', (done) => {
it('dispatches expandDiscussion for all drafts', () => {
const state = {
drafts: [
{
......@@ -271,7 +254,7 @@ describe('Batch comments store actions', () => {
],
};
testAction(
return testAction(
actions.expandAllDiscussions,
null,
state,
......@@ -282,7 +265,6 @@ describe('Batch comments store actions', () => {
payload: { discussionId: '1' },
},
],
done,
);
});
});
......
......@@ -166,31 +166,29 @@ describe('setFilters', () => {
});
describe('performSearch', () => {
it('should dispatch setFilters, fetchLists and resetIssues action', (done) => {
testAction(
it('should dispatch setFilters, fetchLists and resetIssues action', () => {
return testAction(
actions.performSearch,
{},
{},
[],
[{ type: 'setFilters', payload: {} }, { type: 'fetchLists' }, { type: 'resetIssues' }],
done,
);
});
});
describe('setActiveId', () => {
it('should commit mutation SET_ACTIVE_ID', (done) => {
it('should commit mutation SET_ACTIVE_ID', () => {
const state = {
activeId: inactiveId,
};
testAction(
return testAction(
actions.setActiveId,
{ id: 1, sidebarType: 'something' },
state,
[{ type: types.SET_ACTIVE_ID, payload: { id: 1, sidebarType: 'something' } }],
[],
done,
);
});
});
......@@ -219,10 +217,10 @@ describe('fetchLists', () => {
const formattedLists = formatBoardLists(queryResponse.data.group.board.lists);
it('should commit mutations RECEIVE_BOARD_LISTS_SUCCESS on success', (done) => {
it('should commit mutations RECEIVE_BOARD_LISTS_SUCCESS on success', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
return testAction(
actions.fetchLists,
{},
state,
......@@ -233,14 +231,13 @@ describe('fetchLists', () => {
},
],
[],
done,
);
});
it('should commit mutations RECEIVE_BOARD_LISTS_FAILURE on failure', (done) => {
it('should commit mutations RECEIVE_BOARD_LISTS_FAILURE on failure', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
testAction(
return testAction(
actions.fetchLists,
{},
state,
......@@ -250,11 +247,10 @@ describe('fetchLists', () => {
},
],
[],
done,
);
});
it('dispatch createList action when backlog list does not exist and is not hidden', (done) => {
it('dispatch createList action when backlog list does not exist and is not hidden', () => {
queryResponse = {
data: {
group: {
......@@ -269,7 +265,7 @@ describe('fetchLists', () => {
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
return testAction(
actions.fetchLists,
{},
state,
......@@ -280,7 +276,6 @@ describe('fetchLists', () => {
},
],
[{ type: 'createList', payload: { backlog: true } }],
done,
);
});
......@@ -951,10 +946,10 @@ describe('fetchItemsForList', () => {
});
});
it('should commit mutations REQUEST_ITEMS_FOR_LIST and RECEIVE_ITEMS_FOR_LIST_SUCCESS on success', (done) => {
it('should commit mutations REQUEST_ITEMS_FOR_LIST and RECEIVE_ITEMS_FOR_LIST_SUCCESS on success', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
return testAction(
actions.fetchItemsForList,
{ listId },
state,
......@@ -973,14 +968,13 @@ describe('fetchItemsForList', () => {
},
],
[],
done,
);
});
it('should commit mutations REQUEST_ITEMS_FOR_LIST and RECEIVE_ITEMS_FOR_LIST_FAILURE on failure', (done) => {
it('should commit mutations REQUEST_ITEMS_FOR_LIST and RECEIVE_ITEMS_FOR_LIST_FAILURE on failure', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
testAction(
return testAction(
actions.fetchItemsForList,
{ listId },
state,
......@@ -996,7 +990,6 @@ describe('fetchItemsForList', () => {
{ type: types.RECEIVE_ITEMS_FOR_LIST_FAILURE, payload: listId },
],
[],
done,
);
});
});
......@@ -1398,8 +1391,8 @@ describe('setAssignees', () => {
const node = { username: 'name' };
describe('when succeeds', () => {
it('calls the correct mutation with the correct values', (done) => {
testAction(
it('calls the correct mutation with the correct values', () => {
return testAction(
actions.setAssignees,
{ assignees: [node], iid: '1' },
{ commit: () => {} },
......@@ -1410,7 +1403,6 @@ describe('setAssignees', () => {
},
],
[],
done,
);
});
});
......@@ -1728,7 +1720,7 @@ describe('setActiveItemSubscribed', () => {
projectPath: 'gitlab-org/gitlab-test',
};
it('should commit subscribed status', (done) => {
it('should commit subscribed status', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
updateIssuableSubscription: {
......@@ -1746,7 +1738,7 @@ describe('setActiveItemSubscribed', () => {
value: subscribedState,
};
testAction(
return testAction(
actions.setActiveItemSubscribed,
input,
{ ...state, ...getters },
......@@ -1757,7 +1749,6 @@ describe('setActiveItemSubscribed', () => {
},
],
[],
done,
);
});
......@@ -1783,7 +1774,7 @@ describe('setActiveItemTitle', () => {
projectPath: 'h/b',
};
it('should commit title after setting the issue', (done) => {
it('should commit title after setting the issue', () => {
jest.spyOn(gqlClient, 'mutate').mockResolvedValue({
data: {
updateIssuableTitle: {
......@@ -1801,7 +1792,7 @@ describe('setActiveItemTitle', () => {
value: testTitle,
};
testAction(
return testAction(
actions.setActiveItemTitle,
input,
{ ...state, ...getters },
......@@ -1812,7 +1803,6 @@ describe('setActiveItemTitle', () => {
},
],
[],
done,
);
});
......@@ -1829,14 +1819,14 @@ describe('setActiveItemConfidential', () => {
const state = { boardItems: { [mockIssue.id]: mockIssue } };
const getters = { activeBoardItem: mockIssue };
it('set confidential value on board item', (done) => {
it('set confidential value on board item', () => {
const payload = {
itemId: getters.activeBoardItem.id,
prop: 'confidential',
value: true,
};
testAction(
return testAction(
actions.setActiveItemConfidential,
true,
{ ...state, ...getters },
......@@ -1847,7 +1837,6 @@ describe('setActiveItemConfidential', () => {
},
],
[],
done,
);
});
});
......@@ -1876,10 +1865,10 @@ describe('fetchGroupProjects', () => {
},
};
it('should commit mutations REQUEST_GROUP_PROJECTS and RECEIVE_GROUP_PROJECTS_SUCCESS on success', (done) => {
it('should commit mutations REQUEST_GROUP_PROJECTS and RECEIVE_GROUP_PROJECTS_SUCCESS on success', () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
return testAction(
actions.fetchGroupProjects,
{},
state,
......@@ -1894,14 +1883,13 @@ describe('fetchGroupProjects', () => {
},
],
[],
done,
);
});
it('should commit mutations REQUEST_GROUP_PROJECTS and RECEIVE_GROUP_PROJECTS_FAILURE on failure', (done) => {
it('should commit mutations REQUEST_GROUP_PROJECTS and RECEIVE_GROUP_PROJECTS_FAILURE on failure', () => {
jest.spyOn(gqlClient, 'query').mockRejectedValue();
testAction(
return testAction(
actions.fetchGroupProjects,
{},
state,
......@@ -1915,16 +1903,15 @@ describe('fetchGroupProjects', () => {
},
],
[],
done,
);
});
});
describe('setSelectedProject', () => {
it('should commit mutation SET_SELECTED_PROJECT', (done) => {
it('should commit mutation SET_SELECTED_PROJECT', () => {
const project = mockGroupProjects[0];
testAction(
return testAction(
actions.setSelectedProject,
project,
{},
......@@ -1935,7 +1922,6 @@ describe('setSelectedProject', () => {
},
],
[],
done,
);
});
});
......
......@@ -95,70 +95,82 @@ describe('apolloCaptchaLink', () => {
return { operationName: 'operation', variables: {}, setContext: mockContext };
}
it('successful responses are passed through', (done) => {
it('successful responses are passed through', () => {
setupLink(SUCCESS_RESPONSE);
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(SUCCESS_RESPONSE);
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
expect(waitForCaptchaToBeSolved).not.toHaveBeenCalled();
done();
return new Promise((resolve) => {
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(SUCCESS_RESPONSE);
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
expect(waitForCaptchaToBeSolved).not.toHaveBeenCalled();
resolve();
});
});
});
it('non-spam related errors are passed through', (done) => {
it('non-spam related errors are passed through', () => {
setupLink(NON_CAPTCHA_ERROR_RESPONSE);
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(NON_CAPTCHA_ERROR_RESPONSE);
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
expect(mockContext).not.toHaveBeenCalled();
expect(waitForCaptchaToBeSolved).not.toHaveBeenCalled();
done();
return new Promise((resolve) => {
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(NON_CAPTCHA_ERROR_RESPONSE);
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
expect(mockContext).not.toHaveBeenCalled();
expect(waitForCaptchaToBeSolved).not.toHaveBeenCalled();
resolve();
});
});
});
it('unresolvable spam errors are passed through', (done) => {
it('unresolvable spam errors are passed through', () => {
setupLink(SPAM_ERROR_RESPONSE);
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(SPAM_ERROR_RESPONSE);
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
expect(mockContext).not.toHaveBeenCalled();
expect(waitForCaptchaToBeSolved).not.toHaveBeenCalled();
done();
return new Promise((resolve) => {
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(SPAM_ERROR_RESPONSE);
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
expect(mockContext).not.toHaveBeenCalled();
expect(waitForCaptchaToBeSolved).not.toHaveBeenCalled();
resolve();
});
});
});
describe('resolvable spam errors', () => {
it('re-submits request with spam headers if the captcha modal was solved correctly', (done) => {
it('re-submits request with spam headers if the captcha modal was solved correctly', () => {
waitForCaptchaToBeSolved.mockResolvedValue(CAPTCHA_RESPONSE);
setupLink(CAPTCHA_ERROR_RESPONSE, SUCCESS_RESPONSE);
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(SUCCESS_RESPONSE);
expect(waitForCaptchaToBeSolved).toHaveBeenCalledWith(CAPTCHA_SITE_KEY);
expect(mockContext).toHaveBeenCalledWith({
headers: {
'X-GitLab-Captcha-Response': CAPTCHA_RESPONSE,
'X-GitLab-Spam-Log-Id': SPAM_LOG_ID,
},
return new Promise((resolve) => {
link.request(mockOperation()).subscribe((result) => {
expect(result).toEqual(SUCCESS_RESPONSE);
expect(waitForCaptchaToBeSolved).toHaveBeenCalledWith(CAPTCHA_SITE_KEY);
expect(mockContext).toHaveBeenCalledWith({
headers: {
'X-GitLab-Captcha-Response': CAPTCHA_RESPONSE,
'X-GitLab-Spam-Log-Id': SPAM_LOG_ID,
},
});
expect(mockLinkImplementation).toHaveBeenCalledTimes(2);
resolve();
});
expect(mockLinkImplementation).toHaveBeenCalledTimes(2);
done();
});
});
it('throws error if the captcha modal was not solved correctly', (done) => {
it('throws error if the captcha modal was not solved correctly', () => {
const error = new UnsolvedCaptchaError();
waitForCaptchaToBeSolved.mockRejectedValue(error);
setupLink(CAPTCHA_ERROR_RESPONSE, SUCCESS_RESPONSE);
link.request(mockOperation()).subscribe({
next: done.catch,
error: (result) => {
expect(result).toEqual(error);
expect(waitForCaptchaToBeSolved).toHaveBeenCalledWith(CAPTCHA_SITE_KEY);
expect(mockContext).not.toHaveBeenCalled();
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
done();
},
return new Promise((resolve, reject) => {
link.request(mockOperation()).subscribe({
next: reject,
error: (result) => {
expect(result).toEqual(error);
expect(waitForCaptchaToBeSolved).toHaveBeenCalledWith(CAPTCHA_SITE_KEY);
expect(mockContext).not.toHaveBeenCalled();
expect(mockLinkImplementation).toHaveBeenCalledTimes(1);
resolve();
},
});
});
});
});
......
......@@ -86,10 +86,10 @@ describe('CI variable list store actions', () => {
});
describe('deleteVariable', () => {
it('dispatch correct actions on successful deleted variable', (done) => {
it('dispatch correct actions on successful deleted variable', () => {
mock.onPatch(state.endpoint).reply(200);
testAction(
return testAction(
actions.deleteVariable,
{},
state,
......@@ -99,16 +99,13 @@ describe('CI variable list store actions', () => {
{ type: 'receiveDeleteVariableSuccess' },
{ type: 'fetchVariables' },
],
() => {
done();
},
);
});
it('should show flash error and set error in state on delete failure', (done) => {
it('should show flash error and set error in state on delete failure', async () => {
mock.onPatch(state.endpoint).reply(500, '');
testAction(
await testAction(
actions.deleteVariable,
{},
state,
......@@ -120,19 +117,16 @@ describe('CI variable list store actions', () => {
payload: payloadError,
},
],
() => {
expect(createFlash).toHaveBeenCalled();
done();
},
);
expect(createFlash).toHaveBeenCalled();
});
});
describe('updateVariable', () => {
it('dispatch correct actions on successful updated variable', (done) => {
it('dispatch correct actions on successful updated variable', () => {
mock.onPatch(state.endpoint).reply(200);
testAction(
return testAction(
actions.updateVariable,
{},
state,
......@@ -142,16 +136,13 @@ describe('CI variable list store actions', () => {
{ type: 'receiveUpdateVariableSuccess' },
{ type: 'fetchVariables' },
],
() => {
done();
},
);
});
it('should show flash error and set error in state on update failure', (done) => {
it('should show flash error and set error in state on update failure', async () => {
mock.onPatch(state.endpoint).reply(500, '');
testAction(
await testAction(
actions.updateVariable,
mockVariable,
state,
......@@ -163,19 +154,16 @@ describe('CI variable list store actions', () => {
payload: payloadError,
},
],
() => {
expect(createFlash).toHaveBeenCalled();
done();
},
);
expect(createFlash).toHaveBeenCalled();
});
});
describe('addVariable', () => {
it('dispatch correct actions on successful added variable', (done) => {
it('dispatch correct actions on successful added variable', () => {
mock.onPatch(state.endpoint).reply(200);
testAction(
return testAction(
actions.addVariable,
{},
state,
......@@ -185,16 +173,13 @@ describe('CI variable list store actions', () => {
{ type: 'receiveAddVariableSuccess' },
{ type: 'fetchVariables' },
],
() => {
done();
},
);
});
it('should show flash error and set error in state on add failure', (done) => {
it('should show flash error and set error in state on add failure', async () => {
mock.onPatch(state.endpoint).reply(500, '');
testAction(
await testAction(
actions.addVariable,
{},
state,
......@@ -206,19 +191,16 @@ describe('CI variable list store actions', () => {
payload: payloadError,
},
],
() => {
expect(createFlash).toHaveBeenCalled();
done();
},
);
expect(createFlash).toHaveBeenCalled();
});
});
describe('fetchVariables', () => {
it('dispatch correct actions on fetchVariables', (done) => {
it('dispatch correct actions on fetchVariables', () => {
mock.onGet(state.endpoint).reply(200, { variables: mockData.mockVariables });
testAction(
return testAction(
actions.fetchVariables,
{},
state,
......@@ -230,29 +212,24 @@ describe('CI variable list store actions', () => {
payload: prepareDataForDisplay(mockData.mockVariables),
},
],
() => {
done();
},
);
});
it('should show flash error and set error in state on fetch variables failure', (done) => {
it('should show flash error and set error in state on fetch variables failure', async () => {
mock.onGet(state.endpoint).reply(500);
testAction(actions.fetchVariables, {}, state, [], [{ type: 'requestVariables' }], () => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the variables.',
});
done();
await testAction(actions.fetchVariables, {}, state, [], [{ type: 'requestVariables' }]);
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the variables.',
});
});
});
describe('fetchEnvironments', () => {
it('dispatch correct actions on fetchEnvironments', (done) => {
it('dispatch correct actions on fetchEnvironments', () => {
Api.environments = jest.fn().mockResolvedValue({ data: mockData.mockEnvironments });
testAction(
return testAction(
actions.fetchEnvironments,
{},
state,
......@@ -264,28 +241,17 @@ describe('CI variable list store actions', () => {
payload: prepareEnvironments(mockData.mockEnvironments),
},
],
() => {
done();
},
);
});
it('should show flash error and set error in state on fetch environments failure', (done) => {
it('should show flash error and set error in state on fetch environments failure', async () => {
Api.environments = jest.fn().mockRejectedValue();
testAction(
actions.fetchEnvironments,
{},
state,
[],
[{ type: 'requestEnvironments' }],
() => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the environments information.',
});
done();
},
);
await testAction(actions.fetchEnvironments, {}, state, [], [{ type: 'requestEnvironments' }]);
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the environments information.',
});
});
});
......
......@@ -24,14 +24,12 @@ describe('Clusters store actions', () => {
captureException.mockRestore();
});
it('should report sentry error', (done) => {
it('should report sentry error', async () => {
const sentryError = new Error('New Sentry Error');
const tag = 'sentryErrorTag';
testAction(actions.reportSentryError, { error: sentryError, tag }, {}, [], [], () => {
expect(captureException).toHaveBeenCalledWith(sentryError);
done();
});
await testAction(actions.reportSentryError, { error: sentryError, tag }, {}, [], []);
expect(captureException).toHaveBeenCalledWith(sentryError);
});
});
......@@ -62,10 +60,10 @@ describe('Clusters store actions', () => {
afterEach(() => mock.restore());
it('should commit SET_CLUSTERS_DATA with received response', (done) => {
it('should commit SET_CLUSTERS_DATA with received response', () => {
mock.onGet().reply(200, apiData, headers);
testAction(
return testAction(
actions.fetchClusters,
{ endpoint: apiData.endpoint },
{},
......@@ -75,14 +73,13 @@ describe('Clusters store actions', () => {
{ type: types.SET_LOADING_CLUSTERS, payload: false },
],
[],
() => done(),
);
});
it('should show flash on API error', (done) => {
it('should show flash on API error', async () => {
mock.onGet().reply(400, 'Not Found');
testAction(
await testAction(
actions.fetchClusters,
{ endpoint: apiData.endpoint },
{},
......@@ -100,13 +97,10 @@ describe('Clusters store actions', () => {
},
},
],
() => {
expect(createFlash).toHaveBeenCalledWith({
message: expect.stringMatching('error'),
});
done();
},
);
expect(createFlash).toHaveBeenCalledWith({
message: expect.stringMatching('error'),
});
});
describe('multiple api requests', () => {
......@@ -128,8 +122,8 @@ describe('Clusters store actions', () => {
pollStop.mockRestore();
});
it('should stop polling after MAX Requests', (done) => {
testAction(
it('should stop polling after MAX Requests', async () => {
await testAction(
actions.fetchClusters,
{ endpoint: apiData.endpoint },
{},
......@@ -139,47 +133,43 @@ describe('Clusters store actions', () => {
{ type: types.SET_LOADING_CLUSTERS, payload: false },
],
[],
() => {
expect(pollRequest).toHaveBeenCalledTimes(1);
);
expect(pollRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(pollInterval);
return waitForPromises()
.then(() => {
expect(pollRequest).toHaveBeenCalledTimes(2);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(pollInterval);
waitForPromises()
.then(() => {
expect(pollRequest).toHaveBeenCalledTimes(2);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(pollInterval);
})
.then(() => waitForPromises())
.then(() => {
expect(pollRequest).toHaveBeenCalledTimes(MAX_REQUESTS);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(pollInterval);
})
.then(() => waitForPromises())
.then(() => {
expect(pollRequest).toHaveBeenCalledTimes(MAX_REQUESTS + 1);
// Stops poll once it exceeds the MAX_REQUESTS limit
expect(pollStop).toHaveBeenCalledTimes(1);
jest.advanceTimersByTime(pollInterval);
})
.then(() => waitForPromises())
.then(() => {
// Additional poll requests are not made once pollStop is called
expect(pollRequest).toHaveBeenCalledTimes(MAX_REQUESTS + 1);
expect(pollStop).toHaveBeenCalledTimes(1);
})
.then(done)
.catch(done.fail);
},
);
})
.then(() => waitForPromises())
.then(() => {
expect(pollRequest).toHaveBeenCalledTimes(MAX_REQUESTS);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(pollInterval);
})
.then(() => waitForPromises())
.then(() => {
expect(pollRequest).toHaveBeenCalledTimes(MAX_REQUESTS + 1);
// Stops poll once it exceeds the MAX_REQUESTS limit
expect(pollStop).toHaveBeenCalledTimes(1);
jest.advanceTimersByTime(pollInterval);
})
.then(() => waitForPromises())
.then(() => {
// Additional poll requests are not made once pollStop is called
expect(pollRequest).toHaveBeenCalledTimes(MAX_REQUESTS + 1);
expect(pollStop).toHaveBeenCalledTimes(1);
});
});
it('should stop polling and report to Sentry when data is invalid', (done) => {
it('should stop polling and report to Sentry when data is invalid', async () => {
const badApiResponse = { clusters: {} };
mock.onGet().reply(200, badApiResponse, pollHeaders);
testAction(
await testAction(
actions.fetchClusters,
{ endpoint: apiData.endpoint },
{},
......@@ -202,12 +192,9 @@ describe('Clusters store actions', () => {
},
},
],
() => {
expect(pollRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(1);
done();
},
);
expect(pollRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(1);
});
});
});
......
......@@ -10,14 +10,13 @@ describe('Code navigation actions', () => {
const wrapTextNodes = true;
describe('setInitialData', () => {
it('commits SET_INITIAL_DATA', (done) => {
testAction(
it('commits SET_INITIAL_DATA', () => {
return testAction(
actions.setInitialData,
{ projectPath: 'test', wrapTextNodes },
{},
[{ type: 'SET_INITIAL_DATA', payload: { projectPath: 'test', wrapTextNodes } }],
[],
done,
);
});
});
......@@ -59,8 +58,8 @@ describe('Code navigation actions', () => {
]);
});
it('commits REQUEST_DATA_SUCCESS with normalized data', (done) => {
testAction(
it('commits REQUEST_DATA_SUCCESS with normalized data', () => {
return testAction(
actions.fetchData,
null,
state,
......@@ -82,12 +81,11 @@ describe('Code navigation actions', () => {
},
],
[],
done,
);
});
it('calls addInteractionClass with data', (done) => {
testAction(
it('calls addInteractionClass with data', () => {
return testAction(
actions.fetchData,
null,
state,
......@@ -120,9 +118,7 @@ describe('Code navigation actions', () => {
},
wrapTextNodes,
});
})
.then(done)
.catch(done.fail);
});
});
});
......@@ -131,14 +127,13 @@ describe('Code navigation actions', () => {
mock.onGet(codeNavigationPath).replyOnce(500);
});
it('dispatches requestDataError', (done) => {
testAction(
it('dispatches requestDataError', () => {
return testAction(
actions.fetchData,
null,
state,
[{ type: 'REQUEST_DATA' }],
[{ type: 'requestDataError' }],
done,
);
});
});
......@@ -186,20 +181,20 @@ describe('Code navigation actions', () => {
target = document.querySelector('.js-test');
});
it('returns early when no data exists', (done) => {
testAction(actions.showDefinition, { target }, {}, [], [], done);
it('returns early when no data exists', () => {
return testAction(actions.showDefinition, { target }, {}, [], []);
});
it('commits SET_CURRENT_DEFINITION when target is not code navitation element', (done) => {
testAction(actions.showDefinition, { target }, { data: {} }, [], [], done);
it('commits SET_CURRENT_DEFINITION when target is not code navitation element', () => {
return testAction(actions.showDefinition, { target }, { data: {} }, [], []);
});
it('commits SET_CURRENT_DEFINITION with LSIF data', (done) => {
it('commits SET_CURRENT_DEFINITION with LSIF data', () => {
target.classList.add('js-code-navigation');
target.setAttribute('data-line-index', '0');
target.setAttribute('data-char-index', '0');
testAction(
return testAction(
actions.showDefinition,
{ target },
{ data: { 'index.js': { '0:0': { hover: 'test' } } } },
......@@ -214,7 +209,6 @@ describe('Code navigation actions', () => {
},
],
[],
done,
);
});
......
......@@ -120,18 +120,20 @@ describe('Pipelines table in Commits and Merge requests', () => {
});
describe('pipeline badge counts', () => {
it('should receive update-pipelines-count event', (done) => {
it('should receive update-pipelines-count event', () => {
const element = document.createElement('div');
document.body.appendChild(element);
element.addEventListener('update-pipelines-count', (event) => {
expect(event.detail.pipelineCount).toEqual(10);
done();
});
return new Promise((resolve) => {
element.addEventListener('update-pipelines-count', (event) => {
expect(event.detail.pipelineCount).toEqual(10);
resolve();
});
createComponent();
createComponent();
element.appendChild(wrapper.vm.$el);
element.appendChild(wrapper.vm.$el);
});
});
});
});
......
......@@ -200,13 +200,17 @@ describe('content_editor/extensions/attachment', () => {
});
});
it('emits an alert event that includes an error message', (done) => {
it('emits an alert event that includes an error message', () => {
tiptapEditor.commands.uploadAttachment({ file });
eventHub.$on('alert', ({ message, variant }) => {
expect(variant).toBe(VARIANT_DANGER);
expect(message).toBe('An error occurred while uploading the file. Please try again.');
done();
return new Promise((resolve) => {
eventHub.$on('alert', ({ message, variant }) => {
expect(variant).toBe(VARIANT_DANGER);
expect(message).toBe(
'An error occurred while uploading the file. Please try again.',
);
resolve();
});
});
});
});
......@@ -277,13 +281,12 @@ describe('content_editor/extensions/attachment', () => {
});
});
it('emits an alert event that includes an error message', (done) => {
it('emits an alert event that includes an error message', () => {
tiptapEditor.commands.uploadAttachment({ file: attachmentFile });
eventHub.$on('alert', ({ message, variant }) => {
expect(variant).toBe(VARIANT_DANGER);
expect(message).toBe('An error occurred while uploading the file. Please try again.');
done();
});
});
});
......
......@@ -17,10 +17,14 @@ describe('Contributors store actions', () => {
mock = new MockAdapter(axios);
});
it('should commit SET_CHART_DATA with received response', (done) => {
afterEach(() => {
mock.restore();
});
it('should commit SET_CHART_DATA with received response', () => {
mock.onGet().reply(200, chartData);
testAction(
return testAction(
actions.fetchChartData,
{ endpoint },
{},
......@@ -30,30 +34,22 @@ describe('Contributors store actions', () => {
{ type: types.SET_LOADING_STATE, payload: false },
],
[],
() => {
mock.restore();
done();
},
);
});
it('should show flash on API error', (done) => {
it('should show flash on API error', async () => {
mock.onGet().reply(400, 'Not Found');
testAction(
await testAction(
actions.fetchChartData,
{ endpoint },
{},
[{ type: types.SET_LOADING_STATE, payload: true }],
[],
() => {
expect(createFlash).toHaveBeenCalledWith({
message: expect.stringMatching('error'),
});
mock.restore();
done();
},
);
expect(createFlash).toHaveBeenCalledWith({
message: expect.stringMatching('error'),
});
});
});
});
......@@ -14,53 +14,49 @@ import {
describe('GCP Cluster Dropdown Store Actions', () => {
describe('setProject', () => {
it('should set project', (done) => {
testAction(
it('should set project', () => {
return testAction(
actions.setProject,
selectedProjectMock,
{ selectedProject: {} },
[{ type: 'SET_PROJECT', payload: selectedProjectMock }],
[],
done,
);
});
});
describe('setZone', () => {
it('should set zone', (done) => {
testAction(
it('should set zone', () => {
return testAction(
actions.setZone,
selectedZoneMock,
{ selectedZone: '' },
[{ type: 'SET_ZONE', payload: selectedZoneMock }],
[],
done,
);
});
});
describe('setMachineType', () => {
it('should set machine type', (done) => {
testAction(
it('should set machine type', () => {
return testAction(
actions.setMachineType,
selectedMachineTypeMock,
{ selectedMachineType: '' },
[{ type: 'SET_MACHINE_TYPE', payload: selectedMachineTypeMock }],
[],
done,
);
});
});
describe('setIsValidatingProjectBilling', () => {
it('should set machine type', (done) => {
testAction(
it('should set machine type', () => {
return testAction(
actions.setIsValidatingProjectBilling,
true,
{ isValidatingProjectBilling: null },
[{ type: 'SET_IS_VALIDATING_PROJECT_BILLING', payload: true }],
[],
done,
);
});
});
......@@ -94,8 +90,8 @@ describe('GCP Cluster Dropdown Store Actions', () => {
});
describe('validateProjectBilling', () => {
it('checks project billing status from Google API', (done) => {
testAction(
it('checks project billing status from Google API', () => {
return testAction(
actions.validateProjectBilling,
true,
{
......@@ -110,7 +106,6 @@ describe('GCP Cluster Dropdown Store Actions', () => {
{ type: 'SET_PROJECT_BILLING_STATUS', payload: true },
],
[{ type: 'setIsValidatingProjectBilling', payload: false }],
done,
);
});
});
......
......@@ -98,7 +98,7 @@ describe('DiffLineNoteForm', () => {
});
describe('saveNoteForm', () => {
it('should call saveNote action with proper params', (done) => {
it('should call saveNote action with proper params', async () => {
const saveDiffDiscussionSpy = jest
.spyOn(wrapper.vm, 'saveDiffDiscussion')
.mockReturnValue(Promise.resolve());
......@@ -123,16 +123,11 @@ describe('DiffLineNoteForm', () => {
lineRange,
};
wrapper.vm
.handleSaveNote('note body')
.then(() => {
expect(saveDiffDiscussionSpy).toHaveBeenCalledWith({
note: 'note body',
formData,
});
})
.then(done)
.catch(done.fail);
await wrapper.vm.handleSaveNote('note body');
expect(saveDiffDiscussionSpy).toHaveBeenCalledWith({
note: 'note body',
formData,
});
});
});
});
......
This diff is collapsed.
......@@ -23,9 +23,9 @@ describe('Deploy Board', () => {
});
describe('with valid data', () => {
beforeEach((done) => {
beforeEach(() => {
wrapper = createComponent();
nextTick(done);
return nextTick();
});
it('should render percentage with completion value provided', () => {
......@@ -127,14 +127,14 @@ describe('Deploy Board', () => {
});
describe('with empty state', () => {
beforeEach((done) => {
beforeEach(() => {
wrapper = createComponent({
deployBoardData: {},
isLoading: false,
isEmpty: true,
logsPath,
});
nextTick(done);
return nextTick();
});
it('should render the empty state', () => {
......@@ -146,14 +146,14 @@ describe('Deploy Board', () => {
});
describe('with loading state', () => {
beforeEach((done) => {
beforeEach(() => {
wrapper = createComponent({
deployBoardData: {},
isLoading: true,
isEmpty: false,
logsPath,
});
nextTick(done);
return nextTick();
});
it('should render loading spinner', () => {
......@@ -163,7 +163,7 @@ describe('Deploy Board', () => {
describe('has legend component', () => {
let statuses = [];
beforeEach((done) => {
beforeEach(() => {
wrapper = createComponent({
isLoading: false,
isEmpty: false,
......@@ -171,7 +171,7 @@ describe('Deploy Board', () => {
deployBoardData: deployBoardMockData,
});
({ statuses } = wrapper.vm);
nextTick(done);
return nextTick();
});
it('with all the possible statuses', () => {
......
......@@ -122,7 +122,7 @@ describe('Environment table', () => {
expect(wrapper.find('.deploy-board-icon').exists()).toBe(true);
});
it('should toggle deploy board visibility when arrow is clicked', (done) => {
it('should toggle deploy board visibility when arrow is clicked', async () => {
const mockItem = {
name: 'review',
size: 1,
......@@ -142,7 +142,6 @@ describe('Environment table', () => {
eventHub.$on('toggleDeployBoard', (env) => {
expect(env.id).toEqual(mockItem.id);
done();
});
factory({
......@@ -154,7 +153,7 @@ describe('Environment table', () => {
},
});
wrapper.find('.deploy-board-icon').trigger('click');
await wrapper.find('.deploy-board-icon').trigger('click');
});
it('should set the environment to change and weight when a change canary weight event is recevied', async () => {
......
......@@ -28,9 +28,9 @@ describe('Sentry common store actions', () => {
const params = { endpoint, redirectUrl, status };
describe('updateStatus', () => {
it('should handle successful status update', (done) => {
it('should handle successful status update', async () => {
mock.onPut().reply(200, {});
testAction(
await testAction(
actions.updateStatus,
params,
{},
......@@ -41,20 +41,15 @@ describe('Sentry common store actions', () => {
},
],
[],
() => {
done();
expect(visitUrl).toHaveBeenCalledWith(redirectUrl);
},
);
expect(visitUrl).toHaveBeenCalledWith(redirectUrl);
});
it('should handle unsuccessful status update', (done) => {
it('should handle unsuccessful status update', async () => {
mock.onPut().reply(400, {});
testAction(actions.updateStatus, params, {}, [], [], () => {
expect(visitUrl).not.toHaveBeenCalled();
expect(createFlash).toHaveBeenCalledTimes(1);
done();
});
await testAction(actions.updateStatus, params, {}, [], []);
expect(visitUrl).not.toHaveBeenCalled();
expect(createFlash).toHaveBeenCalledTimes(1);
});
});
......
......@@ -28,10 +28,10 @@ describe('Sentry error details store actions', () => {
describe('startPollingStacktrace', () => {
const endpoint = '123/stacktrace';
it('should commit SET_ERROR with received response', (done) => {
it('should commit SET_ERROR with received response', () => {
const payload = { error: [1, 2, 3] };
mockedAdapter.onGet().reply(200, payload);
testAction(
return testAction(
actions.startPollingStacktrace,
{ endpoint },
{},
......@@ -40,37 +40,29 @@ describe('Sentry error details store actions', () => {
{ type: types.SET_LOADING_STACKTRACE, payload: false },
],
[],
() => {
done();
},
);
});
it('should show flash on API error', (done) => {
it('should show flash on API error', async () => {
mockedAdapter.onGet().reply(400);
testAction(
await testAction(
actions.startPollingStacktrace,
{ endpoint },
{},
[{ type: types.SET_LOADING_STACKTRACE, payload: false }],
[],
() => {
expect(createFlash).toHaveBeenCalledTimes(1);
done();
},
);
expect(createFlash).toHaveBeenCalledTimes(1);
});
it('should not restart polling when receiving an empty 204 response', (done) => {
it('should not restart polling when receiving an empty 204 response', async () => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
mockedAdapter.onGet().reply(204);
testAction(actions.startPollingStacktrace, { endpoint }, {}, [], [], () => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
expect(mockedRestart).toHaveBeenCalledTimes(0);
done();
});
await testAction(actions.startPollingStacktrace, { endpoint }, {}, [], []);
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
expect(mockedRestart).toHaveBeenCalledTimes(0);
});
});
});
......@@ -20,11 +20,11 @@ describe('error tracking actions', () => {
});
describe('startPolling', () => {
it('should start polling for data', (done) => {
it('should start polling for data', () => {
const payload = { errors: [{ id: 1 }, { id: 2 }] };
mock.onGet().reply(httpStatusCodes.OK, payload);
testAction(
return testAction(
actions.startPolling,
{},
{},
......@@ -35,16 +35,13 @@ describe('error tracking actions', () => {
{ type: types.SET_LOADING, payload: false },
],
[{ type: 'stopPolling' }],
() => {
done();
},
);
});
it('should show flash on API error', (done) => {
it('should show flash on API error', async () => {
mock.onGet().reply(httpStatusCodes.BAD_REQUEST);
testAction(
await testAction(
actions.startPolling,
{},
{},
......@@ -53,11 +50,8 @@ describe('error tracking actions', () => {
{ type: types.SET_LOADING, payload: false },
],
[],
() => {
expect(createFlash).toHaveBeenCalledTimes(1);
done();
},
);
expect(createFlash).toHaveBeenCalledTimes(1);
});
});
......
......@@ -27,9 +27,9 @@ describe('error tracking settings actions', () => {
refreshCurrentPage.mockClear();
});
it('should request and transform the project list', (done) => {
it('should request and transform the project list', async () => {
mock.onGet(TEST_HOST).reply(() => [200, { projects: projectList }]);
testAction(
await testAction(
actions.fetchProjects,
null,
state,
......@@ -41,16 +41,13 @@ describe('error tracking settings actions', () => {
payload: projectList.map(convertObjectPropsToCamelCase),
},
],
() => {
expect(mock.history.get.length).toBe(1);
done();
},
);
expect(mock.history.get.length).toBe(1);
});
it('should handle a server error', (done) => {
it('should handle a server error', async () => {
mock.onGet(`${TEST_HOST}.json`).reply(() => [400]);
testAction(
await testAction(
actions.fetchProjects,
null,
state,
......@@ -61,27 +58,23 @@ describe('error tracking settings actions', () => {
type: 'receiveProjectsError',
},
],
() => {
expect(mock.history.get.length).toBe(1);
done();
},
);
expect(mock.history.get.length).toBe(1);
});
it('should request projects correctly', (done) => {
testAction(
it('should request projects correctly', () => {
return testAction(
actions.requestProjects,
null,
state,
[{ type: types.SET_PROJECTS_LOADING, payload: true }, { type: types.RESET_CONNECT }],
[],
done,
);
});
it('should receive projects correctly', (done) => {
it('should receive projects correctly', () => {
const testPayload = [];
testAction(
return testAction(
actions.receiveProjectsSuccess,
testPayload,
state,
......@@ -91,13 +84,12 @@ describe('error tracking settings actions', () => {
{ type: types.SET_PROJECTS_LOADING, payload: false },
],
[],
done,
);
});
it('should handle errors when receiving projects', (done) => {
it('should handle errors when receiving projects', () => {
const testPayload = [];
testAction(
return testAction(
actions.receiveProjectsError,
testPayload,
state,
......@@ -107,7 +99,6 @@ describe('error tracking settings actions', () => {
{ type: types.SET_PROJECTS_LOADING, payload: false },
],
[],
done,
);
});
});
......@@ -126,18 +117,16 @@ describe('error tracking settings actions', () => {
mock.restore();
});
it('should save the page', (done) => {
it('should save the page', async () => {
mock.onPatch(TEST_HOST).reply(200);
testAction(actions.updateSettings, null, state, [], [{ type: 'requestSettings' }], () => {
expect(mock.history.patch.length).toBe(1);
expect(refreshCurrentPage).toHaveBeenCalled();
done();
});
await testAction(actions.updateSettings, null, state, [], [{ type: 'requestSettings' }]);
expect(mock.history.patch.length).toBe(1);
expect(refreshCurrentPage).toHaveBeenCalled();
});
it('should handle a server error', (done) => {
it('should handle a server error', async () => {
mock.onPatch(TEST_HOST).reply(400);
testAction(
await testAction(
actions.updateSettings,
null,
state,
......@@ -149,57 +138,50 @@ describe('error tracking settings actions', () => {
payload: new Error('Request failed with status code 400'),
},
],
() => {
expect(mock.history.patch.length).toBe(1);
done();
},
);
expect(mock.history.patch.length).toBe(1);
});
it('should request to save the page', (done) => {
testAction(
it('should request to save the page', () => {
return testAction(
actions.requestSettings,
null,
state,
[{ type: types.UPDATE_SETTINGS_LOADING, payload: true }],
[],
done,
);
});
it('should handle errors when requesting to save the page', (done) => {
testAction(
it('should handle errors when requesting to save the page', () => {
return testAction(
actions.receiveSettingsError,
{},
state,
[{ type: types.UPDATE_SETTINGS_LOADING, payload: false }],
[],
done,
);
});
});
describe('generic actions to update the store', () => {
const testData = 'test';
it('should reset the `connect success` flag when updating the api host', (done) => {
testAction(
it('should reset the `connect success` flag when updating the api host', () => {
return testAction(
actions.updateApiHost,
testData,
state,
[{ type: types.UPDATE_API_HOST, payload: testData }, { type: types.RESET_CONNECT }],
[],
done,
);
});
it('should reset the `connect success` flag when updating the token', (done) => {
testAction(
it('should reset the `connect success` flag when updating the token', () => {
return testAction(
actions.updateToken,
testData,
state,
[{ type: types.UPDATE_TOKEN, payload: testData }, { type: types.RESET_CONNECT }],
[],
done,
);
});
......
......@@ -40,7 +40,7 @@ describe('Feature flags Edit Module actions', () => {
});
describe('success', () => {
it('dispatches requestUpdateFeatureFlag and receiveUpdateFeatureFlagSuccess ', (done) => {
it('dispatches requestUpdateFeatureFlag and receiveUpdateFeatureFlagSuccess ', () => {
const featureFlag = {
name: 'name',
description: 'description',
......@@ -57,7 +57,7 @@ describe('Feature flags Edit Module actions', () => {
};
mock.onPut(mockedState.endpoint, mapStrategiesToRails(featureFlag)).replyOnce(200);
testAction(
return testAction(
updateFeatureFlag,
featureFlag,
mockedState,
......@@ -70,16 +70,15 @@ describe('Feature flags Edit Module actions', () => {
type: 'receiveUpdateFeatureFlagSuccess',
},
],
done,
);
});
});
describe('error', () => {
it('dispatches requestUpdateFeatureFlag and receiveUpdateFeatureFlagError ', (done) => {
it('dispatches requestUpdateFeatureFlag and receiveUpdateFeatureFlagError ', () => {
mock.onPut(`${TEST_HOST}/endpoint.json`).replyOnce(500, { message: [] });
testAction(
return testAction(
updateFeatureFlag,
{
name: 'feature_flag',
......@@ -97,28 +96,26 @@ describe('Feature flags Edit Module actions', () => {
payload: { message: [] },
},
],
done,
);
});
});
});
describe('requestUpdateFeatureFlag', () => {
it('should commit REQUEST_UPDATE_FEATURE_FLAG mutation', (done) => {
testAction(
it('should commit REQUEST_UPDATE_FEATURE_FLAG mutation', () => {
return testAction(
requestUpdateFeatureFlag,
null,
mockedState,
[{ type: types.REQUEST_UPDATE_FEATURE_FLAG }],
[],
done,
);
});
});
describe('receiveUpdateFeatureFlagSuccess', () => {
it('should commit RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS mutation', (done) => {
testAction(
it('should commit RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS mutation', () => {
return testAction(
receiveUpdateFeatureFlagSuccess,
null,
mockedState,
......@@ -128,20 +125,18 @@ describe('Feature flags Edit Module actions', () => {
},
],
[],
done,
);
});
});
describe('receiveUpdateFeatureFlagError', () => {
it('should commit RECEIVE_UPDATE_FEATURE_FLAG_ERROR mutation', (done) => {
testAction(
it('should commit RECEIVE_UPDATE_FEATURE_FLAG_ERROR mutation', () => {
return testAction(
receiveUpdateFeatureFlagError,
'There was an error',
mockedState,
[{ type: types.RECEIVE_UPDATE_FEATURE_FLAG_ERROR, payload: 'There was an error' }],
[],
done,
);
});
});
......@@ -159,10 +154,10 @@ describe('Feature flags Edit Module actions', () => {
});
describe('success', () => {
it('dispatches requestFeatureFlag and receiveFeatureFlagSuccess ', (done) => {
it('dispatches requestFeatureFlag and receiveFeatureFlagSuccess ', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { id: 1 });
testAction(
return testAction(
fetchFeatureFlag,
{ id: 1 },
mockedState,
......@@ -176,16 +171,15 @@ describe('Feature flags Edit Module actions', () => {
payload: { id: 1 },
},
],
done,
);
});
});
describe('error', () => {
it('dispatches requestFeatureFlag and receiveUpdateFeatureFlagError ', (done) => {
it('dispatches requestFeatureFlag and receiveUpdateFeatureFlagError ', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`, {}).replyOnce(500, {});
testAction(
return testAction(
fetchFeatureFlag,
null,
mockedState,
......@@ -198,41 +192,38 @@ describe('Feature flags Edit Module actions', () => {
type: 'receiveFeatureFlagError',
},
],
done,
);
});
});
});
describe('requestFeatureFlag', () => {
it('should commit REQUEST_FEATURE_FLAG mutation', (done) => {
testAction(
it('should commit REQUEST_FEATURE_FLAG mutation', () => {
return testAction(
requestFeatureFlag,
null,
mockedState,
[{ type: types.REQUEST_FEATURE_FLAG }],
[],
done,
);
});
});
describe('receiveFeatureFlagSuccess', () => {
it('should commit RECEIVE_FEATURE_FLAG_SUCCESS mutation', (done) => {
testAction(
it('should commit RECEIVE_FEATURE_FLAG_SUCCESS mutation', () => {
return testAction(
receiveFeatureFlagSuccess,
{ id: 1 },
mockedState,
[{ type: types.RECEIVE_FEATURE_FLAG_SUCCESS, payload: { id: 1 } }],
[],
done,
);
});
});
describe('receiveFeatureFlagError', () => {
it('should commit RECEIVE_FEATURE_FLAG_ERROR mutation', (done) => {
testAction(
it('should commit RECEIVE_FEATURE_FLAG_ERROR mutation', () => {
return testAction(
receiveFeatureFlagError,
null,
mockedState,
......@@ -242,20 +233,18 @@ describe('Feature flags Edit Module actions', () => {
},
],
[],
done,
);
});
});
describe('toggelActive', () => {
it('should commit TOGGLE_ACTIVE mutation', (done) => {
testAction(
it('should commit TOGGLE_ACTIVE mutation', () => {
return testAction(
toggleActive,
true,
mockedState,
[{ type: types.TOGGLE_ACTIVE, payload: true }],
[],
done,
);
});
});
......
......@@ -32,14 +32,13 @@ describe('Feature flags actions', () => {
});
describe('setFeatureFlagsOptions', () => {
it('should commit SET_FEATURE_FLAGS_OPTIONS mutation', (done) => {
testAction(
it('should commit SET_FEATURE_FLAGS_OPTIONS mutation', () => {
return testAction(
setFeatureFlagsOptions,
{ page: '1', scope: 'all' },
mockedState,
[{ type: types.SET_FEATURE_FLAGS_OPTIONS, payload: { page: '1', scope: 'all' } }],
[],
done,
);
});
});
......@@ -57,10 +56,10 @@ describe('Feature flags actions', () => {
});
describe('success', () => {
it('dispatches requestFeatureFlags and receiveFeatureFlagsSuccess ', (done) => {
it('dispatches requestFeatureFlags and receiveFeatureFlagsSuccess ', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, getRequestData, {});
testAction(
return testAction(
fetchFeatureFlags,
null,
mockedState,
......@@ -74,16 +73,15 @@ describe('Feature flags actions', () => {
type: 'receiveFeatureFlagsSuccess',
},
],
done,
);
});
});
describe('error', () => {
it('dispatches requestFeatureFlags and receiveFeatureFlagsError ', (done) => {
it('dispatches requestFeatureFlags and receiveFeatureFlagsError ', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`, {}).replyOnce(500, {});
testAction(
return testAction(
fetchFeatureFlags,
null,
mockedState,
......@@ -96,28 +94,26 @@ describe('Feature flags actions', () => {
type: 'receiveFeatureFlagsError',
},
],
done,
);
});
});
});
describe('requestFeatureFlags', () => {
it('should commit RECEIVE_FEATURE_FLAGS_SUCCESS mutation', (done) => {
testAction(
it('should commit RECEIVE_FEATURE_FLAGS_SUCCESS mutation', () => {
return testAction(
requestFeatureFlags,
null,
mockedState,
[{ type: types.REQUEST_FEATURE_FLAGS }],
[],
done,
);
});
});
describe('receiveFeatureFlagsSuccess', () => {
it('should commit RECEIVE_FEATURE_FLAGS_SUCCESS mutation', (done) => {
testAction(
it('should commit RECEIVE_FEATURE_FLAGS_SUCCESS mutation', () => {
return testAction(
receiveFeatureFlagsSuccess,
{ data: getRequestData, headers: {} },
mockedState,
......@@ -128,20 +124,18 @@ describe('Feature flags actions', () => {
},
],
[],
done,
);
});
});
describe('receiveFeatureFlagsError', () => {
it('should commit RECEIVE_FEATURE_FLAGS_ERROR mutation', (done) => {
testAction(
it('should commit RECEIVE_FEATURE_FLAGS_ERROR mutation', () => {
return testAction(
receiveFeatureFlagsError,
null,
mockedState,
[{ type: types.RECEIVE_FEATURE_FLAGS_ERROR }],
[],
done,
);
});
});
......@@ -159,10 +153,10 @@ describe('Feature flags actions', () => {
});
describe('success', () => {
it('dispatches requestRotateInstanceId and receiveRotateInstanceIdSuccess ', (done) => {
it('dispatches requestRotateInstanceId and receiveRotateInstanceIdSuccess ', () => {
mock.onPost(`${TEST_HOST}/endpoint.json`).replyOnce(200, rotateData, {});
testAction(
return testAction(
rotateInstanceId,
null,
mockedState,
......@@ -176,16 +170,15 @@ describe('Feature flags actions', () => {
type: 'receiveRotateInstanceIdSuccess',
},
],
done,
);
});
});
describe('error', () => {
it('dispatches requestRotateInstanceId and receiveRotateInstanceIdError ', (done) => {
it('dispatches requestRotateInstanceId and receiveRotateInstanceIdError ', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`, {}).replyOnce(500, {});
testAction(
return testAction(
rotateInstanceId,
null,
mockedState,
......@@ -198,28 +191,26 @@ describe('Feature flags actions', () => {
type: 'receiveRotateInstanceIdError',
},
],
done,
);
});
});
});
describe('requestRotateInstanceId', () => {
it('should commit REQUEST_ROTATE_INSTANCE_ID mutation', (done) => {
testAction(
it('should commit REQUEST_ROTATE_INSTANCE_ID mutation', () => {
return testAction(
requestRotateInstanceId,
null,
mockedState,
[{ type: types.REQUEST_ROTATE_INSTANCE_ID }],
[],
done,
);
});
});
describe('receiveRotateInstanceIdSuccess', () => {
it('should commit RECEIVE_ROTATE_INSTANCE_ID_SUCCESS mutation', (done) => {
testAction(
it('should commit RECEIVE_ROTATE_INSTANCE_ID_SUCCESS mutation', () => {
return testAction(
receiveRotateInstanceIdSuccess,
{ data: rotateData, headers: {} },
mockedState,
......@@ -230,20 +221,18 @@ describe('Feature flags actions', () => {
},
],
[],
done,
);
});
});
describe('receiveRotateInstanceIdError', () => {
it('should commit RECEIVE_ROTATE_INSTANCE_ID_ERROR mutation', (done) => {
testAction(
it('should commit RECEIVE_ROTATE_INSTANCE_ID_ERROR mutation', () => {
return testAction(
receiveRotateInstanceIdError,
null,
mockedState,
[{ type: types.RECEIVE_ROTATE_INSTANCE_ID_ERROR }],
[],
done,
);
});
});
......@@ -262,10 +251,10 @@ describe('Feature flags actions', () => {
mock.restore();
});
describe('success', () => {
it('dispatches updateFeatureFlag and receiveUpdateFeatureFlagSuccess', (done) => {
it('dispatches updateFeatureFlag and receiveUpdateFeatureFlagSuccess', () => {
mock.onPut(featureFlag.update_path).replyOnce(200, featureFlag, {});
testAction(
return testAction(
toggleFeatureFlag,
featureFlag,
mockedState,
......@@ -280,15 +269,15 @@ describe('Feature flags actions', () => {
type: 'receiveUpdateFeatureFlagSuccess',
},
],
done,
);
});
});
describe('error', () => {
it('dispatches updateFeatureFlag and receiveUpdateFeatureFlagSuccess', (done) => {
it('dispatches updateFeatureFlag and receiveUpdateFeatureFlagSuccess', () => {
mock.onPut(featureFlag.update_path).replyOnce(500);
testAction(
return testAction(
toggleFeatureFlag,
featureFlag,
mockedState,
......@@ -303,7 +292,6 @@ describe('Feature flags actions', () => {
type: 'receiveUpdateFeatureFlagError',
},
],
done,
);
});
});
......@@ -315,8 +303,8 @@ describe('Feature flags actions', () => {
}));
});
it('commits UPDATE_FEATURE_FLAG with the given flag', (done) => {
testAction(
it('commits UPDATE_FEATURE_FLAG with the given flag', () => {
return testAction(
updateFeatureFlag,
featureFlag,
mockedState,
......@@ -327,7 +315,6 @@ describe('Feature flags actions', () => {
},
],
[],
done,
);
});
});
......@@ -338,8 +325,8 @@ describe('Feature flags actions', () => {
}));
});
it('commits RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS with the given flag', (done) => {
testAction(
it('commits RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS with the given flag', () => {
return testAction(
receiveUpdateFeatureFlagSuccess,
featureFlag,
mockedState,
......@@ -350,7 +337,6 @@ describe('Feature flags actions', () => {
},
],
[],
done,
);
});
});
......@@ -361,8 +347,8 @@ describe('Feature flags actions', () => {
}));
});
it('commits RECEIVE_UPDATE_FEATURE_FLAG_ERROR with the given flag id', (done) => {
testAction(
it('commits RECEIVE_UPDATE_FEATURE_FLAG_ERROR with the given flag id', () => {
return testAction(
receiveUpdateFeatureFlagError,
featureFlag.id,
mockedState,
......@@ -373,22 +359,20 @@ describe('Feature flags actions', () => {
},
],
[],
done,
);
});
});
describe('clearAlert', () => {
it('should commit RECEIVE_CLEAR_ALERT', (done) => {
it('should commit RECEIVE_CLEAR_ALERT', () => {
const alertIndex = 3;
testAction(
return testAction(
clearAlert,
alertIndex,
mockedState,
[{ type: 'RECEIVE_CLEAR_ALERT', payload: alertIndex }],
[],
done,
);
});
});
......
......@@ -33,7 +33,7 @@ describe('Feature flags New Module Actions', () => {
});
describe('success', () => {
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagSuccess ', (done) => {
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagSuccess ', () => {
const actionParams = {
name: 'name',
description: 'description',
......@@ -50,7 +50,7 @@ describe('Feature flags New Module Actions', () => {
};
mock.onPost(mockedState.endpoint, mapStrategiesToRails(actionParams)).replyOnce(200);
testAction(
return testAction(
createFeatureFlag,
actionParams,
mockedState,
......@@ -63,13 +63,12 @@ describe('Feature flags New Module Actions', () => {
type: 'receiveCreateFeatureFlagSuccess',
},
],
done,
);
});
});
describe('error', () => {
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagError ', (done) => {
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagError ', () => {
const actionParams = {
name: 'name',
description: 'description',
......@@ -88,7 +87,7 @@ describe('Feature flags New Module Actions', () => {
.onPost(mockedState.endpoint, mapStrategiesToRails(actionParams))
.replyOnce(500, { message: [] });
testAction(
return testAction(
createFeatureFlag,
actionParams,
mockedState,
......@@ -102,28 +101,26 @@ describe('Feature flags New Module Actions', () => {
payload: { message: [] },
},
],
done,
);
});
});
});
describe('requestCreateFeatureFlag', () => {
it('should commit REQUEST_CREATE_FEATURE_FLAG mutation', (done) => {
testAction(
it('should commit REQUEST_CREATE_FEATURE_FLAG mutation', () => {
return testAction(
requestCreateFeatureFlag,
null,
mockedState,
[{ type: types.REQUEST_CREATE_FEATURE_FLAG }],
[],
done,
);
});
});
describe('receiveCreateFeatureFlagSuccess', () => {
it('should commit RECEIVE_CREATE_FEATURE_FLAG_SUCCESS mutation', (done) => {
testAction(
it('should commit RECEIVE_CREATE_FEATURE_FLAG_SUCCESS mutation', () => {
return testAction(
receiveCreateFeatureFlagSuccess,
null,
mockedState,
......@@ -133,20 +130,18 @@ describe('Feature flags New Module Actions', () => {
},
],
[],
done,
);
});
});
describe('receiveCreateFeatureFlagError', () => {
it('should commit RECEIVE_CREATE_FEATURE_FLAG_ERROR mutation', (done) => {
testAction(
it('should commit RECEIVE_CREATE_FEATURE_FLAG_ERROR mutation', () => {
return testAction(
receiveCreateFeatureFlagError,
'There was an error',
mockedState,
[{ type: types.RECEIVE_CREATE_FEATURE_FLAG_ERROR, payload: 'There was an error' }],
[],
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