Creates shortUrlsListParams reducer test

This commit is contained in:
Alejandro Celaya 2018-08-12 18:49:57 +02:00
parent d6e6c8c6c2
commit f8eb5fb022
4 changed files with 41 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
import { curry } from 'ramda';
const CREATE_SHORT_URL_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START';
const CREATE_SHORT_URL_ERROR = 'shlink/createShortUrl/CREATE_SHORT_URL_ERROR';
@ -37,7 +38,7 @@ export default function reducer(state = defaultState, action) {
}
}
export const createShortUrl = data => async dispatch => {
export const _createShortUrl = (ShlinkApiClient, data) => async dispatch => {
dispatch({ type: CREATE_SHORT_URL_START });
try {
@ -47,5 +48,6 @@ export const createShortUrl = data => async dispatch => {
dispatch({ type: CREATE_SHORT_URL_ERROR });
}
};
export const createShortUrl = curry(_createShortUrl)(ShlinkApiClient);
export const resetCreateShortUrl = () => ({ type: RESET_CREATE_SHORT_URL });

View file

@ -1,4 +1,5 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
import { curry } from 'ramda';
const GET_SHORT_URL_VISITS_START = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS_START';
const GET_SHORT_URL_VISITS_ERROR = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS_ERROR';
@ -36,7 +37,7 @@ export default function dispatch (state = initialState, action) {
}
}
export const getShortUrlVisits = (shortCode, dates) => dispatch => {
export const _getShortUrlVisits = (ShlinkApiClient, shortCode, dates) => dispatch => {
dispatch({ type: GET_SHORT_URL_VISITS_START });
Promise.all([
@ -46,3 +47,4 @@ export const getShortUrlVisits = (shortCode, dates) => dispatch => {
.then(([visits, shortUrl]) => dispatch({ visits, shortUrl, type: GET_SHORT_URL_VISITS }))
.catch(() => dispatch({ type: GET_SHORT_URL_VISITS_ERROR }));
};
export const getShortUrlVisits = curry(_getShortUrlVisits)(ShlinkApiClient);

View file

@ -1,4 +1,5 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
import { curry } from 'ramda';
const LIST_SHORT_URLS_START = 'shlink/shortUrlsList/LIST_SHORT_URLS_START';
const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR';
@ -30,7 +31,7 @@ export default function reducer(state = initialState, action) {
}
}
export const listShortUrls = (params = {}) => async dispatch => {
export const _listShortUrls = (ShlinkApiClient, params = {}) => async dispatch => {
dispatch({ type: LIST_SHORT_URLS_START });
try {
@ -40,3 +41,4 @@ export const listShortUrls = (params = {}) => async dispatch => {
dispatch({ type: LIST_SHORT_URLS_ERROR, params });
}
};
export const listShortUrls = curry(_listShortUrls)(ShlinkApiClient);

View file

@ -0,0 +1,32 @@
import reduce, {
RESET_SHORT_URL_PARAMS,
resetShortUrlParams,
} from '../../../src/short-urls/reducers/shortUrlsListParams';
import { LIST_SHORT_URLS } from '../../../src/short-urls/reducers/shortUrlsList';
describe('shortUrlsListParamsReducer', () => {
describe('reduce', () => {
const defaultState = { page: '1' };
it('returns default value when action is anknown', () =>
expect(reduce(defaultState, { type: 'unknown' })).toEqual(defaultState)
);
it('returns params when action is LIST_SHORT_URLS', () =>
expect(reduce(defaultState, { type: LIST_SHORT_URLS, params: { searchTerm: 'foo' } })).toEqual({
...defaultState,
searchTerm: 'foo'
})
);
it('returns default value when action is RESET_SHORT_URL_PARAMS', () =>
expect(reduce(defaultState, { type: RESET_SHORT_URL_PARAMS })).toEqual(defaultState)
);
});
describe('resetShortUrlParams', () => {
it('returns proper action', () =>
expect(resetShortUrlParams()).toEqual({ type: RESET_SHORT_URL_PARAMS })
);
});
});