mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-12 18:43:50 +00:00
Migrated servers reducer to RTK
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { fetchServers } from '../../../src/servers/reducers/remoteServers';
|
||||
import { CREATE_SERVERS } from '../../../src/servers/reducers/servers';
|
||||
import { createServers } from '../../../src/servers/reducers/servers';
|
||||
|
||||
describe('remoteServersReducer', () => {
|
||||
afterEach(jest.clearAllMocks);
|
||||
@@ -87,7 +87,7 @@ describe('remoteServersReducer', () => {
|
||||
|
||||
await fetchServers(axios)()(dispatch);
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith({ type: CREATE_SERVERS, payload: expectedNewServers });
|
||||
expect(dispatch).toHaveBeenCalledWith({ type: createServers.toString(), payload: expectedNewServers });
|
||||
expect(get).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import { dissoc, values } from 'ramda';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import reducer, {
|
||||
import {
|
||||
deleteServer,
|
||||
createServers,
|
||||
editServer,
|
||||
setAutoConnect,
|
||||
EDIT_SERVER,
|
||||
DELETE_SERVER,
|
||||
CREATE_SERVERS,
|
||||
SET_AUTO_CONNECT,
|
||||
serversReducer,
|
||||
} from '../../../src/servers/reducers/servers';
|
||||
import { RegularServer } from '../../../src/servers/data';
|
||||
|
||||
@@ -22,38 +19,38 @@ describe('serversReducer', () => {
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns edited server when action is EDIT_SERVER', () =>
|
||||
expect(reducer(list, {
|
||||
type: EDIT_SERVER,
|
||||
expect(serversReducer(list, {
|
||||
type: editServer.toString(),
|
||||
payload: { serverId: 'abc123', serverData: { foo: 'foo' } },
|
||||
} as any)).toEqual({
|
||||
})).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,
|
||||
expect(serversReducer(list, {
|
||||
type: editServer.toString(),
|
||||
payload: { serverId: 'invalid', serverData: { foo: 'foo' } },
|
||||
} as any)).toEqual({
|
||||
})).toEqual({
|
||||
abc123: { id: 'abc123' },
|
||||
def456: { id: 'def456' },
|
||||
}));
|
||||
|
||||
it('removes server when action is DELETE_SERVER', () =>
|
||||
expect(reducer(list, {
|
||||
type: DELETE_SERVER,
|
||||
payload: { serverId: 'abc123' },
|
||||
} as any)).toEqual({
|
||||
expect(serversReducer(list, {
|
||||
type: deleteServer.toString(),
|
||||
payload: { id: 'abc123' },
|
||||
})).toEqual({
|
||||
def456: { id: 'def456' },
|
||||
}));
|
||||
|
||||
it('appends server when action is CREATE_SERVERS', () =>
|
||||
expect(reducer(list, {
|
||||
type: CREATE_SERVERS,
|
||||
expect(serversReducer(list, {
|
||||
type: createServers.toString(),
|
||||
payload: {
|
||||
ghi789: { id: 'ghi789' },
|
||||
},
|
||||
} as any)).toEqual({
|
||||
})).toEqual({
|
||||
abc123: { id: 'abc123' },
|
||||
def456: { id: 'def456' },
|
||||
ghi789: { id: 'ghi789' },
|
||||
@@ -63,10 +60,10 @@ describe('serversReducer', () => {
|
||||
[true],
|
||||
[false],
|
||||
])('returns state as it is when trying to set auto-connect on invalid server', (autoConnect) =>
|
||||
expect(reducer(list, {
|
||||
type: SET_AUTO_CONNECT,
|
||||
expect(serversReducer(list, {
|
||||
type: setAutoConnect.toString(),
|
||||
payload: { serverId: 'invalid', autoConnect },
|
||||
} as any)).toEqual({
|
||||
})).toEqual({
|
||||
abc123: { id: 'abc123' },
|
||||
def456: { id: 'def456' },
|
||||
}));
|
||||
@@ -77,10 +74,10 @@ describe('serversReducer', () => {
|
||||
abc123: { ...list.abc123, autoConnect: true },
|
||||
};
|
||||
|
||||
expect(reducer(listWithDisabledAutoConnect, {
|
||||
type: SET_AUTO_CONNECT,
|
||||
expect(serversReducer(listWithDisabledAutoConnect, {
|
||||
type: setAutoConnect.toString(),
|
||||
payload: { serverId: 'abc123', autoConnect: false },
|
||||
} as any)).toEqual({
|
||||
})).toEqual({
|
||||
abc123: { id: 'abc123', autoConnect: false },
|
||||
def456: { id: 'def456' },
|
||||
});
|
||||
@@ -92,10 +89,10 @@ describe('serversReducer', () => {
|
||||
abc123: { ...list.abc123, autoConnect: true },
|
||||
};
|
||||
|
||||
expect(reducer(listWithEnabledAutoConnect, {
|
||||
type: SET_AUTO_CONNECT,
|
||||
expect(serversReducer(listWithEnabledAutoConnect, {
|
||||
type: setAutoConnect.toString(),
|
||||
payload: { serverId: 'def456', autoConnect: true },
|
||||
} as any)).toEqual({
|
||||
})).toEqual({
|
||||
abc123: { id: 'abc123', autoConnect: false },
|
||||
def456: { id: 'def456', autoConnect: true },
|
||||
});
|
||||
@@ -109,7 +106,7 @@ describe('serversReducer', () => {
|
||||
const result = editServer('123', serverData);
|
||||
|
||||
expect(result).toEqual({
|
||||
type: EDIT_SERVER,
|
||||
type: editServer.toString(),
|
||||
payload: { serverId: '123', serverData },
|
||||
});
|
||||
});
|
||||
@@ -121,8 +118,8 @@ describe('serversReducer', () => {
|
||||
const result = deleteServer(serverToDelete);
|
||||
|
||||
expect(result).toEqual({
|
||||
type: DELETE_SERVER,
|
||||
payload: { serverId: 'abc123' },
|
||||
type: deleteServer.toString(),
|
||||
payload: { id: 'abc123' },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -132,7 +129,7 @@ describe('serversReducer', () => {
|
||||
const newServers = values(list);
|
||||
const result = createServers(newServers);
|
||||
|
||||
expect(result).toEqual(expect.objectContaining({ type: CREATE_SERVERS }));
|
||||
expect(result).toEqual(expect.objectContaining({ type: createServers.toString() }));
|
||||
});
|
||||
|
||||
it('generates an id for every provided server if they do not have it', () => {
|
||||
@@ -152,7 +149,7 @@ describe('serversReducer', () => {
|
||||
const result = setAutoConnect(serverToEdit, autoConnect);
|
||||
|
||||
expect(result).toEqual({
|
||||
type: SET_AUTO_CONNECT,
|
||||
type: setAutoConnect.toString(),
|
||||
payload: { serverId: 'abc123', autoConnect },
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user