mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 18:27:25 +03:00
Removed direct calls between actions without DI
This commit is contained in:
parent
4f8c7afc76
commit
1aa1d29d97
3 changed files with 33 additions and 35 deletions
|
@ -14,23 +14,20 @@ export const listServers = (serversService) => () => ({
|
||||||
servers: serversService.listServers(),
|
servers: serversService.listServers(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME listServers action should be injected and not directly invoked
|
export const createServer = (serversService, listServers) => (server) => {
|
||||||
export const createServer = (serversService) => (server) => {
|
|
||||||
serversService.createServer(server);
|
serversService.createServer(server);
|
||||||
|
|
||||||
return listServers(serversService)();
|
return listServers();
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME listServers action should be injected and not directly invoked
|
export const deleteServer = (serversService, listServers) => (server) => {
|
||||||
export const deleteServer = (serversService) => (server) => {
|
|
||||||
serversService.deleteServer(server);
|
serversService.deleteServer(server);
|
||||||
|
|
||||||
return listServers(serversService)();
|
return listServers();
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME listServers action should be injected and not directly invoked
|
export const createServers = (serversService, listServers) => (servers) => {
|
||||||
export const createServers = (serversService) => (servers) => {
|
|
||||||
serversService.createServers(servers);
|
serversService.createServers(servers);
|
||||||
|
|
||||||
return listServers(serversService)();
|
return listServers();
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,9 +35,9 @@ const provideServices = (bottle, connect, withRouter) => {
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
bottle.serviceFactory('selectServer', selectServer, 'ServersService');
|
bottle.serviceFactory('selectServer', selectServer, 'ServersService');
|
||||||
bottle.serviceFactory('createServer', createServer, 'ServersService');
|
bottle.serviceFactory('createServer', createServer, 'ServersService', 'listServers');
|
||||||
bottle.serviceFactory('createServers', createServers, 'ServersService');
|
bottle.serviceFactory('createServers', createServers, 'ServersService', 'listServers');
|
||||||
bottle.serviceFactory('deleteServer', deleteServer, 'ServersService');
|
bottle.serviceFactory('deleteServer', deleteServer, 'ServersService', 'listServers');
|
||||||
bottle.serviceFactory('listServers', listServers, 'ServersService');
|
bottle.serviceFactory('listServers', listServers, 'ServersService');
|
||||||
|
|
||||||
bottle.serviceFactory('resetSelectedServer', () => resetSelectedServer);
|
bottle.serviceFactory('resetSelectedServer', () => resetSelectedServer);
|
||||||
|
|
|
@ -13,6 +13,7 @@ describe('serverReducer', () => {
|
||||||
abc123: { id: 'abc123' },
|
abc123: { id: 'abc123' },
|
||||||
def456: { id: 'def456' },
|
def456: { id: 'def456' },
|
||||||
};
|
};
|
||||||
|
const expectedFetchServersResult = { type: FETCH_SERVERS, servers };
|
||||||
const ServersServiceMock = {
|
const ServersServiceMock = {
|
||||||
listServers: sinon.fake.returns(servers),
|
listServers: sinon.fake.returns(servers),
|
||||||
createServer: sinon.fake(),
|
createServer: sinon.fake(),
|
||||||
|
@ -40,38 +41,38 @@ describe('serverReducer', () => {
|
||||||
it('fetches servers and returns them as part of the action', () => {
|
it('fetches servers and returns them as part of the action', () => {
|
||||||
const result = listServers(ServersServiceMock)();
|
const result = listServers(ServersServiceMock)();
|
||||||
|
|
||||||
expect(result).toEqual({ type: FETCH_SERVERS, servers });
|
expect(result).toEqual(expectedFetchServersResult);
|
||||||
expect(ServersServiceMock.listServers.callCount).toEqual(1);
|
expect(ServersServiceMock.listServers.calledOnce).toEqual(true);
|
||||||
expect(ServersServiceMock.createServer.callCount).toEqual(0);
|
expect(ServersServiceMock.createServer.called).toEqual(false);
|
||||||
expect(ServersServiceMock.deleteServer.callCount).toEqual(0);
|
expect(ServersServiceMock.deleteServer.called).toEqual(false);
|
||||||
expect(ServersServiceMock.createServers.callCount).toEqual(0);
|
expect(ServersServiceMock.createServers.called).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createServer', () => {
|
describe('createServer', () => {
|
||||||
it('adds new server and then fetches servers again', () => {
|
it('adds new server and then fetches servers again', () => {
|
||||||
const serverToCreate = { id: 'abc123' };
|
const serverToCreate = { id: 'abc123' };
|
||||||
const result = createServer(ServersServiceMock)(serverToCreate);
|
const result = createServer(ServersServiceMock, () => expectedFetchServersResult)(serverToCreate);
|
||||||
|
|
||||||
expect(result).toEqual({ type: FETCH_SERVERS, servers });
|
expect(result).toEqual(expectedFetchServersResult);
|
||||||
expect(ServersServiceMock.listServers.callCount).toEqual(1);
|
expect(ServersServiceMock.createServer.calledOnce).toEqual(true);
|
||||||
expect(ServersServiceMock.createServer.callCount).toEqual(1);
|
|
||||||
expect(ServersServiceMock.createServer.firstCall.calledWith(serverToCreate)).toEqual(true);
|
expect(ServersServiceMock.createServer.firstCall.calledWith(serverToCreate)).toEqual(true);
|
||||||
expect(ServersServiceMock.deleteServer.callCount).toEqual(0);
|
expect(ServersServiceMock.listServers.called).toEqual(false);
|
||||||
expect(ServersServiceMock.createServers.callCount).toEqual(0);
|
expect(ServersServiceMock.deleteServer.called).toEqual(false);
|
||||||
|
expect(ServersServiceMock.createServers.called).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteServer', () => {
|
describe('deleteServer', () => {
|
||||||
it('deletes a server and then fetches servers again', () => {
|
it('deletes a server and then fetches servers again', () => {
|
||||||
const serverToDelete = { id: 'abc123' };
|
const serverToDelete = { id: 'abc123' };
|
||||||
const result = deleteServer(ServersServiceMock)(serverToDelete);
|
const result = deleteServer(ServersServiceMock, () => expectedFetchServersResult)(serverToDelete);
|
||||||
|
|
||||||
expect(result).toEqual({ type: FETCH_SERVERS, servers });
|
expect(result).toEqual(expectedFetchServersResult);
|
||||||
expect(ServersServiceMock.listServers.callCount).toEqual(1);
|
expect(ServersServiceMock.listServers.called).toEqual(false);
|
||||||
expect(ServersServiceMock.createServer.callCount).toEqual(0);
|
expect(ServersServiceMock.createServer.called).toEqual(false);
|
||||||
expect(ServersServiceMock.createServers.callCount).toEqual(0);
|
expect(ServersServiceMock.createServers.called).toEqual(false);
|
||||||
expect(ServersServiceMock.deleteServer.callCount).toEqual(1);
|
expect(ServersServiceMock.deleteServer.calledOnce).toEqual(true);
|
||||||
expect(ServersServiceMock.deleteServer.firstCall.calledWith(serverToDelete)).toEqual(true);
|
expect(ServersServiceMock.deleteServer.firstCall.calledWith(serverToDelete)).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -79,14 +80,14 @@ describe('serverReducer', () => {
|
||||||
describe('createServer', () => {
|
describe('createServer', () => {
|
||||||
it('creates multiple servers and then fetches servers again', () => {
|
it('creates multiple servers and then fetches servers again', () => {
|
||||||
const serversToCreate = values(servers);
|
const serversToCreate = values(servers);
|
||||||
const result = createServers(ServersServiceMock)(serversToCreate);
|
const result = createServers(ServersServiceMock, () => expectedFetchServersResult)(serversToCreate);
|
||||||
|
|
||||||
expect(result).toEqual({ type: FETCH_SERVERS, servers });
|
expect(result).toEqual(expectedFetchServersResult);
|
||||||
expect(ServersServiceMock.listServers.callCount).toEqual(1);
|
expect(ServersServiceMock.listServers.called).toEqual(false);
|
||||||
expect(ServersServiceMock.createServer.callCount).toEqual(0);
|
expect(ServersServiceMock.createServer.called).toEqual(false);
|
||||||
expect(ServersServiceMock.createServers.callCount).toEqual(1);
|
expect(ServersServiceMock.createServers.calledOnce).toEqual(true);
|
||||||
expect(ServersServiceMock.createServers.firstCall.calledWith(serversToCreate)).toEqual(true);
|
expect(ServersServiceMock.createServers.firstCall.calledWith(serversToCreate)).toEqual(true);
|
||||||
expect(ServersServiceMock.deleteServer.callCount).toEqual(0);
|
expect(ServersServiceMock.deleteServer.called).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue