-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,174 additions
and
9,005 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
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 |
---|---|---|
|
@@ -12,4 +12,4 @@ html-css/**/*.css* | |
yarn.* | ||
yarn-* | ||
.DS_Store | ||
|
||
.env |
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
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,94 @@ | ||
import moxios from "moxios"; | ||
import thunk from "redux-thunk"; | ||
import configureMockStore from "redux-mock-store"; | ||
import axios from "../../utils/axios"; | ||
import reduxStore from "../../redux/store"; | ||
import { | ||
handleInputChange, | ||
sendResetLink | ||
} from "../../redux/actions/resetPasswordActions"; | ||
import { | ||
SENDING_RESET_PASSWORD_LINK, | ||
RESET_PASSWORD_INPUT_CHANGE, | ||
RESET_PASSWORD_LINK_SUCCESS, | ||
RESET_PASSWORD_LINK_FAILED | ||
} from "../../redux/actionTypes"; | ||
|
||
const DEV_BASE_URL = "http://localhost:3000/api/v1"; | ||
let data; | ||
const mockStore = configureMockStore([thunk]); | ||
let store; | ||
|
||
describe("ResetPassword action creators", () => { | ||
describe("handle user input action creator", () => { | ||
data = { name: "email", value: "me@example.com" }; | ||
it("should create an action to update text input value", () => { | ||
const expectedAction = { | ||
type: RESET_PASSWORD_INPUT_CHANGE, | ||
payload: data | ||
}; | ||
expect(handleInputChange(data.name, data.value)).toEqual(expectedAction); | ||
}); | ||
}); | ||
|
||
describe("handle sign action creator", () => { | ||
beforeEach(() => { | ||
moxios.install(axios); | ||
store = mockStore({}); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(axios); | ||
}); | ||
it("dispatches RESET_PASSWORD_LINK_SUCCESS after successfully sending link", () => { | ||
store = mockStore({ login: reduxStore.resetPassword }); | ||
data = { name: "email", value: "me@example.com" }; | ||
const payload = { | ||
message: | ||
"Password reset instructions have been sent to your account's primary email address." | ||
}; | ||
const expectedActions = [ | ||
{ | ||
type: SENDING_RESET_PASSWORD_LINK | ||
}, | ||
{ | ||
type: RESET_PASSWORD_LINK_SUCCESS, | ||
payload: { ...payload } | ||
} | ||
]; | ||
|
||
moxios.stubRequest(`${DEV_BASE_URL}/users/reset_password`, { | ||
status: 200, | ||
response: { | ||
...payload | ||
} | ||
}); | ||
return store.dispatch(sendResetLink(data)).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
it("dispatches RESET_PASSWORD_LINK_FAILED sending reset password link failed", () => { | ||
store = mockStore({ login: reduxStore.login }); | ||
const payload = { message: "User not found" }; | ||
const expectedActions = [ | ||
{ | ||
type: SENDING_RESET_PASSWORD_LINK | ||
}, | ||
{ | ||
type: RESET_PASSWORD_LINK_FAILED, | ||
payload: { ...payload } | ||
} | ||
]; | ||
|
||
moxios.stubRequest(`${DEV_BASE_URL}/users/reset_password`, { | ||
status: 404, | ||
response: { | ||
...payload | ||
} | ||
}); | ||
|
||
return store.dispatch(sendResetLink({ ...data })).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); | ||
}); |
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,89 @@ | ||
import moxios from "moxios"; | ||
import thunk from "redux-thunk"; | ||
import configureMockStore from "redux-mock-store"; | ||
import axios from "../../utils/axios"; | ||
import * as actions from "../../redux/actions/updatePasswordActions"; | ||
import { | ||
UPDATE_PASSWORD_INPUT_CHANGE, | ||
UPDATING_PASSWORD, | ||
PASSWORD_UPDATE_FAILED, | ||
PASSWORD_UPDATE_SUCCESS | ||
} from "../../redux/actionTypes"; | ||
|
||
const DEV_BASE_URL = "http://localhost:3000/api/v1"; | ||
const mockStore = configureMockStore([thunk]); | ||
let store; | ||
describe("update password actions ceators", () => { | ||
beforeEach(() => { | ||
moxios.install(axios); | ||
store = mockStore({}); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(axios); | ||
}); | ||
it("dispatches UPDATE_PASSWORD_INPUT_CHANGE", () => { | ||
const payload = { field: "password", value: "password" }; | ||
const expectedActions = { | ||
type: UPDATE_PASSWORD_INPUT_CHANGE, | ||
payload | ||
}; | ||
expect(actions.handleInputChange(payload.field, payload.value)).toEqual( | ||
expectedActions | ||
); | ||
}); | ||
it("dispatches PASSWORD_UPDATE_FAILED", () => { | ||
const payload = { message: "Invalid or expired token", errors: {} }; | ||
const params = { | ||
token: "1234567qwertyui", | ||
password: "password" | ||
}; | ||
|
||
moxios.stubRequest(`${DEV_BASE_URL}/users/${params.token}/password`, { | ||
status: 404, | ||
response: { | ||
...payload | ||
} | ||
}); | ||
const expectedActions = [ | ||
{ | ||
type: UPDATING_PASSWORD | ||
}, | ||
{ | ||
type: PASSWORD_UPDATE_FAILED, | ||
payload: { ...payload } | ||
} | ||
]; | ||
return store | ||
.dispatch(actions.handleUpdatePassword({ ...params })) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
it("dispatches PASSWORD_UPDATE_SUCCESS", () => { | ||
const payload = { message: "Password updated successfully" }; | ||
const params = { | ||
token: "1234567qwertyui", | ||
password: "password" | ||
}; | ||
moxios.stubRequest(`${DEV_BASE_URL}/users/${params.token}/password`, { | ||
status: 200, | ||
response: { | ||
...payload | ||
} | ||
}); | ||
const expectedActions = [ | ||
{ | ||
type: UPDATING_PASSWORD | ||
}, | ||
{ | ||
type: PASSWORD_UPDATE_SUCCESS, | ||
payload: { ...payload } | ||
} | ||
]; | ||
return store | ||
.dispatch(actions.handleUpdatePassword({ ...params })) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); |
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,69 @@ | ||
import resetPasswordReducers, { | ||
INITIAL_STATE | ||
} from "../../redux/reducers/resetPasswordReducers"; | ||
import { | ||
RESET_PASSWORD_INPUT_CHANGE, | ||
SENDING_RESET_PASSWORD_LINK, | ||
RESET_PASSWORD_LINK_FAILED, | ||
RESET_PASSWORD_LINK_SUCCESS | ||
} from "../../redux/actionTypes"; | ||
|
||
const userInput = { name: "email", value: "me@example.com" }; | ||
|
||
describe("Login reducers", () => { | ||
it("should return initial state", () => { | ||
expect(resetPasswordReducers(undefined, {})).toEqual({ | ||
...INITIAL_STATE | ||
}); | ||
}); | ||
it("should handle RESET_PASSWORD_INPUT_CHANGE", () => { | ||
expect( | ||
resetPasswordReducers(INITIAL_STATE, { | ||
type: RESET_PASSWORD_INPUT_CHANGE, | ||
payload: { ...userInput } | ||
}) | ||
).toEqual({ | ||
...INITIAL_STATE, | ||
[userInput.name]: userInput.value | ||
}); | ||
}); | ||
it("should handle SENDING_RESET_PASSWORD_LINK", () => { | ||
expect( | ||
resetPasswordReducers(INITIAL_STATE, { | ||
type: SENDING_RESET_PASSWORD_LINK | ||
}) | ||
).toEqual({ | ||
...INITIAL_STATE, | ||
isSubmitting: true | ||
}); | ||
}); | ||
it("should handle RESET_PASSWORD_LINK_FAILED", () => { | ||
const errorPayload = { message: "User not found" }; | ||
expect( | ||
resetPasswordReducers(INITIAL_STATE, { | ||
type: RESET_PASSWORD_LINK_FAILED, | ||
payload: { ...errorPayload } | ||
}) | ||
).toEqual({ | ||
...INITIAL_STATE, | ||
isSuccess: false, | ||
failedMessage: errorPayload.message | ||
}); | ||
}); | ||
it("should handle LOGIN_SUCCESS", () => { | ||
const successPayload = { | ||
message: | ||
"Password reset instructions have been sent to your account's primary email address." | ||
}; | ||
expect( | ||
resetPasswordReducers(INITIAL_STATE, { | ||
type: RESET_PASSWORD_LINK_SUCCESS, | ||
payload: { ...successPayload } | ||
}) | ||
).toEqual({ | ||
...INITIAL_STATE, | ||
isSuccess: true, | ||
successMessage: successPayload.message | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.