add SET_ROOMS dispatch

This commit is contained in:
Sorrel Bri 2020-01-18 16:17:23 -08:00
parent 048f518114
commit 03648fcf3f
4 changed files with 43 additions and 2 deletions

View file

@ -4,7 +4,7 @@ import type { state } from '../stateReducer';
export const initState = (): state => {
return {
user: null,
errors: null
user: {},
errors: {}
};
}

View file

@ -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
}

View file

@ -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});
});

View file

@ -3,6 +3,7 @@ import { initState } from './init/stateReducer.init';
import { authReducer } from './auth/stateReducer.auth';
import { errorReducer } from './err/stateReducer.err';
import { indexReducer } from './index/stateReducer.index';
import { roomsReducer } from './rooms/stateReducer.rooms';
export type state = {
user: {},
@ -27,6 +28,9 @@ export const stateReducer = (state: state, action: action): state => {
case 'INDEX':
return indexReducer(errorStrippedState, action);
case 'ROOMS':
return roomsReducer(errorStrippedState, action);
case 'ERR':
return errorReducer(errorStrippedState, action);