Migrated fetchServers to RTK

This commit is contained in:
Alejandro Celaya
2022-11-10 20:44:58 +01:00
parent a1d869900b
commit 2e0e24d87b
2 changed files with 19 additions and 9 deletions

View File

@@ -7,9 +7,9 @@ describe('remoteServersReducer', () => {
afterEach(jest.clearAllMocks);
describe('fetchServers', () => {
const dispatch = jest.fn();
const get = jest.fn();
const axios = Mock.of<AxiosInstance>({ get });
const dispatch = jest.fn();
it.each([
[
@@ -84,10 +84,17 @@ describe('remoteServersReducer', () => {
[{}, {}],
])('tries to fetch servers from remote', async (mockedValue, expectedNewServers) => {
get.mockResolvedValue(mockedValue);
const doFetchServers = fetchServers(axios);
await fetchServers(axios)()(dispatch);
await doFetchServers()(dispatch, jest.fn(), {});
expect(dispatch).toHaveBeenCalledWith({ type: createServers.toString(), payload: expectedNewServers });
expect(dispatch).toHaveBeenNthCalledWith(1, expect.objectContaining({
type: doFetchServers.pending.toString(),
}));
expect(dispatch).toHaveBeenNthCalledWith(2, { type: createServers.toString(), payload: expectedNewServers });
expect(dispatch).toHaveBeenNthCalledWith(3, expect.objectContaining({
type: doFetchServers.fulfilled.toString(),
}));
expect(get).toHaveBeenCalledTimes(1);
});
});