diff --git a/packages/server/packages/play-node-go/play-node-go/src/reducers/init/stateReducer.init.js b/packages/server/packages/play-node-go/play-node-go/src/reducers/init/stateReducer.init.js index 88cb470..1780d36 100644 --- a/packages/server/packages/play-node-go/play-node-go/src/reducers/init/stateReducer.init.js +++ b/packages/server/packages/play-node-go/play-node-go/src/reducers/init/stateReducer.init.js @@ -4,7 +4,7 @@ import type { state } from '../stateReducer'; export const initState = (): state => { return { - user: null, - errors: null + user: {}, + errors: {} }; } \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/reducers/rooms/stateReducer.rooms.js b/packages/server/packages/play-node-go/play-node-go/src/reducers/rooms/stateReducer.rooms.js new file mode 100644 index 0000000..bfc07b3 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/reducers/rooms/stateReducer.rooms.js @@ -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 +} \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/reducers/rooms/stateReducer.rooms.test.js b/packages/server/packages/play-node-go/play-node-go/src/reducers/rooms/stateReducer.rooms.test.js new file mode 100644 index 0000000..caf1a6f --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/reducers/rooms/stateReducer.rooms.test.js @@ -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}); +}); + diff --git a/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.js b/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.js index 75c9b1c..7290e03 100644 --- a/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.js +++ b/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.js @@ -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);