Move api into a folder

environments/review-organize-s-nqfs0j/deployments/1394
Chewbacca 2022-11-15 08:43:26 -05:00
rodzic 8b22ca5f27
commit a202fe68d1
3 zmienionych plików z 22 dodań i 22 usunięć

Wyświetl plik

@ -4,7 +4,7 @@ import LinkHeader from 'http-link-header';
import type { AxiosInstance, AxiosResponse } from 'axios';
const api = jest.requireActual('../api') as Record<string, Function>;
const api = jest.requireActual('../index') as Record<string, Function>;
let mocks: Array<Function> = [];
export const __stub = (func: (mock: MockAdapter) => void) => mocks.push(func);

Wyświetl plik

@ -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);

Wyświetl plik

@ -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');