Created
October 16, 2020 06:02
-
-
Save dhpradeep/3386b54106b1a542c389686899efa869 to your computer and use it in GitHub Desktop.
Sample
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
const authLogin = async (email, password) => | |
axios.post("/api/token/obtain/", { email, password }) |
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 { login, logoutSuccess } from "../../src/redux/auth/action" | |
import Config from "./config" | |
Cypress.Commands.add("loginAs", (role) => { | |
const user = Config.users[role] | |
cy.log(`Logging with ${user.email} as role of ${role}`) | |
login(user.email, user.password) | |
}) | |
Cypress.Commands.add("logout", () => { | |
cy.log("Logging out user!!") | |
logoutSuccess() | |
window.localStorage.clear() | |
window.sessionStorage.clear() | |
}) |
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
const Config = { | |
users: { | |
admin: { | |
email: "admin@admin.com", | |
password: "admin12345" | |
}, | |
staff: { | |
email: "staff@staff.com", | |
password: "staff12345" | |
} | |
} | |
} | |
export default Config |
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 {authLogin} from "axios" | |
const login = (username, password) => (dispatch) => { | |
dispatch(loadBegin()) | |
return authLogin(username, password) | |
.then((res) => { | |
// successfully logged in | |
dispatch(loginSuccess(res.data, username)) | |
dispatch(loadEnd()) | |
return true | |
}) | |
.catch((err) => { | |
error(err) | |
dispatch(loadEnd()) | |
return false | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment