Removed dependency on redux-actions for all reducers already migrated to typescript

This commit is contained in:
Alejandro Celaya
2020-08-25 19:41:48 +02:00
parent d8f3952920
commit f04aece7df
15 changed files with 99 additions and 74 deletions

View File

@@ -1,10 +1,10 @@
import { Mock } from 'ts-mockery';
import { Action } from 'redux-actions';
import reducer, {
GET_MERCURE_INFO_START,
GET_MERCURE_INFO_ERROR,
GET_MERCURE_INFO,
loadMercureInfo,
GetMercureInfoAction,
} from '../../../src/mercure/reducers/mercureInfo';
import { ShlinkMercureInfo } from '../../../src/utils/services/types';
import ShlinkApiClient from '../../../src/utils/services/ShlinkApiClient';
@@ -17,22 +17,26 @@ describe('mercureInfoReducer', () => {
};
describe('reducer', () => {
const action = (type: string, args: Partial<ShlinkMercureInfo> = {}) => Mock.of<GetMercureInfoAction>(
{ type, ...args },
);
it('returns loading on GET_MERCURE_INFO_START', () => {
expect(reducer(undefined, { type: GET_MERCURE_INFO_START } as Action<ShlinkMercureInfo>)).toEqual({
expect(reducer(undefined, action(GET_MERCURE_INFO_START))).toEqual({
loading: true,
error: false,
});
});
it('returns error on GET_MERCURE_INFO_ERROR', () => {
expect(reducer(undefined, { type: GET_MERCURE_INFO_ERROR } as Action<ShlinkMercureInfo>)).toEqual({
expect(reducer(undefined, action(GET_MERCURE_INFO_ERROR))).toEqual({
loading: false,
error: true,
});
});
it('returns mercure info on GET_MERCURE_INFO', () => {
expect(reducer(undefined, { type: GET_MERCURE_INFO, payload: mercureInfo })).toEqual({
expect(reducer(undefined, { type: GET_MERCURE_INFO, ...mercureInfo })).toEqual({
...mercureInfo,
loading: false,
error: false,
@@ -74,7 +78,7 @@ describe('mercureInfoReducer', () => {
expect(apiClientMock.mercureInfo).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: GET_MERCURE_INFO_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: GET_MERCURE_INFO, payload: mercureInfo });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: GET_MERCURE_INFO, ...mercureInfo });
});
it('throws error on failure', async () => {

View File

@@ -10,17 +10,17 @@ import reducer, {
} from '../../../src/servers/reducers/selectedServer';
import { RESET_SHORT_URL_PARAMS } from '../../../src/short-urls/reducers/shortUrlsListParams';
import { ShlinkState } from '../../../src/container/types';
import { NonReachableServer, NotFoundServer } from '../../../src/servers/data';
import { NonReachableServer, NotFoundServer, RegularServer } from '../../../src/servers/data';
describe('selectedServerReducer', () => {
describe('reducer', () => {
it('returns default when action is RESET_SELECTED_SERVER', () =>
expect(reducer(null, { type: RESET_SELECTED_SERVER } as any)).toEqual(null));
expect(reducer(null, { type: RESET_SELECTED_SERVER, selectedServer: null })).toEqual(null));
it('returns selected server when action is SELECT_SERVER', () => {
const selectedServer = { id: 'abc123' };
const selectedServer = Mock.of<RegularServer>({ id: 'abc123' });
expect(reducer(null, { type: SELECT_SERVER, selectedServer } as any)).toEqual(selectedServer);
expect(reducer(null, { type: SELECT_SERVER, selectedServer })).toEqual(selectedServer);
});
});

View File

@@ -5,7 +5,7 @@ describe('settingsReducer', () => {
describe('reducer', () => {
it('returns realTimeUpdates when action is SET_REAL_TIME_UPDATES', () => {
expect(reducer(undefined, { type: SET_REAL_TIME_UPDATES, realTimeUpdates } as any)).toEqual({ realTimeUpdates });
expect(reducer(undefined, { type: SET_REAL_TIME_UPDATES, realTimeUpdates })).toEqual({ realTimeUpdates });
});
});

View File

@@ -6,6 +6,7 @@ import reducer, {
RESET_CREATE_SHORT_URL,
createShortUrl,
resetCreateShortUrl,
CreateShortUrlAction,
} from '../../../src/short-urls/reducers/shortUrlCreation';
import { ShortUrl } from '../../../src/short-urls/data';
import ShlinkApiClient from '../../../src/utils/services/ShlinkApiClient';
@@ -15,8 +16,12 @@ describe('shortUrlCreationReducer', () => {
const shortUrl = Mock.all<ShortUrl>();
describe('reducer', () => {
const action = (type: string, args: Partial<CreateShortUrlAction> = {}) => Mock.of<CreateShortUrlAction>(
{ type, ...args },
);
it('returns loading on CREATE_SHORT_URL_START', () => {
expect(reducer(undefined, { type: CREATE_SHORT_URL_START } as any)).toEqual({
expect(reducer(undefined, action(CREATE_SHORT_URL_START))).toEqual({
result: null,
saving: true,
error: false,
@@ -24,7 +29,7 @@ describe('shortUrlCreationReducer', () => {
});
it('returns error on CREATE_SHORT_URL_ERROR', () => {
expect(reducer(undefined, { type: CREATE_SHORT_URL_ERROR } as any)).toEqual({
expect(reducer(undefined, action(CREATE_SHORT_URL_ERROR))).toEqual({
result: null,
saving: false,
error: true,
@@ -32,7 +37,7 @@ describe('shortUrlCreationReducer', () => {
});
it('returns result on CREATE_SHORT_URL', () => {
expect(reducer(undefined, { type: CREATE_SHORT_URL, result: shortUrl } as any)).toEqual({
expect(reducer(undefined, action(CREATE_SHORT_URL, { result: shortUrl }))).toEqual({
result: shortUrl,
saving: false,
error: false,
@@ -40,7 +45,7 @@ describe('shortUrlCreationReducer', () => {
});
it('returns default state on RESET_CREATE_SHORT_URL', () => {
expect(reducer(undefined, { type: RESET_CREATE_SHORT_URL } as any)).toEqual({
expect(reducer(undefined, action(RESET_CREATE_SHORT_URL))).toEqual({
result: null,
saving: false,
error: false,
@@ -49,8 +54,7 @@ describe('shortUrlCreationReducer', () => {
});
describe('resetCreateShortUrl', () => {
it('returns proper action', () =>
expect(resetCreateShortUrl()).toEqual({ type: RESET_CREATE_SHORT_URL }));
it('returns proper action', () => expect(resetCreateShortUrl()).toEqual({ type: RESET_CREATE_SHORT_URL }));
});
describe('createShortUrl', () => {

View File

@@ -37,7 +37,7 @@ describe('shortUrlMetaReducer', () => {
});
it('returns provided tags and shortCode on SHORT_URL_META_EDITED', () => {
expect(reducer(undefined, { type: SHORT_URL_META_EDITED, payload: { meta, shortCode } })).toEqual({
expect(reducer(undefined, { type: SHORT_URL_META_EDITED, meta, shortCode })).toEqual({
meta,
shortCode,
saving: false,
@@ -64,8 +64,6 @@ describe('shortUrlMetaReducer', () => {
afterEach(jest.clearAllMocks);
it.each([[ undefined ], [ null ], [ 'example.com' ]])('dispatches metadata on success', async (domain) => {
const payload = { meta, shortCode, domain };
await editShortUrlMeta(buildShlinkApiClient)(shortCode, domain, meta)(dispatch, getState);
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
@@ -73,7 +71,7 @@ describe('shortUrlMetaReducer', () => {
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, domain, meta);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_META_EDITED, payload });
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_META_EDITED, meta, shortCode, domain });
});
it('dispatches error on failure', async () => {