declare const global: any import { expect } from 'chai' import { accessToken } from '../../../js/modules/auth/reducer' import * as authActions from '../../../js/modules/auth/actions' import { LoginStatus }from '../../../js/modules/auth/interfaces' import * as chrome from 'sinon-chrome' describe('reducers', () => { before(() => { global.chrome = chrome }) describe('auth', () => { it('should provide the initial state', () => { expect(accessToken(null, { type: 'unknown' })).to.equal(null) }) it('should handle SET_TOKEN', () => { expect(accessToken(null, authActions.submitLoginSuccess({ token: 'test_token', username: 'test@drift.com' }))).to.deep.equal({ token: 'test_token', status: LoginStatus.SUCCESS }) }) it('should handle SUBMIT_LOGIN_PENDING', () => { expect(accessToken(null, authActions.submitLoginPending())).to.deep.equal({ status: LoginStatus.PENDING }) expect(accessToken({ status: LoginStatus.PENDING }, authActions.submitLoginSuccess({ token: 'test_token', username: 'test@drift.com' }))).to.deep.equal({ token: 'test_token', status: LoginStatus.SUCCESS }) }) it('should handle SUBMIT_LOGIN_PENDING', () => { expect(accessToken(null, authActions.submitLoginFailed())).to.deep.equal({ status: LoginStatus.FAILED }) expect(accessToken({ status: LoginStatus.FAILED }, authActions.submitLoginSuccess({ token: 'test_token', username: 'test@drift.com' }))).to.deep.equal({ token: 'test_token', status: LoginStatus.SUCCESS }) }) it('should ignore unknown actions', () => { expect(accessToken({ token: 'test_token', status: LoginStatus.SUCCESS }, { type: 'unknown' })).to.deep.equal({ token: 'test_token', status: LoginStatus.SUCCESS }) }) }) })