From 6f67f7bbf0374aef5b4ee7538ab2cc312dbc2b6b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 5 Nov 2022 09:40:12 +0100 Subject: [PATCH] Removed redundant createServer action, leaving just createServers --- src/servers/CreateServer.tsx | 6 +++--- src/servers/reducers/servers.ts | 2 -- src/servers/services/provideServices.ts | 5 ++--- test/servers/CreateServer.test.tsx | 12 ++++++------ test/servers/reducers/servers.test.ts | 10 ---------- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/servers/CreateServer.tsx b/src/servers/CreateServer.tsx index df96e838..4ffd93ea 100644 --- a/src/servers/CreateServer.tsx +++ b/src/servers/CreateServer.tsx @@ -13,7 +13,7 @@ import { DuplicatedServersModal } from './helpers/DuplicatedServersModal'; const SHOW_IMPORT_MSG_TIME = 4000; interface CreateServerProps { - createServer: (server: ServerWithId) => void; + createServers: (servers: ServerWithId[]) => void; servers: ServersMap; } @@ -27,7 +27,7 @@ const ImportResult = ({ type }: { type: 'error' | 'success' }) => ( ); export const CreateServer = (ImportServersBtn: FC, useTimeoutToggle: TimeoutToggle) => ( - { servers, createServer }: CreateServerProps, + { servers, createServers }: CreateServerProps, ) => { const navigate = useNavigate(); const goBack = useGoBack(); @@ -43,7 +43,7 @@ export const CreateServer = (ImportServersBtn: FC, useTim const id = uuid(); - createServer({ ...serverData, id }); + createServers([{ ...serverData, id }]); navigate(`/server/${id}`); }; diff --git a/src/servers/reducers/servers.ts b/src/servers/reducers/servers.ts index 2f0a5057..872c450e 100644 --- a/src/servers/reducers/servers.ts +++ b/src/servers/reducers/servers.ts @@ -66,8 +66,6 @@ export const createServers = pipe( (newServers: ServersMap) => ({ type: CREATE_SERVERS, payload: newServers }), ); -export const createServer = (server: ServerWithId) => createServers([server]); - export const editServer = (serverId: string, serverData: Partial) => ({ type: EDIT_SERVER, payload: { serverId, serverData }, diff --git a/src/servers/services/provideServices.ts b/src/servers/services/provideServices.ts index 6f56cc84..f6e03f88 100644 --- a/src/servers/services/provideServices.ts +++ b/src/servers/services/provideServices.ts @@ -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, setAutoConnect } from '../reducers/servers'; +import { createServers, deleteServer, editServer, setAutoConnect } from '../reducers/servers'; import { fetchServers } from '../reducers/remoteServers'; import { ServerError } from '../helpers/ServerError'; import { ConnectDecorator } from '../../container/types'; @@ -38,7 +38,7 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => { bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn', 'useTimeoutToggle'); bottle.decorator('CreateServer', withoutSelectedServer); - bottle.decorator('CreateServer', connect(['selectedServer', 'servers'], ['createServer', 'resetSelectedServer'])); + bottle.decorator('CreateServer', connect(['selectedServer', 'servers'], ['createServers', 'resetSelectedServer'])); bottle.serviceFactory('EditServer', EditServer, 'ServerError'); bottle.decorator('EditServer', connect(['selectedServer'], ['editServer', 'selectServer', 'resetSelectedServer'])); @@ -70,7 +70,6 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => { // Actions bottle.serviceFactory('selectServer', selectServer, 'buildShlinkApiClient', 'loadMercureInfo'); - bottle.serviceFactory('createServer', () => createServer); bottle.serviceFactory('createServers', () => createServers); bottle.serviceFactory('deleteServer', () => deleteServer); bottle.serviceFactory('editServer', () => editServer); diff --git a/test/servers/CreateServer.test.tsx b/test/servers/CreateServer.test.tsx index dd559dc3..a5cbc674 100644 --- a/test/servers/CreateServer.test.tsx +++ b/test/servers/CreateServer.test.tsx @@ -8,7 +8,7 @@ import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); describe('', () => { - const createServerMock = jest.fn(); + const createServersMock = jest.fn(); const navigate = jest.fn(); const servers = { foo: Mock.of({ url: 'https://existing_url.com', apiKey: 'existing_api_key' }) }; const setUp = (serversImported = false, importFailed = false) => { @@ -22,7 +22,7 @@ describe('', () => { }); const CreateServer = createCreateServer(() => <>ImportServersBtn, useTimeoutToggle); - return renderWithEvents(); + return renderWithEvents(); }; beforeEach(jest.clearAllMocks); @@ -48,18 +48,18 @@ describe('', () => { it('creates server data when form is submitted', async () => { const { user } = setUp(); - expect(createServerMock).not.toHaveBeenCalled(); + expect(createServersMock).not.toHaveBeenCalled(); await user.type(screen.getByLabelText(/^Name/), 'the_name'); await user.type(screen.getByLabelText(/^URL/), 'https://the_url.com'); await user.type(screen.getByLabelText(/^API key/), 'the_api_key'); fireEvent.submit(screen.getByRole('form')); - expect(createServerMock).toHaveBeenCalledWith(expect.objectContaining({ + expect(createServersMock).toHaveBeenCalledWith([expect.objectContaining({ name: 'the_name', url: 'https://the_url.com', apiKey: 'the_api_key', - })); + })]); expect(navigate).toHaveBeenCalledWith(expect.stringMatching(/^\/server\//)); expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); }); @@ -75,7 +75,7 @@ describe('', () => { await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument()); await user.click(screen.getByRole('button', { name: 'Discard' })); - expect(createServerMock).not.toHaveBeenCalled(); + expect(createServersMock).not.toHaveBeenCalled(); expect(navigate).toHaveBeenCalledWith(-1); }); }); diff --git a/test/servers/reducers/servers.test.ts b/test/servers/reducers/servers.test.ts index 11f36655..c24ef6aa 100644 --- a/test/servers/reducers/servers.test.ts +++ b/test/servers/reducers/servers.test.ts @@ -1,7 +1,6 @@ import { dissoc, values } from 'ramda'; import { Mock } from 'ts-mockery'; import reducer, { - createServer, deleteServer, createServers, editServer, @@ -104,15 +103,6 @@ describe('serversReducer', () => { }); describe('action creators', () => { - describe('createServer', () => { - it('returns expected action', () => { - const serverToCreate = Mock.of({ id: 'abc123' }); - const result = createServer(serverToCreate); - - expect(result).toEqual(expect.objectContaining({ type: CREATE_SERVERS })); - }); - }); - describe('editServer', () => { it('returns expected action', () => { const serverData = { name: 'edited' };