Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy committed Jan 29, 2024
1 parent 44c957f commit cad43ea
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions packages/astro/test/units/routing/endpoints.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
createBasicSettings,
createFs,
createRequestAndResponse,
defaultLogger,
} from '../test-utils.js';
import { fileURLToPath } from 'node:url';
import { expect } from 'chai';
import { createContainer } from '../../../dist/core/dev/container.js';
import testAdapter from '../../test-adapter.js';

const root = new URL('../../fixtures/api-routes/', import.meta.url);
const fileSystem = {
'/src/pages/api.ts': `export const GET = ({ url }) => Response.redirect("https://example.com/destination", 307)`,
};

describe('endpoints', () => {
let container;
let settings;

before(async () => {
const fs = createFs(fileSystem, root);
settings = await createBasicSettings({
root: fileURLToPath(root),
output: 'server',
adapter: testAdapter(),
});
container = await createContainer({
fs,
settings,
logger: defaultLogger,
});
});

after(async () => {
await container.close();
});

it('should return a redirect response with location header', async () => {
const { req, res, text, done } = createRequestAndResponse({
method: 'GET',
url: '/api',
});
container.handle(req, res);
await done;
expect(res.getHeaders()).to.deep.include({ location: 'https://example.com/destination' });
expect(res.statusCode).to.equal(307);
});
});

0 comments on commit cad43ea

Please sign in to comment.