Skip to content

Commit

Permalink
fix(mvp/test): convert serialized Uint8Arrays from redux-test-recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
n0izn0iz committed Feb 5, 2020
1 parent 69cf59f commit 7261092
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion js/packages/store/chat/account.ts
Expand Up @@ -100,6 +100,19 @@ const commandHandler = createSlice<State, CommandsReducer>({
},
})

const intoBuffer = (
thing: Buffer | Uint8Array | { [key: string]: number } | { [key: number]: number },
): Buffer => {
// redux-test-recorder f up the Uint8Arrays so we have to use this monster
if (thing instanceof Buffer) {
return thing
}
if (thing instanceof Uint8Array) {
return Buffer.from(thing)
}
return Buffer.from(Object.values(thing))
}

const eventHandler = createSlice<State, EventsReducer>({
name: 'chat/account/event',
initialState,
Expand Down Expand Up @@ -133,7 +146,7 @@ const eventHandler = createSlice<State, EventsReducer>({
extraReducers: {
[protocol.events.client.contactRequestReferenceUpdated.type]: (state, { payload }) => {
if (state.aggregates[payload.aggregateId]) {
state.aggregates[payload.aggregateId].contactRequestReference = Buffer.from(
state.aggregates[payload.aggregateId].contactRequestReference = intoBuffer(
payload.reference,
).toString('base64')
}
Expand Down

0 comments on commit 7261092

Please sign in to comment.