Skip to content

Commit

Permalink
Merge fdef729 into 207a58a
Browse files Browse the repository at this point in the history
  • Loading branch information
abayo-luc committed Apr 17, 2019
2 parents 207a58a + fdef729 commit f591e91
Show file tree
Hide file tree
Showing 37 changed files with 1,174 additions and 9,005 deletions.
Binary file modified .DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"no-named-as-default": "off",
"arrow-body-style": ["error", "as-needed"],
"import/no-dynamic-require": "off",
"react/forbid-prop-types": "off",
"no-shadow": [
"error",
{
Expand Down Expand Up @@ -82,6 +83,14 @@
"ClassDeclaration": false
}
}
],
"jsx-a11y/anchor-is-valid": [
"error",
{
"components": ["Link"],
"specialLink": ["to"],
"aspects": ["noHref", "invalidHref", "preferButton"]
}
]
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ html-css/**/*.css*
yarn.*
yarn-*
.DS_Store

.env
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 'stable'
- "stable"
cache:
directories:
- node_modules
Expand All @@ -12,7 +12,7 @@ script:
- yarn test
after_success:
- yarn run coveralls
- 'stable'
- "stable"
notifications:
email: false
slack: andela:LX8VPRMaSP4tskr94puPVmFf
slack: true
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^6.0.1",
"react-router-dom": "^5.0.0",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
Expand Down Expand Up @@ -73,7 +75,6 @@
"node-sass": "^4.11.0",
"prettier": "^1.16.4",
"react-test-renderer": "^16.8.6",
"redux-devtools-extension": "^2.13.8",
"redux-mock-store": "^1.5.3",
"resolve-url-loader": "2",
"sass": "^1.17.4",
Expand Down
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from "react";
import { Provider } from "react-redux";
import "./styles/main.scss";
import store from "./redux/store";
import Login from "./views/Login";
import Routers from "./views";

export default () => (
<Provider store={store}>
<Login />
<Routers />
</Provider>
);
4 changes: 2 additions & 2 deletions src/__tests__/__actions__/loginActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let store;

describe("Login action creators", () => {
describe("handle user input action creator", () => {
data = { name: "email", value: "luc.bayo@gmail.com" };
data = { name: "email", value: "me@example.com" };
it("should create an action to update text input value", () => {
const expectedAction = {
type: LOGIN_INPUT_CHANGE,
Expand All @@ -41,7 +41,7 @@ describe("Login action creators", () => {
});
it("dispatches LOGIN_SUCCESS after successfully signing in", () => {
store = mockStore({ login: reduxStore.login });
data = { name: "email", value: "luc.bayo@gmail.com" };
data = { name: "email", value: "me@example.com" };
const payload = {
message: "Sign in failed",
token: "qwertyuiop123456789"
Expand Down
94 changes: 94 additions & 0 deletions src/__tests__/__actions__/resetPasswordActions.test.js
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);
});
});
});
});
89 changes: 89 additions & 0 deletions src/__tests__/__actions__/updatePasswordActions.test.js
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);
});
});
});
2 changes: 1 addition & 1 deletion src/__tests__/__components__/Inputs/TextInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("Login component", () => {
component.simulate("change", {
target: {
name: "email",
value: "luc.bayo@gmail.com"
value: "me@example.com"
}
});
expect(component.props().onChange).toHaveBeenCalled();
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/__reducers__/loginReducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SUBMITTING_LOGIN_CREDENTIALS
} from "../../redux/actionTypes";

const emailInput = { name: "email", value: "luc.bayo@gmail.com" };
const emailInput = { name: "email", value: "me@example.com" };
const passwordInput = { name: "email", value: "password" };

describe("Login reducers", () => {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("Login reducers", () => {
})
).toEqual({
...INITIAL_STATE,
successMessage: successPayload.message,
loginSuccess: true,
token: successPayload.token
});
});
Expand Down
69 changes: 69 additions & 0 deletions src/__tests__/__reducers__/resetPasswordReducers.test.js
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
});
});
});
Loading

0 comments on commit f591e91

Please sign in to comment.