Skip to content

Commit 5351a93

Browse files
committed
Configure routings and delete unnecessary files
1 parent 3e29dac commit 5351a93

40 files changed

+685
-855
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
jest.dontMock('redux-mock-store');
2+
jest.dontMock('redux-thunk');
3+
jest.dontMock('../../actions/auth');
4+
5+
const configureMockStore = require('redux-mock-store');
6+
const thunk = require('redux-thunk');
7+
const Auth = require('../../actions/auth');
8+
9+
const middlewares = [ thunk ];
10+
const mockStore = configureMockStore(middlewares);
11+
12+
describe('auth actions', () => {
13+
14+
it('creates SIGNUP_REQUEST and SIGNUP_SUCCESS when signup has been done successfully', () => {
15+
16+
/* If this account has already exists in Parse database, it will get SIGNUP_ERROR */
17+
const username = 'testing';
18+
const password = 'testing';
19+
20+
const expectedActions = [
21+
{ type: 'SIGNUP_REQUEST', payload: { username, password } },
22+
{ type: 'SIGNUP_SUCCESS', payload: { } }
23+
];
24+
25+
const store = mockStore({ auth: { user: null } }, expectedActions);
26+
store.dispatch(Auth.signup(username, password));
27+
})
28+
})

meetingapp/app/__tests__/actions/todo-test.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

meetingapp/app/__tests__/actions/visibility-filter-test.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

meetingapp/app/__tests__/reducers/todo-test.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

meetingapp/app/__tests__/reducers/visibility-filter-test.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

meetingapp/app/actions/auth.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* Defines actions related to user authentication.
3+
*
4+
* This approach is refered from Redux creator - gaearon's comments :
5+
* https://github.com/rackt/redux/issues/291
6+
*/
7+
8+
import Parse from '../modules/parse/index';
9+
import { pushPath } from 'redux-simple-router';
10+
11+
export const SIGNUP_REQUEST = 'SIGNUP_REQUEST';
12+
export function signupRequest(username, password) {
13+
return {
14+
type: SIGNUP_REQUEST,
15+
payload: { username, password }
16+
}
17+
}
18+
19+
export const SIGNUP_SUCCESS = 'SIGNUP_SUCCESS';
20+
export function signupSuccess(user) {
21+
return {
22+
type: SIGNUP_SUCCESS,
23+
payload: { user }
24+
}
25+
}
26+
27+
export const SIGNUP_ERROR = 'SIGNUP_ERROR';
28+
export function signupError(error) {
29+
return {
30+
type: SIGNUP_ERROR,
31+
payload: { error }
32+
}
33+
}
34+
35+
/* Here is where we should put our network request. */
36+
export function signup(username, password, redirect = '/') {
37+
38+
var user = new Parse.User();
39+
40+
user.set('username', username);
41+
user.set('password', password);
42+
43+
/**
44+
* Here is a thunk, which is a function that returns a function.
45+
* Return a function that accepts 'dispatch' so we can dispatch in the future moment
46+
* when we get response from promise.
47+
*/
48+
return (dispatch, getState) => {
49+
50+
/* Update the application state to inform user the network request is about to start. */
51+
dispatch(signupRequest(username, password));
52+
53+
return user.signUp(null, {
54+
success: function(user) {
55+
dispatch(signupSuccess(user));
56+
dispatch(pushPath(redirect));
57+
},
58+
error: function(user, error) {
59+
dispatch(signupError(error));
60+
}
61+
})
62+
}
63+
}
64+
65+
export const LOGIN_REQUEST = 'LOGIN_REQUEST';
66+
export function loginRequest(username, password) {
67+
return {
68+
type: LOGIN_REQUEST,
69+
payload: { username, password }
70+
}
71+
}
72+
73+
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
74+
export function loginSuccess(user) {
75+
return {
76+
type: LOGIN_SUCCESS,
77+
payload: { user }
78+
}
79+
}
80+
81+
export const LOGIN_ERROR = 'LOGIN_ERROR';
82+
export function loginError(error) {
83+
return {
84+
type: LOGIN_ERROR,
85+
payload: { error }
86+
}
87+
}
88+
89+
export function login(username, password, redirect = '/') {
90+
91+
/**
92+
* Here is a thunk, which is a function that returns a function.
93+
* Return a function that accepts 'dispatch' so we can dispatch in the future moment
94+
* when we get response from promise.
95+
*/
96+
return (dispatch, getState) => {
97+
98+
/* Update the application state to inform user the network request is about to start. */
99+
dispatch(loginRequest(username, password));
100+
101+
return Parse.User.logIn(username, password, {
102+
success: function(user) {
103+
dispatch(loginSuccess(user));
104+
dispatch(pushPath(redirect));
105+
},
106+
error: function(user, error) {
107+
dispatch(loginError(error));
108+
}
109+
})
110+
}
111+
}
112+
113+
export const LOGOUT = 'LOGOUT';
114+
export function logout() {
115+
return {
116+
type: LOGOUT,
117+
payload: {}
118+
}
119+
}
120+
121+
export function logoutAndRedirect() {
122+
return (dispatch, getState) => {
123+
124+
dispatch(logout());
125+
dispatch(pushPath('/'));
126+
}
127+
}

meetingapp/app/actions/todo.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)