mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 12:16:36 +00:00
Migrated server list actions to use payload prop
This commit is contained in:
@@ -87,7 +87,7 @@ describe('remoteServersReducer', () => {
|
||||
|
||||
await fetchServers(axios)()(dispatch);
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith({ type: CREATE_SERVERS, newServers: expectedNewServers });
|
||||
expect(dispatch).toHaveBeenCalledWith({ type: CREATE_SERVERS, payload: expectedNewServers });
|
||||
expect(get).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ import reducer, {
|
||||
} from '../../../src/servers/reducers/servers';
|
||||
import { RegularServer } from '../../../src/servers/data';
|
||||
|
||||
describe('serverReducer', () => {
|
||||
describe('serversReducer', () => {
|
||||
const list = {
|
||||
abc123: Mock.of<RegularServer>({ id: 'abc123' }),
|
||||
def456: Mock.of<RegularServer>({ id: 'def456' }),
|
||||
@@ -23,32 +23,35 @@ describe('serverReducer', () => {
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns edited server when action is EDIT_SERVER', () =>
|
||||
expect(reducer(
|
||||
list,
|
||||
{ type: EDIT_SERVER, serverId: 'abc123', serverData: { foo: 'foo' } } as any,
|
||||
)).toEqual({
|
||||
expect(reducer(list, {
|
||||
type: EDIT_SERVER,
|
||||
payload: { serverId: 'abc123', serverData: { foo: 'foo' } },
|
||||
} as any)).toEqual({
|
||||
abc123: { id: 'abc123', foo: 'foo' },
|
||||
def456: { id: 'def456' },
|
||||
}));
|
||||
|
||||
it('returns as it is when action is EDIT_SERVER and server does not exist', () =>
|
||||
expect(reducer(
|
||||
list,
|
||||
{ type: EDIT_SERVER, serverId: 'invalid', serverData: { foo: 'foo' } } as any,
|
||||
)).toEqual({
|
||||
expect(reducer(list, {
|
||||
type: EDIT_SERVER,
|
||||
payload: { serverId: 'invalid', serverData: { foo: 'foo' } },
|
||||
} as any)).toEqual({
|
||||
abc123: { id: 'abc123' },
|
||||
def456: { id: 'def456' },
|
||||
}));
|
||||
|
||||
it('removes server when action is DELETE_SERVER', () =>
|
||||
expect(reducer(list, { type: DELETE_SERVER, serverId: 'abc123' } as any)).toEqual({
|
||||
expect(reducer(list, {
|
||||
type: DELETE_SERVER,
|
||||
payload: { serverId: 'abc123' },
|
||||
} as any)).toEqual({
|
||||
def456: { id: 'def456' },
|
||||
}));
|
||||
|
||||
it('appends server when action is CREATE_SERVERS', () =>
|
||||
expect(reducer(list, {
|
||||
type: CREATE_SERVERS,
|
||||
newServers: {
|
||||
payload: {
|
||||
ghi789: { id: 'ghi789' },
|
||||
},
|
||||
} as any)).toEqual({
|
||||
@@ -63,8 +66,7 @@ describe('serverReducer', () => {
|
||||
])('returns state as it is when trying to set auto-connect on invalid server', (autoConnect) =>
|
||||
expect(reducer(list, {
|
||||
type: SET_AUTO_CONNECT,
|
||||
serverId: 'invalid',
|
||||
autoConnect,
|
||||
payload: { serverId: 'invalid', autoConnect },
|
||||
} as any)).toEqual({
|
||||
abc123: { id: 'abc123' },
|
||||
def456: { id: 'def456' },
|
||||
@@ -78,8 +80,7 @@ describe('serverReducer', () => {
|
||||
|
||||
expect(reducer(listWithDisabledAutoConnect, {
|
||||
type: SET_AUTO_CONNECT,
|
||||
serverId: 'abc123',
|
||||
autoConnect: false,
|
||||
payload: { serverId: 'abc123', autoConnect: false },
|
||||
} as any)).toEqual({
|
||||
abc123: { id: 'abc123', autoConnect: false },
|
||||
def456: { id: 'def456' },
|
||||
@@ -94,8 +95,7 @@ describe('serverReducer', () => {
|
||||
|
||||
expect(reducer(listWithEnabledAutoConnect, {
|
||||
type: SET_AUTO_CONNECT,
|
||||
serverId: 'def456',
|
||||
autoConnect: true,
|
||||
payload: { serverId: 'def456', autoConnect: true },
|
||||
} as any)).toEqual({
|
||||
abc123: { id: 'abc123', autoConnect: false },
|
||||
def456: { id: 'def456', autoConnect: true },
|
||||
@@ -118,7 +118,10 @@ describe('serverReducer', () => {
|
||||
const serverData = { name: 'edited' };
|
||||
const result = editServer('123', serverData);
|
||||
|
||||
expect(result).toEqual({ type: EDIT_SERVER, serverId: '123', serverData });
|
||||
expect(result).toEqual({
|
||||
type: EDIT_SERVER,
|
||||
payload: { serverId: '123', serverData },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -127,7 +130,10 @@ describe('serverReducer', () => {
|
||||
const serverToDelete = Mock.of<RegularServer>({ id: 'abc123' });
|
||||
const result = deleteServer(serverToDelete);
|
||||
|
||||
expect(result).toEqual({ type: DELETE_SERVER, serverId: 'abc123' });
|
||||
expect(result).toEqual({
|
||||
type: DELETE_SERVER,
|
||||
payload: { serverId: 'abc123' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -141,9 +147,9 @@ describe('serverReducer', () => {
|
||||
|
||||
it('generates an id for every provided server if they do not have it', () => {
|
||||
const servers = values(list).map(dissoc('id'));
|
||||
const { newServers } = createServers(servers);
|
||||
const { payload } = createServers(servers);
|
||||
|
||||
expect(values(newServers).every(({ id }) => !!id)).toEqual(true);
|
||||
expect(values(payload).every(({ id }) => !!id)).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -155,7 +161,10 @@ describe('serverReducer', () => {
|
||||
const serverToEdit = Mock.of<RegularServer>({ id: 'abc123' });
|
||||
const result = setAutoConnect(serverToEdit, autoConnect);
|
||||
|
||||
expect(result).toEqual({ type: SET_AUTO_CONNECT, serverId: 'abc123', autoConnect });
|
||||
expect(result).toEqual({
|
||||
type: SET_AUTO_CONNECT,
|
||||
payload: { serverId: 'abc123', autoConnect },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user