1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import { FourOhFourActivityImpl, PenguenoRequest, type BaseRequest, type ServerTrace } from '../lib/index';
import { CollectingTrace, TestTraceable } from './test_utils';
const makeBaseRequest = (overrides: Partial<BaseRequest> = {}): BaseRequest => ({
url: 'https://example.com/missing',
method: 'GET',
header: () => ({}),
formData: async () => new FormData(),
json: async () => ({}),
text: async () => '',
param: () => undefined,
query: () => ({}),
queries: () => ({}),
...overrides,
});
describe('server/activity/fourohfour (FourOhFourActivityImpl)', () => {
beforeEach(() => {
jest.spyOn(globalThis.crypto, 'randomUUID').mockReturnValue('00000000-0000-0000-0000-000000000000');
jest.spyOn(Math, 'random').mockReturnValue(0);
});
afterEach(() => {
jest.restoreAllMocks();
});
test('returns JsonResponse with 404', async () => {
const trace = new CollectingTrace<ServerTrace>();
const req = PenguenoRequest.from(TestTraceable.of(makeBaseRequest(), trace));
const activity = new FourOhFourActivityImpl();
const resp = await activity.fourOhFour(req);
expect(resp.status).toBe(404);
expect(resp.headers['Content-Type']).toBe('application/json; charset=utf-8');
expect(resp.body()).toContain('"error"');
});
});
|