mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Replace all in-scope axios callsites with a new helpers/http.js wrapper over native fetch, including JSON/text GET, JSON POST, HEAD checks, and transient 5xx retry behavior; update all browser, build, script, and proxy API clients to use it; add focused unit tests; and remove axios from package dependencies. Constraint: Preserve API/build and deployment behavior while lowering transport surface area. Rejected: inline fetch replacements at each callsite | rejected to avoid inconsistent error/retry semantics. Confidence: high Scope-risk: moderate Directive: Keep helper in place as the transport boundary and update tests when changing request semantics. Tested: pnpm run -s typecheck, pnpm -s run test-prebuild, pnpm -s run test, pnpm -s run test:browser, pnpm -s run netlify-build, smoke GETs on /apple-silicon-app-test and /apple-silicon-app-test/?version=2 Not-tested: branch/netlify deployment health in CI pipeline after merge
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import {
|
|
beforeEach,
|
|
describe,
|
|
expect,
|
|
it,
|
|
vi
|
|
} from 'vitest'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
import {
|
|
loadSitemapEndpoints
|
|
} from '~/helpers/pagefind/load-sitemap-endpoints'
|
|
import { getJson } from '~/helpers/http.js'
|
|
|
|
vi.mock( 'fs-extra', () => {
|
|
return {
|
|
default: {
|
|
pathExists: vi.fn(),
|
|
readJson: vi.fn()
|
|
}
|
|
}
|
|
} )
|
|
|
|
vi.mock( '~/helpers/http.js', () => {
|
|
return {
|
|
getJson: vi.fn(),
|
|
shouldRetryError: vi.fn()
|
|
}
|
|
} )
|
|
|
|
describe( 'load sitemap endpoints', () => {
|
|
beforeEach( () => {
|
|
vi.mocked( fs.pathExists ).mockReset()
|
|
vi.mocked( fs.readJson ).mockReset()
|
|
vi.mocked( getJson ).mockReset()
|
|
} )
|
|
|
|
it( 'reads the local sitemap-endpoints file when it exists', async () => {
|
|
vi.mocked( fs.pathExists ).mockResolvedValueOnce( true )
|
|
vi.mocked( fs.readJson ).mockResolvedValueOnce({
|
|
endpoints: [ '/api/app/spotify.json' ]
|
|
} )
|
|
|
|
await expect( loadSitemapEndpoints() ).resolves.toEqual({
|
|
endpoints: [ '/api/app/spotify.json' ]
|
|
})
|
|
|
|
expect( getJson ).not.toHaveBeenCalled()
|
|
} )
|
|
|
|
it( 'falls back to the remote sitemap-endpoints JSON when the local file is missing', async () => {
|
|
vi.mocked( fs.pathExists ).mockResolvedValueOnce( false )
|
|
vi.mocked( getJson ).mockResolvedValueOnce({
|
|
endpoints: [ '/api/app/electron-framework.json' ]
|
|
} )
|
|
process.env.PUBLIC_API_DOMAIN = 'https://api.doesitarm.com'
|
|
|
|
await expect( loadSitemapEndpoints() ).resolves.toEqual({
|
|
endpoints: [ '/api/app/electron-framework.json' ]
|
|
} )
|
|
|
|
expect( getJson ).toHaveBeenCalledWith( 'https://api.doesitarm.com/sitemap-endpoints.json', {
|
|
attempts: 3,
|
|
delayMs: 1000
|
|
})
|
|
} )
|
|
} )
|