2018-08-26 00:39:27 +03:00
|
|
|
import { values } from 'ramda';
|
2020-08-23 11:20:31 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2018-08-26 11:52:45 +03:00
|
|
|
import reducer, {
|
2018-12-18 21:45:09 +03:00
|
|
|
createServer,
|
|
|
|
deleteServer,
|
|
|
|
createServers,
|
2020-04-25 11:22:17 +03:00
|
|
|
editServer,
|
2020-04-27 12:30:51 +03:00
|
|
|
EDIT_SERVER,
|
|
|
|
DELETE_SERVER,
|
|
|
|
CREATE_SERVERS,
|
2020-04-27 11:52:19 +03:00
|
|
|
} from '../../../src/servers/reducers/servers';
|
2020-08-23 11:20:31 +03:00
|
|
|
import { RegularServer } from '../../../src/servers/data';
|
2018-08-12 11:17:13 +03:00
|
|
|
|
|
|
|
describe('serverReducer', () => {
|
2019-04-28 13:40:50 +03:00
|
|
|
const list = {
|
2020-08-23 11:20:31 +03:00
|
|
|
abc123: Mock.of<RegularServer>({ id: 'abc123' }),
|
|
|
|
def456: Mock.of<RegularServer>({ id: 'def456' }),
|
2018-08-12 11:17:13 +03:00
|
|
|
};
|
|
|
|
|
2019-10-21 20:26:09 +03:00
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
|
2018-08-26 11:52:45 +03:00
|
|
|
describe('reducer', () => {
|
2020-04-27 12:30:51 +03:00
|
|
|
it('returns edited server when action is EDIT_SERVER', () =>
|
|
|
|
expect(reducer(
|
|
|
|
list,
|
2020-08-23 11:20:31 +03:00
|
|
|
{ type: EDIT_SERVER, serverId: 'abc123', serverData: { foo: 'foo' } } as any,
|
2020-04-27 12:30:51 +03:00
|
|
|
)).toEqual({
|
|
|
|
abc123: { id: 'abc123', foo: 'foo' },
|
|
|
|
def456: { id: 'def456' },
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('removes server when action is DELETE_SERVER', () =>
|
2020-08-23 11:20:31 +03:00
|
|
|
expect(reducer(list, { type: DELETE_SERVER, serverId: 'abc123' } as any)).toEqual({
|
2020-04-27 12:30:51 +03:00
|
|
|
def456: { id: 'def456' },
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('appends server when action is CREATE_SERVERS', () =>
|
|
|
|
expect(reducer(list, {
|
|
|
|
type: CREATE_SERVERS,
|
|
|
|
newServers: {
|
|
|
|
ghi789: { id: 'ghi789' },
|
|
|
|
},
|
2020-08-23 11:20:31 +03:00
|
|
|
} as any)).toEqual({
|
2020-04-27 12:30:51 +03:00
|
|
|
abc123: { id: 'abc123' },
|
|
|
|
def456: { id: 'def456' },
|
|
|
|
ghi789: { id: 'ghi789' },
|
|
|
|
}));
|
2018-08-12 11:17:13 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('action creators', () => {
|
|
|
|
describe('createServer', () => {
|
2020-04-27 12:30:51 +03:00
|
|
|
it('returns expected action', () => {
|
2020-08-23 11:20:31 +03:00
|
|
|
const serverToCreate = Mock.of<RegularServer>({ id: 'abc123' });
|
2020-04-27 12:30:51 +03:00
|
|
|
const result = createServer(serverToCreate);
|
2018-08-12 11:17:13 +03:00
|
|
|
|
2020-04-27 12:30:51 +03:00
|
|
|
expect(result).toEqual(expect.objectContaining({ type: CREATE_SERVERS }));
|
2020-03-15 13:29:20 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('editServer', () => {
|
2020-04-27 12:30:51 +03:00
|
|
|
it('returns expected action', () => {
|
|
|
|
const serverData = { name: 'edited' };
|
|
|
|
const result = editServer('123', serverData);
|
2020-03-15 13:29:20 +03:00
|
|
|
|
2020-04-27 12:30:51 +03:00
|
|
|
expect(result).toEqual({ type: EDIT_SERVER, serverId: '123', serverData });
|
2018-08-12 11:17:13 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteServer', () => {
|
2020-04-27 12:30:51 +03:00
|
|
|
it('returns expected action', () => {
|
2020-08-23 11:20:31 +03:00
|
|
|
const serverToDelete = Mock.of<RegularServer>({ id: 'abc123' });
|
2020-04-27 12:30:51 +03:00
|
|
|
const result = deleteServer(serverToDelete);
|
2018-08-12 11:17:13 +03:00
|
|
|
|
2020-04-27 12:30:51 +03:00
|
|
|
expect(result).toEqual({ type: DELETE_SERVER, serverId: 'abc123' });
|
2018-08-12 11:17:13 +03:00
|
|
|
});
|
|
|
|
});
|
2018-08-23 17:35:27 +03:00
|
|
|
|
2020-03-15 13:29:20 +03:00
|
|
|
describe('createServers', () => {
|
2020-04-27 12:30:51 +03:00
|
|
|
it('returns expected action', () => {
|
|
|
|
const newServers = values(list);
|
|
|
|
const result = createServers(newServers);
|
2018-08-23 17:35:27 +03:00
|
|
|
|
2020-04-27 12:30:51 +03:00
|
|
|
expect(result).toEqual(expect.objectContaining({ type: CREATE_SERVERS }));
|
2018-08-23 17:35:27 +03:00
|
|
|
});
|
|
|
|
});
|
2018-08-12 11:17:13 +03:00
|
|
|
});
|
|
|
|
});
|