Skip to content

Instantly share code, notes, and snippets.

@jasongaare
Created June 29, 2017 01:36
Show Gist options
  • Save jasongaare/32e7330dfcdcfe0080dc861ca3bf76d1 to your computer and use it in GitHub Desktop.
Save jasongaare/32e7330dfcdcfe0080dc861ca3bf76d1 to your computer and use it in GitHub Desktop.
import MockAdapter from 'axios-mock-adapter';
import apiClient from 'helpers/api-client';
import { userObject } from 'jest/mockResponseObjects/user-objects';
import mockStore from 'redux-mock-store';
const mockApi = new MockAdapter(apiClient.getAxiosInstance());
const validAuth = '{"email":"email@test.com","password":"password"}';
const store = mockStore();
mockApi.onPost('sessions').reply((config) => {
if (config.data === validAuth) {
return [200, userObject];
}
return [400, 'Bad Credentials'];
});
describe('Testing log in authentication', () => {
beforeEach(() => {
store.clearActions();
});
it('attempt with correct password succeeds', async () => {
await store.dispatch(authenticateUser('email@test.com', 'password'));
expect(store.getActions()).toMatchSnapshot();
});
it('attempt with wrong password fails as expected', async () => {
await store.dispatch(authenticateUser('email@test.com', 'wrong'))
.catch((error) => {
const errorObject = { ...error };
delete errorObject.duration;
expect(errorObject).toMatchSnapshot();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment