mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-05-27 07:36:34 +00:00
Removed no longer needed async/await when building api client
This commit is contained in:
@@ -19,7 +19,7 @@ export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serve
|
|||||||
dispatch(resetShortUrlParams());
|
dispatch(resetShortUrlParams());
|
||||||
|
|
||||||
const selectedServer = findServerById(serverId);
|
const selectedServer = findServerById(serverId);
|
||||||
const { health } = await buildShlinkApiClient(selectedServer);
|
const { health } = buildShlinkApiClient(selectedServer);
|
||||||
const version = await health()
|
const version = await health()
|
||||||
.then(({ version }) => version === LATEST_VERSION_CONSTRAINT ? MAX_FALLBACK_VERSION : version)
|
.then(({ version }) => version === LATEST_VERSION_CONSTRAINT ? MAX_FALLBACK_VERSION : version)
|
||||||
.then((version) => !versionIsValidSemVer(version) ? MIN_FALLBACK_VERSION : version)
|
.then((version) => !versionIsValidSemVer(version) ? MIN_FALLBACK_VERSION : version)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const createShortUrl = (buildShlinkApiClient) => (data) => async (dispatch, getState) => {
|
export const createShortUrl = (buildShlinkApiClient) => (data) => async (dispatch, getState) => {
|
||||||
dispatch({ type: CREATE_SHORT_URL_START });
|
dispatch({ type: CREATE_SHORT_URL_START });
|
||||||
const { createShortUrl } = await buildShlinkApiClient(getState);
|
const { createShortUrl } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await createShortUrl(data);
|
const result = await createShortUrl(data);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const deleteShortUrl = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => {
|
export const deleteShortUrl = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => {
|
||||||
dispatch({ type: DELETE_SHORT_URL_START });
|
dispatch({ type: DELETE_SHORT_URL_START });
|
||||||
const { deleteShortUrl } = await buildShlinkApiClient(getState);
|
const { deleteShortUrl } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteShortUrl(shortCode, domain);
|
await deleteShortUrl(shortCode, domain);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const editShortUrlMeta = (buildShlinkApiClient) => (shortCode, domain, meta) => async (dispatch, getState) => {
|
export const editShortUrlMeta = (buildShlinkApiClient) => (shortCode, domain, meta) => async (dispatch, getState) => {
|
||||||
dispatch({ type: EDIT_SHORT_URL_META_START });
|
dispatch({ type: EDIT_SHORT_URL_META_START });
|
||||||
const { updateShortUrlMeta } = await buildShlinkApiClient(getState);
|
const { updateShortUrlMeta } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateShortUrlMeta(shortCode, domain, meta);
|
await updateShortUrlMeta(shortCode, domain, meta);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const editShortUrlTags = (buildShlinkApiClient) => (shortCode, domain, tags) => async (dispatch, getState) => {
|
export const editShortUrlTags = (buildShlinkApiClient) => (shortCode, domain, tags) => async (dispatch, getState) => {
|
||||||
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
|
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
|
||||||
const { updateShortUrlTags } = await buildShlinkApiClient(getState);
|
const { updateShortUrlTags } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const normalizedTags = await updateShortUrlTags(shortCode, domain, tags);
|
const normalizedTags = await updateShortUrlTags(shortCode, domain, tags);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const listShortUrls = (buildShlinkApiClient) => (params = {}) => async (dispatch, getState) => {
|
export const listShortUrls = (buildShlinkApiClient) => (params = {}) => async (dispatch, getState) => {
|
||||||
dispatch({ type: LIST_SHORT_URLS_START });
|
dispatch({ type: LIST_SHORT_URLS_START });
|
||||||
const { listShortUrls } = await buildShlinkApiClient(getState);
|
const { listShortUrls } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const shortUrls = await listShortUrls(params);
|
const shortUrls = await listShortUrls(params);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const deleteTag = (buildShlinkApiClient) => (tag) => async (dispatch, getState) => {
|
export const deleteTag = (buildShlinkApiClient) => (tag) => async (dispatch, getState) => {
|
||||||
dispatch({ type: DELETE_TAG_START });
|
dispatch({ type: DELETE_TAG_START });
|
||||||
const { deleteTags } = await buildShlinkApiClient(getState);
|
const { deleteTags } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteTags([ tag ]);
|
await deleteTags([ tag ]);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const editTag = (buildShlinkApiClient, colorGenerator) => (oldName, newNa
|
|||||||
getState
|
getState
|
||||||
) => {
|
) => {
|
||||||
dispatch({ type: EDIT_TAG_START });
|
dispatch({ type: EDIT_TAG_START });
|
||||||
const { editTag } = await buildShlinkApiClient(getState);
|
const { editTag } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await editTag(oldName, newName);
|
await editTag(oldName, newName);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const listTags = (buildShlinkApiClient, force = true) => () => async (dis
|
|||||||
dispatch({ type: LIST_TAGS_START });
|
dispatch({ type: LIST_TAGS_START });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { listTags } = await buildShlinkApiClient(getState);
|
const { listTags } = buildShlinkApiClient(getState);
|
||||||
const tags = await listTags();
|
const tags = await listTags();
|
||||||
|
|
||||||
dispatch({ tags, type: LIST_TAGS });
|
dispatch({ tags, type: LIST_TAGS });
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const getSelectedServerFromState = (getState) => {
|
|||||||
return selectedServer;
|
return selectedServer;
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildShlinkApiClient = (axios) => async (getStateOrSelectedServer) => {
|
const buildShlinkApiClient = (axios) => (getStateOrSelectedServer) => {
|
||||||
const { url, apiKey } = typeof getStateOrSelectedServer === 'function'
|
const { url, apiKey } = typeof getStateOrSelectedServer === 'function'
|
||||||
? getSelectedServerFromState(getStateOrSelectedServer)
|
? getSelectedServerFromState(getStateOrSelectedServer)
|
||||||
: getStateOrSelectedServer;
|
: getStateOrSelectedServer;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => {
|
export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => {
|
||||||
dispatch({ type: GET_SHORT_URL_DETAIL_START });
|
dispatch({ type: GET_SHORT_URL_DETAIL_START });
|
||||||
const { getShortUrl } = await buildShlinkApiClient(getState);
|
const { getShortUrl } = buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const shortUrl = await getShortUrl(shortCode, domain);
|
const shortUrl = await getShortUrl(shortCode, domain);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export default handleActions({
|
|||||||
|
|
||||||
export const getShortUrlVisits = (buildShlinkApiClient) => (shortCode, query) => async (dispatch, getState) => {
|
export const getShortUrlVisits = (buildShlinkApiClient) => (shortCode, query) => async (dispatch, getState) => {
|
||||||
dispatch({ type: GET_SHORT_URL_VISITS_START });
|
dispatch({ type: GET_SHORT_URL_VISITS_START });
|
||||||
const { getShortUrlVisits } = await buildShlinkApiClient(getState);
|
const { getShortUrlVisits } = buildShlinkApiClient(getState);
|
||||||
const itemsPerPage = 5000;
|
const itemsPerPage = 5000;
|
||||||
const isLastPage = ({ currentPage, pagesCount }) => currentPage >= pagesCount;
|
const isLastPage = ({ currentPage, pagesCount }) => currentPage >= pagesCount;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ describe('selectedServerReducer', () => {
|
|||||||
const apiClientMock = {
|
const apiClientMock = {
|
||||||
health: jest.fn(),
|
health: jest.fn(),
|
||||||
};
|
};
|
||||||
const buildApiClient = jest.fn().mockResolvedValue(apiClientMock);
|
const buildApiClient = jest.fn().mockReturnValue(apiClientMock);
|
||||||
const dispatch = jest.fn();
|
const dispatch = jest.fn();
|
||||||
|
|
||||||
afterEach(jest.clearAllMocks);
|
afterEach(jest.clearAllMocks);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ describe('shortUrlMetaReducer', () => {
|
|||||||
|
|
||||||
describe('editShortUrlMeta', () => {
|
describe('editShortUrlMeta', () => {
|
||||||
const updateShortUrlMeta = jest.fn().mockResolvedValue({});
|
const updateShortUrlMeta = jest.fn().mockResolvedValue({});
|
||||||
const buildShlinkApiClient = jest.fn().mockResolvedValue({ updateShortUrlMeta });
|
const buildShlinkApiClient = jest.fn().mockReturnValue({ updateShortUrlMeta });
|
||||||
const dispatch = jest.fn();
|
const dispatch = jest.fn();
|
||||||
|
|
||||||
afterEach(jest.clearAllMocks);
|
afterEach(jest.clearAllMocks);
|
||||||
|
|||||||
@@ -51,14 +51,10 @@ describe('shortUrlTagsReducer', () => {
|
|||||||
|
|
||||||
describe('editShortUrlTags', () => {
|
describe('editShortUrlTags', () => {
|
||||||
const updateShortUrlTags = jest.fn();
|
const updateShortUrlTags = jest.fn();
|
||||||
const buildShlinkApiClient = jest.fn().mockResolvedValue({ updateShortUrlTags });
|
const buildShlinkApiClient = jest.fn().mockReturnValue({ updateShortUrlTags });
|
||||||
const dispatch = jest.fn();
|
const dispatch = jest.fn();
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(jest.clearAllMocks);
|
||||||
updateShortUrlTags.mockReset();
|
|
||||||
buildShlinkApiClient.mockClear();
|
|
||||||
dispatch.mockReset();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([[ undefined ], [ null ], [ 'example.com' ]])('dispatches normalized tags on success', async (domain) => {
|
it.each([[ undefined ], [ null ], [ 'example.com' ]])('dispatches normalized tags on success', async (domain) => {
|
||||||
const normalizedTags = [ 'bar', 'foo' ];
|
const normalizedTags = [ 'bar', 'foo' ];
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ describe('tagsListReducer', () => {
|
|||||||
const tags = [ 'foo', 'bar', 'baz' ];
|
const tags = [ 'foo', 'bar', 'baz' ];
|
||||||
|
|
||||||
listTagsMock.mockResolvedValue(tags);
|
listTagsMock.mockResolvedValue(tags);
|
||||||
buildShlinkApiClient.mockResolvedValue({ listTags: listTagsMock });
|
buildShlinkApiClient.mockReturnValue({ listTags: listTagsMock });
|
||||||
|
|
||||||
await listTags(buildShlinkApiClient, true)()(dispatch, getState);
|
await listTags(buildShlinkApiClient, true)()(dispatch, getState);
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ describe('tagsListReducer', () => {
|
|||||||
|
|
||||||
it('dispatches error when error occurs on list call', async () => {
|
it('dispatches error when error occurs on list call', async () => {
|
||||||
listTagsMock.mockRejectedValue(new Error());
|
listTagsMock.mockRejectedValue(new Error());
|
||||||
buildShlinkApiClient.mockResolvedValue({ listTags: listTagsMock });
|
buildShlinkApiClient.mockReturnValue({ listTags: listTagsMock });
|
||||||
|
|
||||||
await assertErrorResult();
|
await assertErrorResult();
|
||||||
|
|
||||||
@@ -135,7 +135,9 @@ describe('tagsListReducer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('dispatches error when error occurs on build call', async () => {
|
it('dispatches error when error occurs on build call', async () => {
|
||||||
buildShlinkApiClient.mockRejectedValue(new Error());
|
buildShlinkApiClient.mockImplementation(() => {
|
||||||
|
throw new Error();
|
||||||
|
});
|
||||||
|
|
||||||
await assertErrorResult();
|
await assertErrorResult();
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ describe('ShlinkApiClientBuilder', () => {
|
|||||||
expect(secondApiClient).toBe(thirdApiClient);
|
expect(secondApiClient).toBe(thirdApiClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not fetch from state when provided param is already selected server', async () => {
|
it('does not fetch from state when provided param is already selected server', () => {
|
||||||
const url = 'url';
|
const url = 'url';
|
||||||
const apiKey = 'apiKey';
|
const apiKey = 'apiKey';
|
||||||
const apiClient = await buildShlinkApiClient({})({ url, apiKey });
|
const apiClient = buildShlinkApiClient({})({ url, apiKey });
|
||||||
|
|
||||||
expect(apiClient._baseUrl).toEqual(url);
|
expect(apiClient._baseUrl).toEqual(url);
|
||||||
expect(apiClient._apiKey).toEqual(apiKey);
|
expect(apiClient._apiKey).toEqual(apiKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user