Skip to content

Commit

Permalink
Added tests and update ignore rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleh T committed Jun 13, 2018
1 parent 3475e14 commit 9946616
Show file tree
Hide file tree
Showing 6 changed files with 716 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.next/
flow-typed/
node_modules/
node_modules/
client/**/__test__/
82 changes: 82 additions & 0 deletions client/reducers/__test__/auth.js
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);
});
});
134 changes: 134 additions & 0 deletions client/reducers/__test__/error.js
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);
});
});
Loading

0 comments on commit 9946616

Please sign in to comment.