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/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) 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) + }) + }) +}) 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

+
) }