Move api into a folder
This commit is contained in:
parent
8b22ca5f27
commit
a202fe68d1
3 changed files with 22 additions and 22 deletions
|
@ -4,7 +4,7 @@ import LinkHeader from 'http-link-header';
|
||||||
|
|
||||||
import type { AxiosInstance, AxiosResponse } from 'axios';
|
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> = [];
|
let mocks: Array<Function> = [];
|
||||||
|
|
||||||
export const __stub = (func: (mock: MockAdapter) => void) => mocks.push(func);
|
export const __stub = (func: (mock: MockAdapter) => void) => mocks.push(func);
|
|
@ -16,11 +16,11 @@ import { getAccessToken, getAppToken, isURL, parseBaseURL } from 'soapbox/utils/
|
||||||
import type MockAdapter from 'axios-mock-adapter';
|
import type MockAdapter from 'axios-mock-adapter';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Parse Link headers, mostly for pagination.
|
Parse Link headers, mostly for pagination.
|
||||||
@see {@link https://www.npmjs.com/package/http-link-header}
|
@see {@link https://www.npmjs.com/package/http-link-header}
|
||||||
@param {object} response - Axios response object
|
@param {object} response - Axios response object
|
||||||
@returns {object} Link object
|
@returns {object} Link object
|
||||||
*/
|
*/
|
||||||
export const getLinks = (response: AxiosResponse): LinkHeader => {
|
export const getLinks = (response: AxiosResponse): LinkHeader => {
|
||||||
return new LinkHeader(response.headers?.link);
|
return new LinkHeader(response.headers?.link);
|
||||||
};
|
};
|
||||||
|
@ -50,11 +50,11 @@ const getAuthBaseURL = createSelector([
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base client for HTTP requests.
|
* Base client for HTTP requests.
|
||||||
* @param {string} accessToken
|
* @param {string} accessToken
|
||||||
* @param {string} baseURL
|
* @param {string} baseURL
|
||||||
* @returns {object} Axios instance
|
* @returns {object} Axios instance
|
||||||
*/
|
*/
|
||||||
export const baseClient = (accessToken?: string | null, baseURL: string = ''): AxiosInstance => {
|
export const baseClient = (accessToken?: string | null, baseURL: string = ''): AxiosInstance => {
|
||||||
return axios.create({
|
return axios.create({
|
||||||
// When BACKEND_URL is set, always use it.
|
// 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.
|
* Dumb client for grabbing static files.
|
||||||
* It uses FE_SUBDIRECTORY and parses JSON if possible.
|
* It uses FE_SUBDIRECTORY and parses JSON if possible.
|
||||||
* No authorization is needed.
|
* No authorization is needed.
|
||||||
*/
|
*/
|
||||||
export const staticClient = axios.create({
|
export const staticClient = axios.create({
|
||||||
baseURL: BuildConfig.FE_SUBDIRECTORY,
|
baseURL: BuildConfig.FE_SUBDIRECTORY,
|
||||||
transformResponse: [maybeParseJSON],
|
transformResponse: [maybeParseJSON],
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stateful API client.
|
* Stateful API client.
|
||||||
* Uses credentials from the Redux store if available.
|
* Uses credentials from the Redux store if available.
|
||||||
* @param {function} getState - Must return the Redux state
|
* @param {function} getState - Must return the Redux state
|
||||||
* @param {string} authType - Either 'user' or 'app'
|
* @param {string} authType - Either 'user' or 'app'
|
||||||
* @returns {object} Axios instance
|
* @returns {object} Axios instance
|
||||||
*/
|
*/
|
||||||
export default (getState: () => RootState, authType: string = 'user'): AxiosInstance => {
|
export default (getState: () => RootState, authType: string = 'user'): AxiosInstance => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const accessToken = getToken(state, authType);
|
const accessToken = getToken(state, authType);
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { __clear as clearApiMocks } from '../__mocks__/api';
|
import { __clear as clearApiMocks } from '../api/__mocks__';
|
||||||
|
|
||||||
// API mocking
|
// API mocking
|
||||||
jest.mock('soapbox/api');
|
jest.mock('soapbox/api');
|
||||||
|
|
Loading…
Reference in a new issue