mattermost-mobile/test/reducers/logout.test.js
Mike Piccolo 25f284a068 Add logout to the topnav (#45)
* WIP

* Remove session token after logout.

* Add logout reducer test

* Pop stack to login

* Use newProps and doFetchWithResponse

* Setup the reducers to clear the store
2016-10-20 11:49:03 -07:00

75 lines
2.2 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import assert from 'assert';
import reduceLogout, {initState} from 'reducers/logout';
import {LogoutTypes as types} from 'constants';
describe('logout reducer', () => {
describe('Init', () => {
let store;
let expectedStore;
before(() => {
store = reduceLogout(store, {type: ''});
expectedStore = {...initState};
});
it('should be initial state', () => {
assert.equal(typeof store, 'object');
});
it('have a specifc initial state', () => {
assert.deepEqual(store, expectedStore);
});
});
describe(`when ${types.LOGOUT_REQUEST}`, () => {
let store;
let expectedStore;
before(() => {
store = reduceLogout(store, {
type: types.LOGOUT_REQUEST
});
expectedStore = {
...initState,
status: 'fetching'
};
});
it('should set status to fetching', () => {
assert.deepEqual(store, expectedStore);
});
});
describe(`when ${types.LOGOUT_SUCCESS}`, () => {
let store;
let expectedStore;
before(() => {
store = reduceLogout(store, {
type: types.LOGOUT_SUCCESS
});
expectedStore = {
...initState,
status: 'fetched'
};
});
it('should set status to fetched and data', () => {
assert.deepEqual(store, expectedStore);
});
});
describe(`when ${types.LOGOUT_FAILURE}`, () => {
let store;
let error;
let expectedStore;
before(() => {
error = {id: 'the.error.id', message: 'Something went wrong'};
store = reduceLogout(store, {
type: types.LOGOUT_FAILURE,
error
});
expectedStore = {
...initState,
status: 'failed',
error
};
});
it('should set status to failed and error', () => {
assert.deepEqual(store, expectedStore);
});
});
});