diff --git a/src/reducers/index.js b/src/reducers/index.js index feaf6d5d..51b95d8c 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,5 +1,5 @@ import { combineReducers } from 'redux'; -import serversReducer from '../servers/reducers/server'; +import serversReducer from '../servers/reducers/servers'; import selectedServerReducer from '../servers/reducers/selectedServer'; import shortUrlsListReducer from '../short-urls/reducers/shortUrlsList'; import shortUrlsListParamsReducer from '../short-urls/reducers/shortUrlsListParams'; diff --git a/src/servers/reducers/server.js b/src/servers/reducers/servers.js similarity index 83% rename from src/servers/reducers/server.js rename to src/servers/reducers/servers.js index d703ce11..41027c69 100644 --- a/src/servers/reducers/server.js +++ b/src/servers/reducers/servers.js @@ -3,21 +3,21 @@ import { pipe, isEmpty, assoc, map, prop } from 'ramda'; import { v4 as uuid } from 'uuid'; import { homepage } from '../../../package.json'; -export const FETCH_SERVERS = 'shlink/servers/FETCH_SERVERS'; +export const LIST_SERVERS = 'shlink/servers/LIST_SERVERS'; const initialState = {}; const assocId = (server) => assoc('id', server.id || uuid(), server); export default handleActions({ - [FETCH_SERVERS]: (state, { list }) => list, + [LIST_SERVERS]: (state, { list }) => list, }, initialState); export const listServers = ({ listServers, createServers }, { get }) => () => async (dispatch) => { const localList = listServers(); if (!isEmpty(localList)) { - dispatch({ type: FETCH_SERVERS, list: localList }); + dispatch({ type: LIST_SERVERS, list: localList }); return; } @@ -39,7 +39,7 @@ export const listServers = ({ listServers, createServers }, { get }) => () => as .catch(() => []); createServers(remoteList); - dispatch({ type: FETCH_SERVERS, list: remoteList.reduce((map, server) => ({ ...map, [server.id]: server }), {}) }); + dispatch({ type: LIST_SERVERS, list: remoteList.reduce((map, server) => ({ ...map, [server.id]: server }), {}) }); }; export const createServer = ({ createServer }, listServersAction) => pipe(createServer, listServersAction); diff --git a/src/servers/services/provideServices.js b/src/servers/services/provideServices.js index ce325ffd..fd3fcec7 100644 --- a/src/servers/services/provideServices.js +++ b/src/servers/services/provideServices.js @@ -6,7 +6,7 @@ import DeleteServerButton from '../DeleteServerButton'; import { EditServer } from '../EditServer'; import ImportServersBtn from '../helpers/ImportServersBtn'; import { resetSelectedServer, selectServer } from '../reducers/selectedServer'; -import { createServer, createServers, deleteServer, editServer, listServers } from '../reducers/server'; +import { createServer, createServers, deleteServer, editServer, listServers } from '../reducers/servers'; import ForServerVersion from '../helpers/ForServerVersion'; import { ServerError } from '../helpers/ServerError'; import ServersImporter from './ServersImporter'; diff --git a/test/servers/reducers/server.test.js b/test/servers/reducers/server.test.js index 73d6dd83..2a68bbce 100644 --- a/test/servers/reducers/server.test.js +++ b/test/servers/reducers/server.test.js @@ -5,15 +5,15 @@ import reducer, { listServers, createServers, editServer, - FETCH_SERVERS, -} from '../../../src/servers/reducers/server'; + LIST_SERVERS, +} from '../../../src/servers/reducers/servers'; describe('serverReducer', () => { const list = { abc123: { id: 'abc123' }, def456: { id: 'def456' }, }; - const expectedFetchServersResult = { type: FETCH_SERVERS, list }; + const expectedFetchServersResult = { type: LIST_SERVERS, list }; const ServersServiceMock = { listServers: jest.fn(() => list), createServer: jest.fn(), @@ -25,8 +25,8 @@ describe('serverReducer', () => { afterEach(jest.clearAllMocks); describe('reducer', () => { - it('returns servers when action is FETCH_SERVERS', () => - expect(reducer({}, { type: FETCH_SERVERS, list })).toEqual(list)); + it('returns servers when action is LIST_SERVERS', () => + expect(reducer({}, { type: LIST_SERVERS, list })).toEqual(list)); }); describe('action creators', () => { @@ -89,7 +89,7 @@ describe('serverReducer', () => { await listServers(NoListServersServiceMock, axios)()(dispatch); expect(dispatch).toHaveBeenCalledTimes(1); - expect(dispatch).toHaveBeenNthCalledWith(1, { type: FETCH_SERVERS, list: expectedList }); + expect(dispatch).toHaveBeenNthCalledWith(1, { type: LIST_SERVERS, list: expectedList }); expect(NoListServersServiceMock.listServers).toHaveBeenCalledTimes(1); expect(NoListServersServiceMock.createServer).not.toHaveBeenCalled(); expect(NoListServersServiceMock.editServer).not.toHaveBeenCalled();