add SET_ROOMS dispatch
This commit is contained in:
parent
36eeb8202b
commit
5a7f3bc177
4 changed files with 43 additions and 2 deletions
|
@ -4,7 +4,7 @@ import type { state } from '../stateReducer';
|
||||||
|
|
||||||
export const initState = (): state => {
|
export const initState = (): state => {
|
||||||
return {
|
return {
|
||||||
user: null,
|
user: {},
|
||||||
errors: null
|
errors: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
// @flow
|
||||||
|
import type { state, action } from '../stateReducer';
|
||||||
|
|
||||||
|
export const roomsReducer = (state: state, action: action):state => {
|
||||||
|
switch(action.message) {
|
||||||
|
|
||||||
|
case 'SET_ROOMS':
|
||||||
|
const rooms = roomsParse(action.body);
|
||||||
|
return {...state, rooms};
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function roomsParse(roomsData) {
|
||||||
|
const rooms = JSON.parse(roomsData);
|
||||||
|
return rooms
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import {stateReducer} from '../stateReducer';
|
||||||
|
import { initState } from '../init/stateReducer.init';
|
||||||
|
|
||||||
|
const roomsData = [
|
||||||
|
{
|
||||||
|
description: "A general place to play Go",
|
||||||
|
id: 1,
|
||||||
|
language: "EN",
|
||||||
|
name: "main"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
it('default returns state with rooms added', () => {
|
||||||
|
const state = initState();
|
||||||
|
const action = {type: 'ROOMS', message: 'SET_ROOMS', body: JSON.stringify(roomsData)};
|
||||||
|
expect(stateReducer(state, action)).toEqual({...state, rooms: roomsData});
|
||||||
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { initState } from './init/stateReducer.init';
|
||||||
import { authReducer } from './auth/stateReducer.auth';
|
import { authReducer } from './auth/stateReducer.auth';
|
||||||
import { errorReducer } from './err/stateReducer.err';
|
import { errorReducer } from './err/stateReducer.err';
|
||||||
import { indexReducer } from './index/stateReducer.index';
|
import { indexReducer } from './index/stateReducer.index';
|
||||||
|
import { roomsReducer } from './rooms/stateReducer.rooms';
|
||||||
|
|
||||||
export type state = {
|
export type state = {
|
||||||
user: {},
|
user: {},
|
||||||
|
@ -27,6 +28,9 @@ export const stateReducer = (state: state, action: action): state => {
|
||||||
case 'INDEX':
|
case 'INDEX':
|
||||||
return indexReducer(errorStrippedState, action);
|
return indexReducer(errorStrippedState, action);
|
||||||
|
|
||||||
|
case 'ROOMS':
|
||||||
|
return roomsReducer(errorStrippedState, action);
|
||||||
|
|
||||||
case 'ERR':
|
case 'ERR':
|
||||||
return errorReducer(errorStrippedState, action);
|
return errorReducer(errorStrippedState, action);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue