mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Separate middleware from Express.
This commit is contained in:
@@ -42,7 +42,6 @@ describe('ExpressHttpServerFactory', (): void => {
|
||||
});
|
||||
|
||||
afterEach(async(): Promise<void> => {
|
||||
// Close server
|
||||
server.close();
|
||||
});
|
||||
|
||||
@@ -50,36 +49,6 @@ describe('ExpressHttpServerFactory', (): void => {
|
||||
mock.mockReset();
|
||||
});
|
||||
|
||||
it('sends server identification in the X-Powered-By header.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/');
|
||||
expect(res.header).toEqual(expect.objectContaining({
|
||||
'x-powered-by': 'Community Solid Server',
|
||||
}));
|
||||
});
|
||||
|
||||
it('returns CORS headers for an OPTIONS request.', async(): Promise<void> => {
|
||||
const res = await request(server)
|
||||
.options('/')
|
||||
.set('Access-Control-Request-Headers', 'content-type')
|
||||
.set('Access-Control-Request-Method', 'POST')
|
||||
.set('Host', 'test.com')
|
||||
.expect(204);
|
||||
expect(res.header).toEqual(expect.objectContaining({
|
||||
'access-control-allow-origin': '*',
|
||||
'access-control-allow-headers': 'content-type',
|
||||
}));
|
||||
const corsMethods = res.header['access-control-allow-methods'].split(',')
|
||||
.map((method: string): string => method.trim());
|
||||
const allowedMethods = [ 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE' ];
|
||||
expect(corsMethods).toEqual(expect.arrayContaining(allowedMethods));
|
||||
expect(corsMethods).toHaveLength(allowedMethods.length);
|
||||
});
|
||||
|
||||
it('specifies CORS origin header if an origin was supplied.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').set('origin', 'test.com').expect(200);
|
||||
expect(res.header).toEqual(expect.objectContaining({ 'access-control-allow-origin': 'test.com' }));
|
||||
});
|
||||
|
||||
it('sends incoming requests to the handler.', async(): Promise<void> => {
|
||||
await request(server).get('/').set('Host', 'test.com').expect(200);
|
||||
expect(canHandleJest).toHaveBeenCalledTimes(1);
|
||||
|
||||
Reference in New Issue
Block a user