Created
April 23, 2018 11:10
-
-
Save Tinusw/9f82451a46e71664dbbffd7b62593bde to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { expect } from "../test_helper"; | |
import configureMockStore from "redux-mock-store"; | |
import thunk from "redux-thunk"; | |
import moxios from "moxios"; | |
import { storageMock } from "./mock_local_storage"; | |
import { signinUser } from "../../src/actions/index"; | |
import { AUTH_USER, AUTH_ERROR } from "../../src/actions/types"; | |
global.localStorage = storageMock(); | |
const middlewares = [thunk]; | |
const mockStore = configureMockStore(middlewares); | |
let store; | |
let url; | |
describe("AUTH ACTION CREATORS", () => { | |
beforeEach(() => { | |
moxios.install(); | |
store = mockStore({}); | |
url = "http://localhost:3030"; | |
}); | |
afterEach(() => { | |
moxios.uninstall(); | |
}); | |
describe("signinUser()", () => { | |
it("create a token on AUTH USER", () => { | |
moxios.wait(() => { | |
let request = moxios.requests.mostRecent(); | |
request.respondWith({ | |
status: 200, | |
response: { | |
data: { | |
token: "sample_token" | |
} | |
} | |
}); | |
}); | |
const expectedAction = { type: AUTH_USER }; | |
let testData = { email: "[email protected]", password: "1234" }; | |
return store.dispatch(signinUser(testData)).then(() => { | |
const actualAction = store.getActions(); | |
expect(actualAction[0]).to.eql(expectedAction); | |
}); | |
}); | |
it("returns an error on AUTH_ERROR with 401", () => { | |
moxios.wait(() => { | |
let request = moxios.requests.mostRecent(); | |
request.respondWith({ | |
status: 401, | |
response: { | |
data: "Unauthorized", | |
status: 401 | |
} | |
}); | |
}); | |
const expectedAction = { | |
type: AUTH_ERROR, | |
payload: "Error: Request failed with status code 401" | |
}; | |
let testData = { email: "[email protected]", password: "124" }; | |
return store.dispatch(signinUser(testData)).then(() => { | |
const actualAction = store.getActions(); | |
expect(actualAction[0].type).to.eql(expectedAction.type); | |
expect(actualAction[0].payload.toString()).to.eql( | |
expectedAction.payload | |
); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment