techdocs-backend: fix http mock in cacheMiddleware test

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-07-12 13:28:05 +02:00
parent 3ded9cc158
commit 0d0b86fb5b
2 changed files with 28 additions and 22 deletions
+14 -11
View File
@@ -23,17 +23,20 @@ import { createCacheMiddleware, TechDocsCache } from '.';
* Mocks cached HTTP response.
*/
const getMockHttpResponseFor = (content: string): Buffer => {
return Buffer.concat([
Buffer.from(`HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Sat, 1 Jul 2021 12:00:00 GMT
Date: Sat, 1 Jul 2021 12:00:00 GMT
Connection: close
Content-Length: ${content.length}\n\n`),
Buffer.from(content),
]);
return Buffer.from(
[
'HTTP/1.1 200 OK',
'Content-Type: text/plain; charset=utf-8',
'Accept-Ranges: bytes',
'Cache-Control: public, max-age=0',
'Last-Modified: Sat, 1 Jul 2021 12:00:00 GMT',
'Date: Sat, 1 Jul 2021 12:00:00 GMT',
'Connection: close',
`Content-Length: ${content.length}`,
'',
content,
].join('\r\n'),
);
};
/**
@@ -56,17 +56,20 @@ const MockTechDocsCache = {
TechDocsCache.fromConfig = () => MockTechDocsCache;
const getMockHttpResponseFor = (content: string): Buffer => {
return Buffer.concat([
Buffer.from(`HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Sat, 1 Jul 2021 12:00:00 GMT
Date: Sat, 1 Jul 2021 12:00:00 GMT
Connection: close
Content-Length: ${content.length}\n\n`),
Buffer.from(content),
]);
return Buffer.from(
[
'HTTP/1.1 200 OK',
'Content-Type: text/plain; charset=utf-8',
'Accept-Ranges: bytes',
'Cache-Control: public, max-age=0',
'Last-Modified: Sat, 1 Jul 2021 12:00:00 GMT',
'Date: Sat, 1 Jul 2021 12:00:00 GMT',
'Connection: close',
`Content-Length: ${content.length}`,
'',
content,
].join('\r\n'),
);
};
const createApp = async (options: RouterOptions) => {