@@ -2,6 +2,7 @@ import path from 'node:path';
2
2
import fastifyStatic from '@fastify/static' ;
3
3
import fastifyHelmet from '@fastify/helmet' ;
4
4
import { fastifySwagger } from '@fastify/swagger' ;
5
+ import fastifyCookie from '@fastify/cookie' ;
5
6
import Fastify , { type FastifyInstance } from 'fastify' ;
6
7
import { Hookified , type HookifiedOptions } from 'hookified' ;
7
8
import { detect } from 'detect-port' ;
@@ -16,6 +17,7 @@ import {statusCodeRoute} from './routes/status-codes/index.js';
16
17
import { ipRoute , headersRoute , userAgentRoute } from './routes/request-inspection/index.js' ;
17
18
import { cacheRoutes , etagRoutes , responseHeadersRoutes } from './routes/response-inspection/index.js' ;
18
19
import { absoluteRedirectRoute , relativeRedirectRoute , redirectToRoute } from './routes/redirects/index.js' ;
20
+ import { getCookiesRoute , postCookieRoute , deleteCookieRoute } from './routes/cookies/index.js' ;
19
21
20
22
// eslint-disable-next-line unicorn/prevent-abbreviations
21
23
export type HttpBinOptions = {
@@ -24,6 +26,7 @@ export type HttpBinOptions = {
24
26
requestInspection ?: boolean ;
25
27
responseInspection ?: boolean ;
26
28
statusCodes ?: boolean ;
29
+ cookies ?: boolean ;
27
30
} ;
28
31
29
32
export type MockHttpOptions = {
@@ -70,6 +73,7 @@ export class MockHttp extends Hookified {
70
73
requestInspection : true ,
71
74
responseInspection : true ,
72
75
statusCodes : true ,
76
+ cookies : true ,
73
77
} ;
74
78
75
79
// eslint-disable-next-line new-cap
@@ -245,7 +249,7 @@ export class MockHttp extends Hookified {
245
249
await this . registerApiDocs ( ) ;
246
250
}
247
251
248
- const { httpMethods, redirects, requestInspection, responseInspection, statusCodes} = this . _httpBin ;
252
+ const { httpMethods, redirects, requestInspection, responseInspection, statusCodes, cookies } = this . _httpBin ;
249
253
250
254
if ( httpMethods ) {
251
255
await this . registerHttpMethods ( ) ;
@@ -267,6 +271,10 @@ export class MockHttp extends Hookified {
267
271
await this . registerRedirectRoutes ( ) ;
268
272
}
269
273
274
+ if ( cookies ) {
275
+ await this . registerCookieRoutes ( ) ;
276
+ }
277
+
270
278
if ( this . _autoDetectPort ) {
271
279
const originalPort = this . _port ;
272
280
this . _port = await this . detectPort ( ) ;
@@ -370,6 +378,18 @@ export class MockHttp extends Hookified {
370
378
await fastify . register ( relativeRedirectRoute ) ;
371
379
await fastify . register ( redirectToRoute ) ;
372
380
}
381
+
382
+ /**
383
+ * Register the cookie routes.
384
+ * @param fastifyInstance - the server instance to register the routes on.
385
+ */
386
+ public async registerCookieRoutes ( fastifyInstance ?: FastifyInstance ) : Promise < void > {
387
+ const fastify = fastifyInstance ?? this . _server ;
388
+ await fastify . register ( fastifyCookie ) ;
389
+ await fastify . register ( getCookiesRoute ) ;
390
+ await fastify . register ( postCookieRoute ) ;
391
+ await fastify . register ( deleteCookieRoute ) ;
392
+ }
373
393
}
374
394
375
395
export const mockhttp = MockHttp ;
0 commit comments