mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-31 21:38:19 +03:00
Fixed test by using different serverId every time, preventing memoization
This commit is contained in:
parent
5145a41dac
commit
2ec04c0121
2 changed files with 11 additions and 11 deletions
|
@ -18,6 +18,11 @@ const versionToSemVer = pipe(
|
|||
toSemVer(MIN_FALLBACK_VERSION)
|
||||
);
|
||||
|
||||
const getServerVersion = memoizeWith(identity, (serverId, health) => health().then(({ version }) => ({
|
||||
version: versionToSemVer(version),
|
||||
printableVersion: versionToPrintable(version),
|
||||
})));
|
||||
|
||||
export const resetSelectedServer = createAction(RESET_SELECTED_SERVER);
|
||||
|
||||
export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serverId) => async (dispatch) => {
|
||||
|
@ -54,11 +59,6 @@ export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serve
|
|||
}
|
||||
};
|
||||
|
||||
const getServerVersion = memoizeWith(identity, (serverId, health) => health().then(({ version }) => ({
|
||||
version: versionToSemVer(version),
|
||||
printableVersion: versionToPrintable(version),
|
||||
})));
|
||||
|
||||
export default handleActions({
|
||||
[RESET_SELECTED_SERVER]: () => initialState,
|
||||
[SELECT_SERVER]: (state, { selectedServer }) => selectedServer,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { v4 as uuid } from 'uuid';
|
||||
import reducer, {
|
||||
selectServer,
|
||||
resetSelectedServer,
|
||||
|
@ -27,9 +28,8 @@ describe('selectedServerReducer', () => {
|
|||
});
|
||||
|
||||
describe('selectServer', () => {
|
||||
const serverId = 'abc123';
|
||||
const selectedServer = {
|
||||
id: serverId,
|
||||
id: 'abc123',
|
||||
};
|
||||
const version = '1.19.0';
|
||||
const ServersServiceMock = {
|
||||
|
@ -56,7 +56,7 @@ describe('selectedServerReducer', () => {
|
|||
|
||||
apiClientMock.health.mockResolvedValue({ version: serverVersion });
|
||||
|
||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(dispatch);
|
||||
await selectServer(ServersServiceMock, buildApiClient)(uuid())(dispatch);
|
||||
|
||||
expect(dispatch).toHaveBeenCalledTimes(3);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SELECTED_SERVER });
|
||||
|
@ -65,7 +65,7 @@ describe('selectedServerReducer', () => {
|
|||
});
|
||||
|
||||
it('invokes dependencies', async () => {
|
||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(() => {});
|
||||
await selectServer(ServersServiceMock, buildApiClient)(uuid())(() => {});
|
||||
|
||||
expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1);
|
||||
expect(buildApiClient).toHaveBeenCalledTimes(1);
|
||||
|
@ -76,7 +76,7 @@ describe('selectedServerReducer', () => {
|
|||
|
||||
apiClientMock.health.mockRejectedValue({});
|
||||
|
||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(dispatch);
|
||||
await selectServer(ServersServiceMock, buildApiClient)(uuid())(dispatch);
|
||||
|
||||
expect(apiClientMock.health).toHaveBeenCalled();
|
||||
expect(dispatch).toHaveBeenNthCalledWith(3, { type: SELECT_SERVER, selectedServer: expectedSelectedServer });
|
||||
|
@ -87,7 +87,7 @@ describe('selectedServerReducer', () => {
|
|||
|
||||
ServersServiceMock.findServerById.mockReturnValue(undefined);
|
||||
|
||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(dispatch);
|
||||
await selectServer(ServersServiceMock, buildApiClient)(uuid())(dispatch);
|
||||
|
||||
expect(ServersServiceMock.findServerById).toHaveBeenCalled();
|
||||
expect(apiClientMock.health).not.toHaveBeenCalled();
|
||||
|
|
Loading…
Reference in a new issue