mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: return contenttype header value string with parameters
This commit is contained in:
committed by
Joachim Van Herwegen
parent
e0954cf2a7
commit
311f8756ec
@@ -0,0 +1,43 @@
|
||||
import { createResponse } from 'node-mocks-http';
|
||||
import { ContentTypeMetadataWriter } from '../../../../../src/http/output/metadata/ContentTypeMetadataWriter';
|
||||
import { RepresentationMetadata } from '../../../../../src/http/representation/RepresentationMetadata';
|
||||
import type { HttpResponse } from '../../../../../src/server/HttpResponse';
|
||||
|
||||
describe('A ContentTypeMetadataWriter', (): void => {
|
||||
const writer = new ContentTypeMetadataWriter();
|
||||
let response: HttpResponse;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
response = createResponse() as HttpResponse;
|
||||
});
|
||||
|
||||
it('adds no header if there is no relevant metadata.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata();
|
||||
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
|
||||
expect(response.getHeaders()).toEqual({ });
|
||||
});
|
||||
|
||||
it('adds a Content-Type header with parameters if present.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata('text/plain; charset=utf-8');
|
||||
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
|
||||
|
||||
expect(response.getHeaders()).toEqual({
|
||||
'content-type': 'text/plain; charset=utf-8',
|
||||
});
|
||||
|
||||
const metadata2 = new RepresentationMetadata('text/plain; charset="utf-8"');
|
||||
await expect(writer.handle({ response, metadata: metadata2 })).resolves.toBeUndefined();
|
||||
expect(response.getHeaders()).toEqual({
|
||||
'content-type': 'text/plain; charset=utf-8',
|
||||
});
|
||||
});
|
||||
|
||||
it('adds a Content-Type header without parameters.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata('text/plain');
|
||||
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
|
||||
|
||||
expect(response.getHeaders()).toEqual({
|
||||
'content-type': 'text/plain',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user