Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Apr 7, 2017
1 parent 48b1243 commit 04a9915
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 217 deletions.
6 changes: 6 additions & 0 deletions client/components/form/components/TextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ function TextField({ input, label, meta: { touched, error }, ...custom }) {
)
}

TextField.propTypes = {
input: PropTypes.object.isRequired,
label: PropTypes.string.isRequired,
meta: PropTypes.object.isRequired
}

export default TextField
28 changes: 15 additions & 13 deletions client/components/password/sagas.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { call, put } from 'redux-saga/effects'
import { push } from 'connected-react-router'
import { takeLatest } from 'redux-saga'
import { endpoints } from '../../services/endpoints'
import post from '../../services/post'
import endpoints from '../../services/endpoints'
import api from '../../services/api'
import { actions as notificationActions } from '../notifications'
import { RESET_PASSWORD, REQUEST_RESET_PASSWORD } from './actionTypes'
import {
Expand All @@ -13,13 +13,14 @@ import {
} from './actions'

export function* resetPassword({ payload }) {
const { data, error } = yield call(post, endpoints.RESET_PASSWORD, { payload })
if (data) {
const endpoint = endpoints.constant.RESET_PASSWORD
const data = payload

try {
yield call(api.post, { endpoint, data })
yield put(resetPasswordSuccess())
yield put(push('/'))
} else if (error.errors) {
yield put(resetPasswordFailure(error.errors))
} else {
} catch (error) {
yield put(resetPasswordFailure(error))
}
}
Expand All @@ -29,14 +30,15 @@ export function* watchResetPassword() {
}

export function* requestResetPassword({ payload }) {
const { data, error } = yield call(post, endpoints.REQUEST_RESET_PASSWORD, { email: payload })
if (data) {
yield put(requestResetPasswordSuccess(data.token))
const endpoint = endpoints.constant.REQUEST_RESET_PASSWORD
const data = { email: payload }

try {
const response = yield call(api.post, { endpoint, data })
yield put(requestResetPasswordSuccess(response.token))
yield put(notificationActions.addNotification('Wachtwoord reset aangevraagd'))
yield put(push('/login'))
} else if (error.errors) {
yield put(requestResetPasswordFailure(error.errors))
} else {
} catch (error) {
yield put(requestResetPasswordFailure(error))
}
}
Expand Down
71 changes: 23 additions & 48 deletions client/components/password/sagas.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { call, put } from 'redux-saga/effects'
import { push } from 'connected-react-router'
import { takeLatest } from 'redux-saga'
import post from '../../services/post'
import api from '../../services/api'
import { actions as notificationActions } from '../notifications'
import { endpoints } from '../../services/endpoints'
import endpoints from '../../services/endpoints'
import * as actions from './actions'
import * as types from './actionTypes'
import * as sagas from './sagas'
Expand All @@ -19,65 +19,51 @@ describe('watchResetPassword', () => {
})

describe('resetPassword', () => {
const action = {
payload: 'payload'
}
const action = { payload: 'payload' }
const endpoint = endpoints.constant.RESET_PASSWORD
const data = action.payload

it('should post the password data', () => {
const generator = sagas.resetPassword(action)
const actual = generator.next().value
const expected = call(post, endpoints.RESET_PASSWORD, { payload: action.payload })
const expected = call(api.post, { endpoint, data })

expect(actual).toEqual(expected)
})

it('should put resetPasswordSuccess on success', () => {
const data = { token: 'token' }
const generator = sagas.resetPassword(action)
const expected = put(actions.resetPasswordSuccess())

generator.next()
const actual = generator.next({ data }).value
const actual = generator.next().value

expect(actual).toEqual(expected)
})

it('should redirect to home on success', () => {
const data = { token: 'token' }
const generator = sagas.resetPassword(action)
const expected = put(push('/'))

generator.next()
generator.next({ data })
const actual = generator.next().value

expect(actual).toEqual(expected)
})

it('should put resetPasswordFailure on api errors', () => {
const error = { errors: 'errors' }
const generator = sagas.resetPassword(action)
const expected = put(actions.resetPasswordFailure(error.errors))

generator.next()
const actual = generator.next({ error }).value
const actual = generator.next().value

expect(actual).toEqual(expected)
})

it('should put resetPasswordFailure on network errors', () => {
it('should put resetPasswordFailure on errors', () => {
const error = new Error('error')
const generator = sagas.resetPassword(action)
const expected = put(actions.resetPasswordFailure(error))

generator.next()
const actual = generator.next({ error }).value
const actual = generator.throw(error).value

expect(actual).toEqual(expected)
})
})


describe('watchRequestResetPassword', () => {
it('should respond to REQUEST_RESET_PASSWORD', () => {
const generator = sagas.watchRequestResetPassword()
Expand All @@ -89,72 +75,61 @@ describe('watchRequestResetPassword', () => {
})

describe('requestResetPassword', () => {
const action = {
payload: 'email'
}
const action = { payload: 'payload' }
const endpoint = endpoints.constant.REQUEST_RESET_PASSWORD
const data = { email: action.payload }

it('should post the email data', () => {
const generator = sagas.requestResetPassword(action)
const actual = generator.next().value
const expected = call(post, endpoints.REQUEST_RESET_PASSWORD, { email: action.payload })
const expected = call(api.post, { endpoint, data })

expect(actual).toEqual(expected)
})

it('should put requestResetPasswordSuccess on success', () => {
const data = { token: 'token' }
const response = { token: 'token' }
const generator = sagas.requestResetPassword(action)
const expected = put(actions.requestResetPasswordSuccess(data.token))
const expected = put(actions.requestResetPasswordSuccess(response.token))

generator.next()
const actual = generator.next({ data }).value
const actual = generator.next(response).value

expect(actual).toEqual(expected)
})

it('should put addNotification on success', () => {
const data = { token: 'token' }
const response = { token: 'token' }
const generator = sagas.requestResetPassword(action)
const expected = put(notificationActions.addNotification('Wachtwoord reset aangevraagd'))

generator.next()
generator.next({ data })
generator.next(response)
const actual = generator.next().value

expect(actual).toEqual(expected)
})

it('should redirect on success', () => {
const data = { token: 'token' }
const response = { token: 'token' }
const generator = sagas.requestResetPassword(action)
const expected = put(push('/login'))

generator.next()
generator.next({ data })
generator.next(response)
generator.next()
const actual = generator.next().value

expect(actual).toEqual(expected)
})

it('should put requestResetPasswordFailure on api errors', () => {
const error = { errors: 'errors' }
const generator = sagas.requestResetPassword(action)
const expected = put(actions.requestResetPasswordFailure(error.errors))

generator.next()
const actual = generator.next({ error }).value

expect(actual).toEqual(expected)
})

it('should put requestResetPasswordFailure on network errors', () => {
it('should put requestResetPasswordFailure on errors', () => {
const error = new Error('error')
const generator = sagas.requestResetPassword(action)
const expected = put(actions.requestResetPasswordFailure(error))

generator.next()
const actual = generator.next({ error }).value
const actual = generator.throw(error).value

expect(actual).toEqual(expected)
})
Expand Down
32 changes: 16 additions & 16 deletions client/components/profile/sagas.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { call, put, select } from 'redux-saga/effects'
import { takeLatest } from 'redux-saga'
import { selectors as sessionSelectors } from '../../data/session'
import get from '../../services/get'
import putService from '../../services/put'
import { endpoints } from '../../services/endpoints'
import api from '../../services/api'
import endpoints from '../../services/endpoints'
import * as actions from './actions'
import * as types from './actionTypes'

export function* fetchProfile() {
const token = yield select(sessionSelectors.getToken)
const { data, error } = yield call(get, endpoints.PROFILE, token)
if (data) {
yield put(actions.fetchProfileSuccess(data.data))
} else if (error.errors) {
yield put(actions.fetchProfileFailure(error.errors))
} else {
const endpoint = endpoints.constant.PROFILE

try {
const token = yield select(sessionSelectors.getToken)
const response = yield call(api.get, { endpoint, token })
yield put(actions.fetchProfileSuccess(response.data))
} catch (error) {
yield put(actions.fetchProfileFailure(error))
}
}
Expand All @@ -24,13 +23,14 @@ export function* watchFetchProfile() {
}

export function* updateProfile({ payload }) {
const token = yield select(sessionSelectors.getToken)
const { data, error } = yield call(putService, endpoints.user(payload.id), payload, token)
if (data) {
const endpoint = endpoints.dynamic.user(payload.id)
const data = payload

try {
const token = yield select(sessionSelectors.getToken)
yield call(api.put, { endpoint, data, token })
yield put(actions.updateProfileSuccess())
} else if (error.errors) {
yield put(actions.updateProfileFailure(error.errors))
} else {
} catch (error) {
yield put(actions.updateProfileFailure(error))
}
}
Expand Down
Loading

0 comments on commit 04a9915

Please sign in to comment.