From a202fe68d1ffa9cc2f34ceaae89811535936688f Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Tue, 15 Nov 2022 08:43:26 -0500 Subject: [PATCH] Move api into a folder --- .../api.ts => api/__mocks__/index.ts} | 2 +- app/soapbox/{api.ts => api/index.ts} | 40 +++++++++---------- app/soapbox/jest/test-setup.ts | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) rename app/soapbox/{__mocks__/api.ts => api/__mocks__/index.ts} (92%) rename app/soapbox/{api.ts => api/index.ts} (77%) diff --git a/app/soapbox/__mocks__/api.ts b/app/soapbox/api/__mocks__/index.ts similarity index 92% rename from app/soapbox/__mocks__/api.ts rename to app/soapbox/api/__mocks__/index.ts index 060846c94..dd2f1ec93 100644 --- a/app/soapbox/__mocks__/api.ts +++ b/app/soapbox/api/__mocks__/index.ts @@ -4,7 +4,7 @@ import LinkHeader from 'http-link-header'; import type { AxiosInstance, AxiosResponse } from 'axios'; -const api = jest.requireActual('../api') as Record; +const api = jest.requireActual('../index') as Record; let mocks: Array = []; export const __stub = (func: (mock: MockAdapter) => void) => mocks.push(func); diff --git a/app/soapbox/api.ts b/app/soapbox/api/index.ts similarity index 77% rename from app/soapbox/api.ts rename to app/soapbox/api/index.ts index bdcaf53d8..fde4a1a24 100644 --- a/app/soapbox/api.ts +++ b/app/soapbox/api/index.ts @@ -16,11 +16,11 @@ import { getAccessToken, getAppToken, isURL, parseBaseURL } from 'soapbox/utils/ import type MockAdapter from 'axios-mock-adapter'; /** - Parse Link headers, mostly for pagination. - @see {@link https://www.npmjs.com/package/http-link-header} - @param {object} response - Axios response object - @returns {object} Link object - */ + Parse Link headers, mostly for pagination. + @see {@link https://www.npmjs.com/package/http-link-header} + @param {object} response - Axios response object + @returns {object} Link object + */ export const getLinks = (response: AxiosResponse): LinkHeader => { return new LinkHeader(response.headers?.link); }; @@ -50,11 +50,11 @@ const getAuthBaseURL = createSelector([ }); /** - * Base client for HTTP requests. - * @param {string} accessToken - * @param {string} baseURL - * @returns {object} Axios instance - */ + * Base client for HTTP requests. + * @param {string} accessToken + * @param {string} baseURL + * @returns {object} Axios instance + */ export const baseClient = (accessToken?: string | null, baseURL: string = ''): AxiosInstance => { return axios.create({ // When BACKEND_URL is set, always use it. @@ -68,22 +68,22 @@ export const baseClient = (accessToken?: string | null, baseURL: string = ''): A }; /** - * Dumb client for grabbing static files. - * It uses FE_SUBDIRECTORY and parses JSON if possible. - * No authorization is needed. - */ + * Dumb client for grabbing static files. + * It uses FE_SUBDIRECTORY and parses JSON if possible. + * No authorization is needed. + */ export const staticClient = axios.create({ baseURL: BuildConfig.FE_SUBDIRECTORY, transformResponse: [maybeParseJSON], }); /** - * Stateful API client. - * Uses credentials from the Redux store if available. - * @param {function} getState - Must return the Redux state - * @param {string} authType - Either 'user' or 'app' - * @returns {object} Axios instance - */ + * Stateful API client. + * Uses credentials from the Redux store if available. + * @param {function} getState - Must return the Redux state + * @param {string} authType - Either 'user' or 'app' + * @returns {object} Axios instance + */ export default (getState: () => RootState, authType: string = 'user'): AxiosInstance => { const state = getState(); const accessToken = getToken(state, authType); diff --git a/app/soapbox/jest/test-setup.ts b/app/soapbox/jest/test-setup.ts index 0052388b0..c2a226a48 100644 --- a/app/soapbox/jest/test-setup.ts +++ b/app/soapbox/jest/test-setup.ts @@ -1,6 +1,6 @@ 'use strict'; -import { __clear as clearApiMocks } from '../__mocks__/api'; +import { __clear as clearApiMocks } from '../api/__mocks__'; // API mocking jest.mock('soapbox/api');