-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolving conflicts to merge to tdd redux action login
- Loading branch information
Showing
9 changed files
with
210 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ stats.json | |
|
||
#apidoc | ||
apidoc | ||
|
||
.vscode |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { login, logout } from "../../actions/Login"; | ||
import configureStore from "../../configureStore"; | ||
import axios from "axios"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
import "jest-localstorage-mock"; | ||
|
||
describe("Action Login", () => { | ||
let store; | ||
let mock; | ||
beforeEach(() => { | ||
store = configureStore(); | ||
mock = new MockAdapter(axios); | ||
}); | ||
|
||
afterEach(() => { | ||
mock.restore(); | ||
mock.reset(); | ||
}); | ||
|
||
it("Shoud to authenticate a user and set token localstorage", () => { | ||
let response = { | ||
success: true, | ||
message: "Login User successfull!", | ||
token: "asijaosijas1109281029812", | ||
user: { name: "Name example", email: "email@example.com" }, | ||
showPreloader: false | ||
}; | ||
|
||
mock.onPost("/api/v1/login").reply(200, response); | ||
|
||
const expectedState = [ | ||
{ | ||
success: response.success, | ||
message: response.message, | ||
user: response.user, | ||
showPreloader: response.showPreloader | ||
} | ||
]; | ||
|
||
store.dispatch(login(response.user.email, 12345)).then(() => { | ||
expect([store.getState().userReducer]).toEqual(expectedState); | ||
expect(response.token).toEqual(JSON.parse(localStorage.getItem("token"))); | ||
expect(response.user).toEqual(JSON.parse(localStorage.getItem("user"))); | ||
}); | ||
}); | ||
|
||
it("Shoud logout a user and clean token and user in the localstorage", () => { | ||
store.dispatch(logout()); | ||
expect(localStorage.getItem("token")).toEqual(null); | ||
expect(localStorage.getItem("user")).toEqual(null); | ||
}); | ||
}); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// setup file | ||
import { configure } from "enzyme"; | ||
import Adapter from "enzyme-adapter-react-16"; | ||
|
||
export default configure({ adapter: new Adapter() }); |
Oops, something went wrong.