Remove staticClient
This commit is contained in:
parent
d861890488
commit
28bbaae793
|
@ -1,44 +0,0 @@
|
||||||
import MockAdapter from 'axios-mock-adapter';
|
|
||||||
import { describe, expect, it } from 'vitest';
|
|
||||||
|
|
||||||
import { staticClient } from 'soapbox/api/index.ts';
|
|
||||||
import { mockStore } from 'soapbox/jest/test-helpers.tsx';
|
|
||||||
|
|
||||||
import {
|
|
||||||
FETCH_ABOUT_PAGE_REQUEST,
|
|
||||||
FETCH_ABOUT_PAGE_SUCCESS,
|
|
||||||
FETCH_ABOUT_PAGE_FAIL,
|
|
||||||
fetchAboutPage,
|
|
||||||
} from './about.ts';
|
|
||||||
|
|
||||||
describe('fetchAboutPage()', () => {
|
|
||||||
it('creates the expected actions on success', () => {
|
|
||||||
|
|
||||||
const mock = new MockAdapter(staticClient);
|
|
||||||
|
|
||||||
mock.onGet('/instance/about/index.html')
|
|
||||||
.reply(200, '<h1>Hello world</h1>');
|
|
||||||
|
|
||||||
const expectedActions = [
|
|
||||||
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },
|
|
||||||
{ type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index', html: '<h1>Hello world</h1>' },
|
|
||||||
];
|
|
||||||
const store = mockStore({});
|
|
||||||
|
|
||||||
return store.dispatch(fetchAboutPage()).then(() => {
|
|
||||||
expect(store.getActions()).toEqual(expectedActions);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('creates the expected actions on failure', () => {
|
|
||||||
const expectedActions = [
|
|
||||||
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'asdf' },
|
|
||||||
{ type: FETCH_ABOUT_PAGE_FAIL, slug: 'asdf', error: new Error('Request failed with status code 404') },
|
|
||||||
];
|
|
||||||
const store = mockStore({});
|
|
||||||
|
|
||||||
return store.dispatch(fetchAboutPage('asdf')).catch(() => {
|
|
||||||
expect(store.getActions()).toEqual(expectedActions);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -6,7 +6,7 @@ import KVStore from 'soapbox/storage/kv-store.ts';
|
||||||
import { removeVS16s } from 'soapbox/utils/emoji.ts';
|
import { removeVS16s } from 'soapbox/utils/emoji.ts';
|
||||||
import { getFeatures } from 'soapbox/utils/features.ts';
|
import { getFeatures } from 'soapbox/utils/features.ts';
|
||||||
|
|
||||||
import api, { staticClient } from '../api/index.ts';
|
import api from '../api/index.ts';
|
||||||
|
|
||||||
import type { AppDispatch, RootState } from 'soapbox/store.ts';
|
import type { AppDispatch, RootState } from 'soapbox/store.ts';
|
||||||
import type { APIEntity } from 'soapbox/types/entities.ts';
|
import type { APIEntity } from 'soapbox/types/entities.ts';
|
||||||
|
@ -86,7 +86,7 @@ const loadSoapboxConfig = () =>
|
||||||
|
|
||||||
const fetchSoapboxJson = (host: string | null) =>
|
const fetchSoapboxJson = (host: string | null) =>
|
||||||
(dispatch: AppDispatch) =>
|
(dispatch: AppDispatch) =>
|
||||||
staticClient.get('/instance/soapbox.json').then(({ data }) => {
|
fetch('/instance/soapbox.json').then((response) => response.json()).then((data) => {
|
||||||
if (!isObject(data)) throw 'soapbox.json failed';
|
if (!isObject(data)) throw 'soapbox.json failed';
|
||||||
dispatch(importSoapboxConfig(data, host));
|
dispatch(importSoapboxConfig(data, host));
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -15,8 +15,6 @@ const setupMock = (axios: AxiosInstance) => {
|
||||||
mocks.map(func => func(mock));
|
mocks.map(func => func(mock));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const staticClient = api.staticClient;
|
|
||||||
|
|
||||||
export const getLinks = (response: AxiosResponse): LinkHeader => {
|
export const getLinks = (response: AxiosResponse): LinkHeader => {
|
||||||
return new LinkHeader(response.headers?.link);
|
return new LinkHeader(response.headers?.link);
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,16 +82,6 @@ export const baseClient = (
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* Stateful API client.
|
||||||
* Uses credentials from the Redux store if available.
|
* Uses credentials from the Redux store if available.
|
||||||
|
|
Loading…
Reference in New Issue