From e2dbe42484055c1714989eae0d597b5b5eca6fc3 Mon Sep 17 00:00:00 2001 From: omiceron Date: Sun, 20 May 2018 10:53:46 +0500 Subject: [PATCH 1/4] test --- admin/src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/App.js b/admin/src/App.js index 89f2dc0..c7ec8ec 100644 --- a/admin/src/App.js +++ b/admin/src/App.js @@ -3,7 +3,7 @@ import { Route, NavLink } from 'react-router-dom' import ProtectedRoute from './components/common/protected-route' import AuthPage from './routes/auth' import AdminPage from './routes/admin' - +//123 class App extends Component { render() { return ( From f0ed6b26a21ec43236474f62ccbd2780452de8bd Mon Sep 17 00:00:00 2001 From: omiceron Date: Sun, 20 May 2018 23:48:12 +0500 Subject: [PATCH 2/4] HT2: Sign in tests added --- admin/src/App.js | 2 +- admin/src/config.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/admin/src/App.js b/admin/src/App.js index c7ec8ec..89f2dc0 100644 --- a/admin/src/App.js +++ b/admin/src/App.js @@ -3,7 +3,7 @@ import { Route, NavLink } from 'react-router-dom' import ProtectedRoute from './components/common/protected-route' import AuthPage from './routes/auth' import AdminPage from './routes/admin' -//123 + class App extends Component { render() { return ( diff --git a/admin/src/config.js b/admin/src/config.js index aa22b3b..d9a5ccd 100644 --- a/admin/src/config.js +++ b/admin/src/config.js @@ -2,15 +2,15 @@ import firebase from 'firebase/app' import 'firebase/auth' import 'firebase/database' -export const appName = 'advreact-10-05' +export const appName = 'advancedreactcourse' export const config = { - apiKey: 'AIzaSyCbMQM0eQUSQ0SuLVAu9ZNPUcm4rdbiB8U', + apiKey: 'AIzaSyCCtMGA9FTNVds_QTkB1oRTlqF2u07MHuk', authDomain: `${appName}.firebaseapp.com`, databaseURL: `https://${appName}.firebaseio.com`, projectId: appName, - storageBucket: '', - messagingSenderId: '1094825197832' + storageBucket: `${appName}.appspot.com`, + messagingSenderId: '649150663252' } firebase.initializeApp(config) From d51a8e75656fb3e6b5f4c2ecdf7a988f7b02ebe3 Mon Sep 17 00:00:00 2001 From: omiceron Date: Mon, 21 May 2018 00:43:49 +0500 Subject: [PATCH 3/4] HT2: Sign up test cases + negative cases --- admin/src/ducks/auth.test.js | 134 +++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 admin/src/ducks/auth.test.js diff --git a/admin/src/ducks/auth.test.js b/admin/src/ducks/auth.test.js new file mode 100644 index 0000000..197bb93 --- /dev/null +++ b/admin/src/ducks/auth.test.js @@ -0,0 +1,134 @@ +import { call, put, take, apply, takeEvery, all } from 'redux-saga/effects' +import firebase from 'firebase/app' + +import { + signInSaga, + signUpSaga, + SIGN_IN_SUCCESS, + SIGN_IN_REQUEST, + SIGN_IN_ERROR, + SIGN_IN_REQUESTS_LIMIT, + SIGN_UP_SUCCESS, + SIGN_UP_REQUEST, + SIGN_UP_ERROR +} from './auth' + +describe('Auth duck', () => { + const auth = firebase.auth() + const goodCredentials = { + email: 'exampl1@home.ru', + password: '12345678' + } + + const badCredentials = { + email: 'newuser@home.ru', + password: '12345678' + } + + describe('Positive cases', () => { + const user = apply(auth, auth.signInWithEmailAndPassword, [ + goodCredentials.email, + goodCredentials.password + ]) + + it('should sign in user', () => { + const sagaProcess = signInSaga() + + expect(sagaProcess.next().value).toEqual(take(SIGN_IN_REQUEST)) + expect( + sagaProcess.next({ type: SIGN_IN_REQUEST, payload: goodCredentials }) + .value + ).toEqual(user) + expect(sagaProcess.next(user).value).toEqual( + put({ type: SIGN_IN_SUCCESS, payload: { user } }) + ) + expect(sagaProcess.next().done).toEqual(false) + }) + + it('should sign up user', () => { + const sagaProcess = signUpSaga({ + type: SIGN_UP_REQUEST, + payload: badCredentials + }) + + const user = call( + [auth, auth.createUserWithEmailAndPassword], + badCredentials.email, + badCredentials.password + ) + + expect(sagaProcess.next().value).toEqual(user) + expect(sagaProcess.next(user).value).toEqual( + put({ type: SIGN_UP_SUCCESS, payload: { user } }) + ) + expect(sagaProcess.next().done).toEqual(true) + }) + }) + + describe('Negative cases', () => { + const user = apply(auth, auth.signInWithEmailAndPassword, [ + badCredentials.email, + badCredentials.password + ]) + + const error = new Error() + + it('should reject signing in with invalid credentials', () => { + const sagaProcess = signInSaga() + + expect(sagaProcess.next().value).toEqual(take(SIGN_IN_REQUEST)) + + expect( + sagaProcess.next({ type: SIGN_IN_REQUEST, payload: badCredentials }) + .value + ).toEqual(user) + // expect(sagaProcess.next(user).value).toEqual( put({ type: SIGN_IN_ERROR, error })) + // приходит success, не понимаю как решать + // throw делает искусственную ошибку, а не сага сама + expect(sagaProcess.throw(error).value).toEqual( + put({ type: SIGN_IN_ERROR, error }) + ) + expect(sagaProcess.next().done).toEqual(false) + }) + + it('should limit attempts of invalid signing in', () => { + const sagaProcess = signInSaga() + + for (let i = 0; i < 3; i++) { + expect(sagaProcess.next().value).toEqual(take(SIGN_IN_REQUEST)) + + expect( + sagaProcess.next({ type: SIGN_IN_REQUEST, payload: badCredentials }) + .value + ).toEqual(user) + expect(sagaProcess.throw(error).value).toEqual( + put({ type: SIGN_IN_ERROR, error }) + ) + } + + expect(sagaProcess.next().value).toEqual( + put({ type: SIGN_IN_REQUESTS_LIMIT }) + ) + expect(sagaProcess.next().done).toEqual(true) + }) + + it('should reject attempts to sign up with existing credentials', () => { + const sagaProcess = signUpSaga({ + type: SIGN_UP_REQUEST, + payload: goodCredentials + }) + + const user = call( + [auth, auth.createUserWithEmailAndPassword], + goodCredentials.email, + goodCredentials.password + ) + + expect(sagaProcess.next().value).toEqual(user) + expect(sagaProcess.throw(error).value).toEqual( + put({ type: SIGN_UP_ERROR, error }) + ) + expect(sagaProcess.next().done).toEqual(true) + }) + }) +}) From 4d0d796d91f7a30a4a7ed3c3d510e47244b1635d Mon Sep 17 00:00:00 2001 From: omiceron Date: Mon, 21 May 2018 11:56:28 +0500 Subject: [PATCH 4/4] HT2: Firbase events implemented --- admin/src/App.js | 5 +++++ admin/src/redux/reducer.js | 4 +++- admin/src/redux/saga.js | 3 ++- admin/src/routes/admin.js | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/admin/src/App.js b/admin/src/App.js index 89f2dc0..160980f 100644 --- a/admin/src/App.js +++ b/admin/src/App.js @@ -13,6 +13,11 @@ class App extends Component { people +
+ + events + +
auth diff --git a/admin/src/redux/reducer.js b/admin/src/redux/reducer.js index f9c1879..7e88eca 100644 --- a/admin/src/redux/reducer.js +++ b/admin/src/redux/reducer.js @@ -3,10 +3,12 @@ import { routerReducer as router } from 'react-router-redux' import { reducer as form } from 'redux-form' import authReducer, { moduleName as authModule } from '../ducks/auth' import peopleReducer, { moduleName as peopleModule } from '../ducks/people' +import eventsReducer, { moduleName as eventsModule } from '../ducks/events' export default combineReducers({ router, form, [authModule]: authReducer, - [peopleModule]: peopleReducer + [peopleModule]: peopleReducer, + [eventsModule]: eventsReducer }) diff --git a/admin/src/redux/saga.js b/admin/src/redux/saga.js index 8f1e0cd..9d0ed64 100644 --- a/admin/src/redux/saga.js +++ b/admin/src/redux/saga.js @@ -1,7 +1,8 @@ import { all } from 'redux-saga/effects' import { saga as authSaga } from '../ducks/auth' import { saga as peopleSaga } from '../ducks/people' +import { saga as eventsSaga } from '../ducks/events' export default function*() { - yield all([authSaga(), peopleSaga()]) + yield all([authSaga(), peopleSaga(), eventsSaga()]) } diff --git a/admin/src/routes/admin.js b/admin/src/routes/admin.js index aa30167..75df8cd 100644 --- a/admin/src/routes/admin.js +++ b/admin/src/routes/admin.js @@ -1,6 +1,7 @@ import React, { Component } from 'react' import { Route } from 'react-router-dom' import PersonPage from './person-page' +import EventsPage from './events' class AdminPage extends Component { static propTypes = {} @@ -10,6 +11,7 @@ class AdminPage extends Component {

Admin Page

+
) }