Created
June 29, 2017 01:36
-
-
Save jasongaare/32e7330dfcdcfe0080dc861ca3bf76d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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