mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Improved server reducer test
This commit is contained in:
parent
ff28169c74
commit
53650938f7
1 changed files with 21 additions and 0 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue