diff --git a/src/servers/reducers/selectedServer.ts b/src/servers/reducers/selectedServer.ts index b33f344d..78c0d69d 100644 --- a/src/servers/reducers/selectedServer.ts +++ b/src/servers/reducers/selectedServer.ts @@ -1,3 +1,4 @@ +import { PayloadAction } from '@reduxjs/toolkit'; import { identity, memoizeWith, pipe } from 'ramda'; import { Action, Dispatch } from 'redux'; import { versionToPrintable, versionToSemVer as toSemVer } from '../../utils/helpers/version'; @@ -14,9 +15,7 @@ export const MIN_FALLBACK_VERSION = '1.0.0'; export const MAX_FALLBACK_VERSION = '999.999.999'; export const LATEST_VERSION_CONSTRAINT = 'latest'; -export interface SelectServerAction extends Action { - selectedServer: SelectedServer; -} +export type SelectServerAction = PayloadAction; const versionToSemVer = pipe( (version: string) => (version === LATEST_VERSION_CONSTRAINT ? MAX_FALLBACK_VERSION : version), @@ -35,7 +34,7 @@ const initialState: SelectedServer = null; export default buildReducer({ [RESET_SELECTED_SERVER]: () => initialState, - [SELECT_SERVER]: (_, { selectedServer }) => selectedServer, + [SELECT_SERVER]: (_, { payload }) => payload, }, initialState); export const resetSelectedServer = buildActionCreator(RESET_SELECTED_SERVER); @@ -57,7 +56,7 @@ export const selectServer = ( if (!selectedServer) { dispatch({ type: SELECT_SERVER, - selectedServer: { serverNotFound: true }, + payload: { serverNotFound: true }, }); return; @@ -69,7 +68,7 @@ export const selectServer = ( dispatch({ type: SELECT_SERVER, - selectedServer: { + payload: { ...selectedServer, version, printableVersion, @@ -79,7 +78,7 @@ export const selectServer = ( } catch (e) { dispatch({ type: SELECT_SERVER, - selectedServer: { ...selectedServer, serverNotReachable: true }, + payload: { ...selectedServer, serverNotReachable: true }, }); } }; diff --git a/test/servers/reducers/selectedServer.test.ts b/test/servers/reducers/selectedServer.test.ts index 2074bcd3..28c443ae 100644 --- a/test/servers/reducers/selectedServer.test.ts +++ b/test/servers/reducers/selectedServer.test.ts @@ -14,12 +14,12 @@ import { NonReachableServer, NotFoundServer, RegularServer } from '../../../src/ describe('selectedServerReducer', () => { describe('reducer', () => { it('returns default when action is RESET_SELECTED_SERVER', () => - expect(reducer(null, { type: RESET_SELECTED_SERVER, selectedServer: null })).toBeNull()); + expect(reducer(null, { type: RESET_SELECTED_SERVER, payload: null })).toBeNull()); it('returns selected server when action is SELECT_SERVER', () => { - const selectedServer = Mock.of({ id: 'abc123' }); + const payload = Mock.of({ id: 'abc123' }); - expect(reducer(null, { type: SELECT_SERVER, selectedServer })).toEqual(selectedServer); + expect(reducer(null, { type: SELECT_SERVER, payload })).toEqual(payload); }); });