From 53650938f7c3bfd3ec47f210cde1b32ad9324c8d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 23 Aug 2018 16:35:27 +0200 Subject: [PATCH] Improved server reducer test --- test/servers/reducers/server.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/servers/reducers/server.test.js b/test/servers/reducers/server.test.js index 7fa70143..e0227081 100644 --- a/test/servers/reducers/server.test.js +++ b/test/servers/reducers/server.test.js @@ -2,9 +2,11 @@ import reduce, { _createServer, _deleteServer, _listServers, + _createServers, FETCH_SERVERS, } from '../../../src/servers/reducers/server'; import * as sinon from 'sinon'; +import { values } from 'ramda'; describe('serverReducer', () => { const servers = { @@ -15,6 +17,7 @@ describe('serverReducer', () => { listServers: sinon.fake.returns(servers), createServer: sinon.fake(), deleteServer: sinon.fake(), + createServers: sinon.fake(), }; describe('reduce', () => { @@ -32,6 +35,7 @@ describe('serverReducer', () => { ServersServiceMock.listServers.resetHistory(); ServersServiceMock.createServer.resetHistory(); ServersServiceMock.deleteServer.resetHistory(); + ServersServiceMock.createServers.resetHistory(); }); describe('listServers', () => { @@ -42,6 +46,7 @@ describe('serverReducer', () => { expect(ServersServiceMock.listServers.callCount).toEqual(1); expect(ServersServiceMock.createServer.callCount).toEqual(0); expect(ServersServiceMock.deleteServer.callCount).toEqual(0); + expect(ServersServiceMock.createServers.callCount).toEqual(0); }); }); @@ -55,6 +60,7 @@ describe('serverReducer', () => { expect(ServersServiceMock.createServer.callCount).toEqual(1); expect(ServersServiceMock.createServer.firstCall.calledWith(serverToCreate)).toEqual(true); expect(ServersServiceMock.deleteServer.callCount).toEqual(0); + expect(ServersServiceMock.createServers.callCount).toEqual(0); }); }); @@ -66,9 +72,24 @@ describe('serverReducer', () => { expect(result).toEqual({ type: FETCH_SERVERS, servers }); expect(ServersServiceMock.listServers.callCount).toEqual(1); expect(ServersServiceMock.createServer.callCount).toEqual(0); + expect(ServersServiceMock.createServers.callCount).toEqual(0); expect(ServersServiceMock.deleteServer.callCount).toEqual(1); expect(ServersServiceMock.deleteServer.firstCall.calledWith(serverToDelete)).toEqual(true); }); }); + + describe('createServer', () => { + it('creates multiple servers and then fetches servers again', () => { + const serversToCreate = values(servers); + const result = _createServers(ServersServiceMock, serversToCreate); + + expect(result).toEqual({ type: FETCH_SERVERS, servers }); + expect(ServersServiceMock.listServers.callCount).toEqual(1); + expect(ServersServiceMock.createServer.callCount).toEqual(0); + expect(ServersServiceMock.createServers.callCount).toEqual(1); + expect(ServersServiceMock.createServers.firstCall.calledWith(serversToCreate)).toEqual(true); + expect(ServersServiceMock.deleteServer.callCount).toEqual(0); + }); + }); }); });