From 666674327f009e9b1013218fc384f193b64c6997 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 14 Dec 2025 22:39:18 -0800 Subject: Adds unit tests --- tst/fourohfour.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tst/fourohfour.test.ts (limited to 'tst/fourohfour.test.ts') diff --git a/tst/fourohfour.test.ts b/tst/fourohfour.test.ts new file mode 100644 index 0000000..c8fdd6f --- /dev/null +++ b/tst/fourohfour.test.ts @@ -0,0 +1,38 @@ +import { FourOhFourActivityImpl, PenguenoRequest, type BaseRequest, type ServerTrace } from '../lib/index'; +import { CollectingTrace, TestTraceable } from './test_utils'; + +const makeBaseRequest = (overrides: Partial = {}): 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(); + 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"'); + }); +}); -- cgit v1.2.3-70-g09d2