mirror of
https://github.com/withastro/astro.git
synced 2025-04-07 23:41:43 -05:00
chore: add tests for HEAD requests to endpoints (#13239)
* chore: add tests for HEAD requests to endpoints * Fix test * chore: run tests on ssr fixture Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com>
This commit is contained in:
parent
1a9363745e
commit
65f7e09901
3 changed files with 37 additions and 1 deletions
5
packages/astro/test/fixtures/ssr-api-route/src/pages/custom-status.ts
vendored
Normal file
5
packages/astro/test/fixtures/ssr-api-route/src/pages/custom-status.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import type { APIRoute } from 'astro';
|
||||
|
||||
export const GET: APIRoute = async function () {
|
||||
return new Response("hello world", { status: 403, headers: { "x-hello": 'world' } });
|
||||
};
|
|
@ -53,6 +53,38 @@ describe('API routes in SSR', () => {
|
|||
assert.equal(data.clientAddress, '0.0.0.0');
|
||||
assert.equal(data.site, 'https://mysite.dev/subsite/');
|
||||
});
|
||||
|
||||
describe('custom status', () => {
|
||||
it('should return a custom status code and empty body for HEAD', async () => {
|
||||
const request = new Request('http://example.com/custom-status', { method: 'HEAD' });
|
||||
const response = await app.render(request);
|
||||
const text = await response.text();
|
||||
assert.equal(response.status, 403);
|
||||
assert.equal(text, '');
|
||||
});
|
||||
|
||||
it('should return a 403 status code with the correct body for GET', async () => {
|
||||
const request = new Request('http://example.com/custom-status');
|
||||
const response = await app.render(request);
|
||||
const text = await response.text();
|
||||
assert.equal(response.status, 403);
|
||||
assert.equal(text, 'hello world');
|
||||
});
|
||||
|
||||
it('should return the correct headers for GET', async () => {
|
||||
const request = new Request('http://example.com/custom-status');
|
||||
const response = await app.render(request);
|
||||
const headers = response.headers.get('x-hello');
|
||||
assert.equal(headers, 'world');
|
||||
});
|
||||
|
||||
it('should return the correct headers for HEAD', async () => {
|
||||
const request = new Request('http://example.com/custom-status', { method: 'HEAD' });
|
||||
const response = await app.render(request);
|
||||
const headers = response.headers.get('x-hello');
|
||||
assert.equal(headers, 'world');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Dev', () => {
|
||||
|
|
1
pnpm-lock.yaml
generated
1
pnpm-lock.yaml
generated
|
@ -10172,7 +10172,6 @@ packages:
|
|||
|
||||
libsql@0.4.5:
|
||||
resolution: {integrity: sha512-sorTJV6PNt94Wap27Sai5gtVLIea4Otb2LUiAUyr3p6BPOScGMKGt5F1b5X/XgkNtcsDKeX5qfeBDj+PdShclQ==}
|
||||
cpu: [x64, arm64, wasm32]
|
||||
os: [darwin, linux, win32]
|
||||
|
||||
lightningcss-darwin-arm64@1.29.1:
|
||||
|
|
Loading…
Add table
Reference in a new issue