auth.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { expect } from 'chai';
  2. import deepFreeze from 'deep-freeze';
  3. import {
  4. AUTH_USER,
  5. AUTH_RENEW,
  6. UNAUTH_USER,
  7. SENT_VERIFICATION
  8. } from '../../actions/actionTypes';
  9. import reducer from '../auth';
  10. describe('auth reducer', () => {
  11. const initialState = {
  12. isAuthenticated: false,
  13. sentVerification: false,
  14. user: '',
  15. renew: false
  16. };
  17. beforeEach(() => {
  18. deepFreeze(initialState);
  19. });
  20. it('should return the initial state', () => {
  21. expect(reducer(undefined, {})).to.deep.equal(initialState);
  22. });
  23. it('should handle AUTH_USER', () => {
  24. const user = 'test@user.com';
  25. const state = reducer(initialState, {
  26. type: AUTH_USER,
  27. payload: user
  28. });
  29. expect(state).not.to.be.undefined;
  30. expect(state.isAuthenticated).to.be.true;
  31. expect(state.user).to.be.equal(user);
  32. expect(state.sentVerification).to.be.false;
  33. });
  34. it('should handle AUTH_RENEW', () => {
  35. const state = reducer(initialState, {
  36. type: AUTH_RENEW
  37. });
  38. expect(state).not.to.be.undefined;
  39. expect(state.renew).to.be.true;
  40. });
  41. it('should handle UNAUTH_USER', () => {
  42. const state = reducer(initialState, {
  43. type: UNAUTH_USER
  44. });
  45. expect(state).not.to.be.undefined;
  46. expect(state).to.deep.equal(initialState);
  47. });
  48. it('should handle SENT_VERIFICATION', () => {
  49. const user = 'test@user.com';
  50. const state = reducer(initialState, {
  51. type: SENT_VERIFICATION,
  52. payload: user
  53. });
  54. expect(state).not.to.be.undefined;
  55. expect(state.sentVerification).to.be.true;
  56. expect(state.user).to.be.equal(user);
  57. });
  58. it('should not handle other action types', () => {
  59. const state = reducer(initialState, {
  60. type: 'ANOTHER_ACTION'
  61. });
  62. expect(state).not.to.be.undefined;
  63. expect(state).to.deep.equal(initialState);
  64. });
  65. });