atproto/packages/ozone/tests/server.test.ts
Matthieu Sieben 72eba67af1
Drop axios dependency (#3177)
* Minor adaptation of VerifyCidTransform implementation

* refactor: factorize content-encoding negotiation into new lib

* bsky: Use undici to stream blob

* fixup! bsky: Use undici to stream blob

* disable ssrf bsky protection in dev-env

* remove http requests to self to host "/img/"

* drop axios from tests

* fixes

* fix tests

* reviex changes

* properly handle HEAD requests

* handle client disconnection

* fix tests

* drop unrelated change

* tidy

* tidy

* tidy

* remove axios from dev-env

* remove axios from identity package

* use undici 6

* remove axios dependency from ozone

* tidy

* remove axios from PDS package

* avoid killing bsky-pds connections

* improve debugging data

* Better handle invalid CID

* tidy

* tidy

* refactor "allFulfilled" util in @atproto/common

* tidy

---------

Co-authored-by: devin ivy <devinivy@gmail.com>
2025-01-06 18:34:11 +01:00

66 lines
1.8 KiB
TypeScript

import { TestNetwork, TestOzone } from '@atproto/dev-env'
import express from 'express'
import { handler as errorHandler } from '../src/error'
import { startServer } from './_util'
describe('server', () => {
let network: TestNetwork
let ozone: TestOzone
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'ozone_server',
})
ozone = network.ozone
})
afterAll(async () => {
await network.close()
})
it('preserves 404s.', async () => {
const response = await fetch(`${ozone.url}/unknown`)
expect(response.status).toEqual(404)
})
it('error handler turns unknown errors into 500s.', async () => {
const app = express()
.get('/oops', () => {
throw new Error('Oops!')
})
.use(errorHandler)
const { origin, stop } = await startServer(app)
try {
const response = await fetch(new URL(`/oops`, origin))
expect(response.status).toEqual(500)
await expect(response.json()).resolves.toEqual({
error: 'InternalServerError',
message: 'Internal Server Error',
})
} finally {
await stop()
}
})
it('healthcheck succeeds when database is available.', async () => {
const response = await fetch(`${network.bsky.url}/xrpc/_health`)
expect(response.status).toEqual(200)
await expect(response.json()).resolves.toEqual({ version: 'unknown' })
})
it('healthcheck fails when database is unavailable.', async () => {
// destroy sequencer to release connection that would prevent the db from closing
await ozone.ctx.sequencer.destroy()
await ozone.ctx.db.close()
const res = await fetch(`${ozone.url}/xrpc/_health`)
expect(res.status).toEqual(503)
await expect(res.json()).resolves.toEqual({
version: '0.0.0',
error: 'Service Unavailable',
})
})
})