mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
* consistent error handling * Display server errors in InviteUserForm * Handle errors in Form component * Refactors query form * creates KolideAce component * Renders QueryForm from query page and manage hosts page * Moves ace editor and select targets dropdown to query form * Render base errors in Form HOC * LoginPage and ForgotPasswordPage server errors * Ensure unique key for user blocks * Adds base error to login form and forgot password form * Adds base error to query form * Adds base error to Pack Form * Adds errors to confirm invite form * Adds clearErrors action * clear errors when confirm invite page unmounts * Handle errors in the App Setting page * Handle server errors in the User Settings Page * Handle server errors in the User Management Page
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
import expect from 'expect';
|
|
import nock from 'nock';
|
|
import { find } from 'lodash';
|
|
|
|
import { reduxMockStore } from 'test/helpers';
|
|
import { validGetQueryRequest, invalidGetQueryRequest } from 'test/mocks';
|
|
import helpers from 'components/queries/QueryPageWrapper/helpers';
|
|
|
|
describe('QueryPageWrapper - helpers', () => {
|
|
afterEach(() => { nock.cleanAll(); });
|
|
|
|
const queryID = '10';
|
|
|
|
describe('#fetchQuery', () => {
|
|
const { fetchQuery } = helpers;
|
|
const bearerToken = 'abc123';
|
|
|
|
beforeEach(() => {
|
|
global.localStorage.setItem('KOLIDE::auth_token', bearerToken);
|
|
});
|
|
|
|
context('when the API call is successful', () => {
|
|
it('dispatches a load successful action', (done) => {
|
|
validGetQueryRequest(bearerToken, queryID);
|
|
const mockStore = reduxMockStore();
|
|
|
|
fetchQuery(mockStore.dispatch, queryID)
|
|
.then(() => {
|
|
const dispatchedActions = mockStore.getActions().map((action) => { return action.type; });
|
|
expect(dispatchedActions).toInclude('queries_LOAD_SUCCESS');
|
|
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
context('when the API call is unsuccessful', () => {
|
|
it('pushes to the new query page', (done) => {
|
|
invalidGetQueryRequest(bearerToken, queryID);
|
|
const mockStore = reduxMockStore();
|
|
|
|
fetchQuery(mockStore.dispatch, queryID)
|
|
.then(() => {
|
|
const dispatchedActions = mockStore.getActions();
|
|
const locationChangeAction = find(dispatchedActions, { type: '@@router/CALL_HISTORY_METHOD' });
|
|
expect(locationChangeAction).toExist();
|
|
expect(locationChangeAction.payload).toEqual({
|
|
method: 'push',
|
|
args: ['/queries/new'],
|
|
});
|
|
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('renders a flash error message', (done) => {
|
|
invalidGetQueryRequest(bearerToken, queryID);
|
|
const mockStore = reduxMockStore();
|
|
|
|
fetchQuery(mockStore.dispatch, queryID)
|
|
.then(() => {
|
|
const dispatchedActions = mockStore.getActions();
|
|
const flashMessageAction = find(dispatchedActions, { type: 'RENDER_FLASH' });
|
|
|
|
expect(flashMessageAction).toExist();
|
|
expect(flashMessageAction.payload).toInclude({
|
|
alertType: 'error',
|
|
message: 'Resource not found',
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done);
|
|
});
|
|
});
|
|
});
|
|
});
|