-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oleh T
committed
Jun 13, 2018
1 parent
3475e14
commit 9946616
Showing
6 changed files
with
716 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.next/ | ||
flow-typed/ | ||
node_modules/ | ||
node_modules/ | ||
client/**/__test__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { expect } from 'chai'; | ||
import deepFreeze from 'deep-freeze'; | ||
|
||
import { | ||
AUTH_USER, | ||
AUTH_RENEW, | ||
UNAUTH_USER, | ||
SENT_VERIFICATION | ||
} from '../../actions/actionTypes'; | ||
|
||
import reducer from '../auth'; | ||
|
||
describe('auth reducer', () => { | ||
const initialState = { | ||
isAuthenticated: false, | ||
sentVerification: false, | ||
user: '', | ||
renew: false | ||
}; | ||
|
||
beforeEach(() => { | ||
deepFreeze(initialState); | ||
}); | ||
|
||
it('should return the initial state', () => { | ||
expect(reducer(undefined, {})).to.deep.equal(initialState); | ||
}); | ||
|
||
it('should handle AUTH_USER', () => { | ||
const user = 'test@user.com'; | ||
|
||
const state = reducer(initialState, { | ||
type: AUTH_USER, | ||
payload: user | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.isAuthenticated).to.be.true; | ||
expect(state.user).to.be.equal(user); | ||
expect(state.sentVerification).to.be.false; | ||
}); | ||
|
||
it('should handle AUTH_RENEW', () => { | ||
const state = reducer(initialState, { | ||
type: AUTH_RENEW | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.renew).to.be.true; | ||
}); | ||
|
||
it('should handle UNAUTH_USER', () => { | ||
const state = reducer(initialState, { | ||
type: UNAUTH_USER | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state).to.deep.equal(initialState); | ||
}); | ||
|
||
it('should handle SENT_VERIFICATION', () => { | ||
const user = 'test@user.com'; | ||
|
||
const state = reducer(initialState, { | ||
type: SENT_VERIFICATION, | ||
payload: user | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.sentVerification).to.be.true; | ||
expect(state.user).to.be.equal(user); | ||
}); | ||
|
||
it('should not handle other action types', () => { | ||
const state = reducer(initialState, { | ||
type: 'ANOTHER_ACTION' | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state).to.deep.equal(initialState); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { expect } from 'chai'; | ||
import deepFreeze from 'deep-freeze'; | ||
|
||
import { | ||
SHORTENER_ERROR, | ||
DOMAIN_ERROR, | ||
SET_DOMAIN, | ||
SHOW_DOMAIN_INPUT, | ||
ADD_URL, | ||
UPDATE_URL, | ||
AUTH_ERROR, | ||
AUTH_USER, | ||
HIDE_PAGE_LOADING | ||
} from '../../actions/actionTypes'; | ||
|
||
import reducer from '../error'; | ||
|
||
describe('error reducer', () => { | ||
const initialState = { | ||
auth: '', | ||
domain: '', | ||
shortener: '', | ||
urlOptions: '' | ||
}; | ||
|
||
beforeEach(() => { | ||
deepFreeze(initialState); | ||
}); | ||
|
||
it('should return the initial state', () => { | ||
expect(reducer(undefined, {})).to.deep.equal(initialState); | ||
}); | ||
|
||
it('should handle SHORTENER_ERROR', () => { | ||
const error = 'SHORTENER_ERROR'; | ||
|
||
const state = reducer(initialState, { | ||
type: SHORTENER_ERROR, | ||
payload: error | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.shortener).to.be.equal(error); | ||
}); | ||
|
||
it('should handle DOMAIN_ERROR', () => { | ||
const error = 'DOMAIN_ERROR'; | ||
|
||
const state = reducer(initialState, { | ||
type: DOMAIN_ERROR, | ||
payload: error | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.domain).to.be.equal(error); | ||
}); | ||
|
||
it('should handle SET_DOMAIN', () => { | ||
const state = reducer(initialState, { | ||
type: SET_DOMAIN | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.domain).to.be.empty; | ||
}); | ||
|
||
it('should handle SHOW_DOMAIN_INPUT', () => { | ||
const state = reducer(initialState, { | ||
type: SHOW_DOMAIN_INPUT | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.domain).to.be.empty; | ||
}); | ||
|
||
it('should handle ADD_URL', () => { | ||
const state = reducer(initialState, { | ||
type: ADD_URL | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.shortener).to.be.empty; | ||
}); | ||
|
||
it('should handle UPDATE_URL', () => { | ||
const state = reducer(initialState, { | ||
type: UPDATE_URL | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.urlOptions).to.be.empty; | ||
}); | ||
|
||
it('should handle AUTH_ERROR', () => { | ||
const error = 'AUTH_ERROR'; | ||
|
||
const state = reducer(initialState, { | ||
type: AUTH_ERROR, | ||
payload: error | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.auth).to.be.equal(error); | ||
}); | ||
|
||
it('should handle AUTH_USER', () => { | ||
const state = reducer(initialState, { | ||
type: AUTH_USER | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.auth).to.be.empty; | ||
}); | ||
|
||
it('should handle HIDE_PAGE_LOADING', () => { | ||
const state = reducer(initialState, { | ||
type: HIDE_PAGE_LOADING | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state.auth).to.be.empty; | ||
expect(state.shortener).to.be.empty; | ||
expect(state.urlOptions).to.be.empty; | ||
}); | ||
|
||
it('should not handle other action types', () => { | ||
const state = reducer(initialState, { | ||
type: 'ANOTHER_ACTION' | ||
}); | ||
|
||
expect(state).not.to.be.undefined; | ||
expect(state).to.deep.equal(initialState); | ||
}); | ||
}); |
Oops, something went wrong.