Lets the CI preview server stand in for the contact API
With contactForm.enabled=true the e2e and Lighthouse runs asked a token route that CI does not have (404, console error, run 666). The preview server gets an opt-in --contact-stub (token 200 without captcha, submit 202); the e2e server helper and the Lighthouse start command switch it on. Tests that need another answer still replace it per page with page.route. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -570,7 +570,7 @@ function siteDir(): string {
|
||||
|
||||
async function serve(
|
||||
clientDir: string,
|
||||
options?: { auditRoute?: boolean },
|
||||
options?: { auditRoute?: boolean; contactStub?: boolean },
|
||||
): Promise<number> {
|
||||
const server = await startPreviewServer(clientDir, 0, options);
|
||||
servers.push(server);
|
||||
@@ -652,6 +652,28 @@ describe('startPreviewServer', () => {
|
||||
expect((await ask(port, '/andere')).status).toBe(404);
|
||||
});
|
||||
|
||||
it('bootst de contact-API alleen na met de optie (--contact-stub)', async () => {
|
||||
const without = await serve(siteDir());
|
||||
expect(
|
||||
(await ask(without, '/api/v1/contact-messages/token')).status,
|
||||
).toBe(404);
|
||||
|
||||
const port = await serve(siteDir(), { contactStub: true });
|
||||
const token = await ask(port, '/api/v1/contact-messages/token');
|
||||
expect(token.status).toBe(200);
|
||||
expect(token.headers['content-type']).toBe('application/json');
|
||||
expect(JSON.parse(token.body)).toMatchObject({
|
||||
captcha: null,
|
||||
minSeconds: expect.any(Number),
|
||||
});
|
||||
expect(
|
||||
(await ask(port, '/api/v1/contact-messages', 'POST')).status,
|
||||
).toBe(202);
|
||||
// Al het andere blijft zoals het was
|
||||
expect((await ask(port, '/api/v1/andere')).status).toBe(404);
|
||||
expect((await ask(port, '/api/v1/contact-messages')).status).toBe(404);
|
||||
});
|
||||
|
||||
it('stuurt een 301 met een relatieve Location, de query en de securityheaders, zonder inhoud', async () => {
|
||||
const port = await serve(siteDir());
|
||||
const expected = securityHeaders('production');
|
||||
|
||||
Reference in New Issue
Block a user