From 28bbaae793208eebc2a75873b2129fad3efe98d3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 13 Nov 2024 13:38:40 -0600 Subject: [PATCH] Remove staticClient --- src/actions/about.test.ts | 44 -------------------------------------- src/actions/soapbox.ts | 4 ++-- src/api/__mocks__/index.ts | 2 -- src/api/index.ts | 10 --------- 4 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 src/actions/about.test.ts diff --git a/src/actions/about.test.ts b/src/actions/about.test.ts deleted file mode 100644 index 34e5240f7..000000000 --- a/src/actions/about.test.ts +++ /dev/null @@ -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, '

Hello world

'); - - const expectedActions = [ - { type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' }, - { type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index', html: '

Hello world

' }, - ]; - 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); - }); - }); -}); diff --git a/src/actions/soapbox.ts b/src/actions/soapbox.ts index 31e7679b1..cee62ab4f 100644 --- a/src/actions/soapbox.ts +++ b/src/actions/soapbox.ts @@ -6,7 +6,7 @@ import KVStore from 'soapbox/storage/kv-store.ts'; import { removeVS16s } from 'soapbox/utils/emoji.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 { APIEntity } from 'soapbox/types/entities.ts'; @@ -86,7 +86,7 @@ const loadSoapboxConfig = () => const fetchSoapboxJson = (host: string | null) => (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'; dispatch(importSoapboxConfig(data, host)); return data; diff --git a/src/api/__mocks__/index.ts b/src/api/__mocks__/index.ts index d0664bbe6..ff5fba2c2 100644 --- a/src/api/__mocks__/index.ts +++ b/src/api/__mocks__/index.ts @@ -15,8 +15,6 @@ const setupMock = (axios: AxiosInstance) => { mocks.map(func => func(mock)); }; -export const staticClient = api.staticClient; - export const getLinks = (response: AxiosResponse): LinkHeader => { return new LinkHeader(response.headers?.link); }; diff --git a/src/api/index.ts b/src/api/index.ts index 7a7e9aeaf..0898ab576 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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. * Uses credentials from the Redux store if available.