@geekmidas/constructs 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { EnvironmentParser } from '@geekmidas/envkit';
2
- import type { APIGatewayProxyEventV2, Context } from 'aws-lambda';
3
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { createMockContext, createMockV2Event } from '@geekmidas/testkit/aws';
3
+ import type { Context } from 'aws-lambda';
4
+ import { beforeEach, describe, expect, it } from 'vitest';
4
5
  import { z } from 'zod';
5
6
  import { AmazonApiGatewayV2Endpoint } from '../AmazonApiGatewayV2EndpointAdaptor';
6
7
  import { e } from '../EndpointFactory';
@@ -11,20 +12,7 @@ describe('AmazonApiGatewayV2Endpoint', () => {
11
12
 
12
13
  beforeEach(() => {
13
14
  envParser = new EnvironmentParser({});
14
- mockContext = {
15
- functionName: 'test-function',
16
- functionVersion: '1',
17
- awsRequestId: 'test-request-id',
18
- invokedFunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:test',
19
- memoryLimitInMB: '128',
20
- logGroupName: '/aws/lambda/test',
21
- logStreamName: '2024/01/01/[$LATEST]test',
22
- callbackWaitsForEmptyEventLoop: true,
23
- getRemainingTimeInMillis: () => 30000,
24
- done: vi.fn(),
25
- fail: vi.fn(),
26
- succeed: vi.fn(),
27
- };
15
+ mockContext = createMockContext();
28
16
  });
29
17
 
30
18
  describe('getInput', () => {
@@ -32,36 +20,12 @@ describe('AmazonApiGatewayV2Endpoint', () => {
32
20
  const endpoint = e.get('/test').handle(() => ({ success: true }));
33
21
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
34
22
 
35
- const event: APIGatewayProxyEventV2 = {
36
- version: '2.0',
37
- routeKey: 'GET /test',
38
- rawPath: '/test',
23
+ const event = createMockV2Event({
39
24
  rawQueryString: 'foo=bar&baz=qux',
40
- cookies: [],
41
- headers: {},
42
25
  queryStringParameters: { foo: 'bar', baz: 'qux' },
43
26
  pathParameters: { id: '123' },
44
- requestContext: {
45
- accountId: '123456789012',
46
- apiId: 'api-id',
47
- domainName: 'api.example.com',
48
- domainPrefix: 'api',
49
- http: {
50
- method: 'GET',
51
- path: '/test',
52
- protocol: 'HTTP/1.1',
53
- sourceIp: '127.0.0.1',
54
- userAgent: 'test-agent',
55
- },
56
- requestId: 'request-id',
57
- routeKey: 'GET /test',
58
- stage: 'prod',
59
- time: '01/Jan/2024:00:00:00 +0000',
60
- timeEpoch: 1704067200000,
61
- },
62
27
  body: JSON.stringify({ name: 'test' }),
63
- isBase64Encoded: false,
64
- };
28
+ });
65
29
 
66
30
  const result = adapter.getInput(event);
67
31
 
@@ -76,33 +40,7 @@ describe('AmazonApiGatewayV2Endpoint', () => {
76
40
  const endpoint = e.get('/test').handle(() => ({ success: true }));
77
41
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
78
42
 
79
- const event: APIGatewayProxyEventV2 = {
80
- version: '2.0',
81
- routeKey: 'GET /test',
82
- rawPath: '/test',
83
- rawQueryString: '',
84
- cookies: [],
85
- headers: {},
86
- requestContext: {
87
- accountId: '123456789012',
88
- apiId: 'api-id',
89
- domainName: 'api.example.com',
90
- domainPrefix: 'api',
91
- http: {
92
- method: 'GET',
93
- path: '/test',
94
- protocol: 'HTTP/1.1',
95
- sourceIp: '127.0.0.1',
96
- userAgent: 'test-agent',
97
- },
98
- requestId: 'request-id',
99
- routeKey: 'GET /test',
100
- stage: 'prod',
101
- time: '01/Jan/2024:00:00:00 +0000',
102
- timeEpoch: 1704067200000,
103
- },
104
- isBase64Encoded: false,
105
- };
43
+ const event = createMockV2Event();
106
44
 
107
45
  const result = adapter.getInput(event);
108
46
 
@@ -119,18 +57,9 @@ describe('AmazonApiGatewayV2Endpoint', () => {
119
57
  const endpoint = e.get('/test').handle(() => ({ success: true }));
120
58
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
121
59
 
122
- const event: APIGatewayProxyEventV2 = {
123
- version: '2.0',
124
- routeKey: 'GET /test',
125
- rawPath: '/test',
126
- rawQueryString: '',
127
- cookies: [],
128
- headers: {},
60
+ const event = createMockV2Event({
129
61
  requestContext: {
130
- accountId: '123456789012',
131
- apiId: 'api-id',
132
- domainName: 'api.example.com',
133
- domainPrefix: 'api',
62
+ ...createMockV2Event().requestContext,
134
63
  http: {
135
64
  method: 'GET',
136
65
  path: '/test/123',
@@ -139,13 +68,8 @@ describe('AmazonApiGatewayV2Endpoint', () => {
139
68
  userAgent: 'Mozilla/5.0 Test',
140
69
  },
141
70
  requestId: 'event-request-id',
142
- routeKey: 'GET /test',
143
- stage: 'prod',
144
- time: '01/Jan/2024:00:00:00 +0000',
145
- timeEpoch: 1704067200000,
146
71
  },
147
- isBase64Encoded: false,
148
- };
72
+ });
149
73
 
150
74
  const result = adapter.getLoggerContext(event, mockContext);
151
75
 
@@ -168,18 +92,9 @@ describe('AmazonApiGatewayV2Endpoint', () => {
168
92
  const endpoint = e.get('/test').handle(() => ({ success: true }));
169
93
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
170
94
 
171
- const event: APIGatewayProxyEventV2 = {
172
- version: '2.0',
173
- routeKey: 'GET /test',
174
- rawPath: '/test',
175
- rawQueryString: '',
176
- cookies: [],
177
- headers: {},
95
+ const event = createMockV2Event({
178
96
  requestContext: {
179
- accountId: '123456789012',
180
- apiId: 'api-id',
181
- domainName: 'api.example.com',
182
- domainPrefix: 'api',
97
+ ...createMockV2Event().requestContext,
183
98
  http: {
184
99
  method: 'GET',
185
100
  path: '/test',
@@ -187,14 +102,8 @@ describe('AmazonApiGatewayV2Endpoint', () => {
187
102
  sourceIp: '127.0.0.1',
188
103
  userAgent: '',
189
104
  },
190
- requestId: 'request-id',
191
- routeKey: 'GET /test',
192
- stage: 'prod',
193
- time: '01/Jan/2024:00:00:00 +0000',
194
- timeEpoch: 1704067200000,
195
105
  },
196
- isBase64Encoded: false,
197
- };
106
+ });
198
107
 
199
108
  const result = adapter.getLoggerContext(event, mockContext);
200
109
 
@@ -215,34 +124,12 @@ describe('AmazonApiGatewayV2Endpoint', () => {
215
124
 
216
125
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
217
126
 
218
- const event: APIGatewayProxyEventV2 = {
219
- version: '2.0',
127
+ const event = createMockV2Event({
220
128
  routeKey: 'POST /users',
221
129
  rawPath: '/users',
222
- rawQueryString: '',
223
- cookies: [],
224
130
  headers: { 'content-type': 'application/json' },
225
- requestContext: {
226
- accountId: '123456789012',
227
- apiId: 'api-id',
228
- domainName: 'api.example.com',
229
- domainPrefix: 'api',
230
- http: {
231
- method: 'POST',
232
- path: '/users',
233
- protocol: 'HTTP/1.1',
234
- sourceIp: '127.0.0.1',
235
- userAgent: 'test',
236
- },
237
- requestId: 'request-id',
238
- routeKey: 'POST /users',
239
- stage: 'prod',
240
- time: '01/Jan/2024:00:00:00 +0000',
241
- timeEpoch: 1704067200000,
242
- },
243
131
  body: JSON.stringify({ name: 'John', age: 30 }),
244
- isBase64Encoded: false,
245
- };
132
+ });
246
133
  // @ts-ignore
247
134
  const response = await adapter.handler(event, mockContext);
248
135
 
@@ -274,37 +161,15 @@ describe('AmazonApiGatewayV2Endpoint', () => {
274
161
 
275
162
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
276
163
 
277
- const event: APIGatewayProxyEventV2 = {
278
- version: '2.0',
164
+ const event = createMockV2Event({
279
165
  routeKey: 'GET /search',
280
166
  rawPath: '/search',
281
167
  rawQueryString: 'tags=nodejs,typescript,javascript&limit=20',
282
- cookies: [],
283
- headers: {},
284
168
  queryStringParameters: {
285
169
  tags: 'nodejs,typescript,javascript',
286
170
  limit: '20',
287
171
  },
288
- requestContext: {
289
- accountId: '123456789012',
290
- apiId: 'api-id',
291
- domainName: 'api.example.com',
292
- domainPrefix: 'api',
293
- http: {
294
- method: 'GET',
295
- path: '/search',
296
- protocol: 'HTTP/1.1',
297
- sourceIp: '127.0.0.1',
298
- userAgent: 'test',
299
- },
300
- requestId: 'request-id',
301
- routeKey: 'GET /search',
302
- stage: 'prod',
303
- time: '01/Jan/2024:00:00:00 +0000',
304
- timeEpoch: 1704067200000,
305
- },
306
- isBase64Encoded: false,
307
- };
172
+ });
308
173
  // @ts-ignore
309
174
  const response = await adapter.handler(event, mockContext);
310
175
 
@@ -342,37 +207,15 @@ describe('AmazonApiGatewayV2Endpoint', () => {
342
207
 
343
208
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
344
209
 
345
- const event: APIGatewayProxyEventV2 = {
346
- version: '2.0',
210
+ const event = createMockV2Event({
347
211
  routeKey: 'GET /search',
348
212
  rawPath: '/search',
349
213
  rawQueryString: 'filter.category=electronics&filter.active=true',
350
- cookies: [],
351
- headers: {},
352
214
  queryStringParameters: {
353
215
  'filter.category': 'electronics',
354
216
  'filter.active': 'true',
355
217
  },
356
- requestContext: {
357
- accountId: '123456789012',
358
- apiId: 'api-id',
359
- domainName: 'api.example.com',
360
- domainPrefix: 'api',
361
- http: {
362
- method: 'GET',
363
- path: '/search',
364
- protocol: 'HTTP/1.1',
365
- sourceIp: '127.0.0.1',
366
- userAgent: 'test',
367
- },
368
- requestId: 'request-id',
369
- routeKey: 'GET /search',
370
- stage: 'prod',
371
- time: '01/Jan/2024:00:00:00 +0000',
372
- timeEpoch: 1704067200000,
373
- },
374
- isBase64Encoded: false,
375
- };
218
+ });
376
219
  // @ts-ignore
377
220
  const response = await adapter.handler(event, mockContext);
378
221
 
@@ -400,35 +243,13 @@ describe('AmazonApiGatewayV2Endpoint', () => {
400
243
 
401
244
  const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
402
245
 
403
- const event: APIGatewayProxyEventV2 = {
404
- version: '2.0',
246
+ const event = createMockV2Event({
405
247
  routeKey: 'GET /users/{id}',
406
248
  rawPath: '/users/123',
407
249
  rawQueryString: 'include=profile',
408
- cookies: [],
409
- headers: {},
410
250
  queryStringParameters: { include: 'profile' },
411
251
  pathParameters: { id: '123' },
412
- requestContext: {
413
- accountId: '123456789012',
414
- apiId: 'api-id',
415
- domainName: 'api.example.com',
416
- domainPrefix: 'api',
417
- http: {
418
- method: 'GET',
419
- path: '/users/123',
420
- protocol: 'HTTP/1.1',
421
- sourceIp: '127.0.0.1',
422
- userAgent: 'test',
423
- },
424
- requestId: 'request-id',
425
- routeKey: 'GET /users/{id}',
426
- stage: 'prod',
427
- time: '01/Jan/2024:00:00:00 +0000',
428
- timeEpoch: 1704067200000,
429
- },
430
- isBase64Encoded: false,
431
- };
252
+ });
432
253
  // @ts-ignore
433
254
  const response = await adapter.handler(event, mockContext);
434
255
 
@@ -437,5 +258,161 @@ describe('AmazonApiGatewayV2Endpoint', () => {
437
258
  body: JSON.stringify({ id: '123', include: 'profile' }),
438
259
  });
439
260
  });
261
+
262
+ describe('response metadata', () => {
263
+ it('should set response cookies', async () => {
264
+ const endpoint = e
265
+ .get('/test')
266
+ .output(z.object({ success: z.boolean() }))
267
+ .handle((_, response) => {
268
+ response.cookie('session', 'abc123', {
269
+ httpOnly: true,
270
+ secure: true,
271
+ });
272
+ return { success: true };
273
+ });
274
+
275
+ const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
276
+ const event = createMockV2Event();
277
+ // @ts-ignore
278
+ const response = await adapter.handler(event, mockContext);
279
+
280
+ expect(response.multiValueHeaders?.['Set-Cookie']).toEqual([
281
+ 'session=abc123; HttpOnly; Secure',
282
+ ]);
283
+ expect(response.statusCode).toBe(200);
284
+ expect(response.body).toBe(JSON.stringify({ success: true }));
285
+ });
286
+
287
+ it('should set custom headers', async () => {
288
+ const endpoint = e
289
+ .get('/test')
290
+ .output(z.object({ success: z.boolean() }))
291
+ .handle((_, response) => {
292
+ response.header('X-Custom-Header', 'custom-value');
293
+ response.header('X-Request-Id', '12345');
294
+ return { success: true };
295
+ });
296
+
297
+ const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
298
+ const event = createMockV2Event();
299
+ // @ts-ignore
300
+ const response = await adapter.handler(event, mockContext);
301
+
302
+ expect(response.headers).toEqual({
303
+ 'X-Custom-Header': 'custom-value',
304
+ 'X-Request-Id': '12345',
305
+ });
306
+ });
307
+
308
+ it('should set custom status code', async () => {
309
+ const endpoint = e
310
+ .post('/test')
311
+ .output(z.object({ id: z.string() }))
312
+ .handle((_, response) => {
313
+ response.status(201);
314
+ return { id: '123' };
315
+ });
316
+
317
+ const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
318
+ const event = createMockV2Event({ routeKey: 'POST /test' });
319
+ // @ts-ignore
320
+ const response = await adapter.handler(event, mockContext);
321
+
322
+ expect(response.statusCode).toBe(201);
323
+ });
324
+
325
+ it('should combine cookies, headers, and status', async () => {
326
+ const endpoint = e
327
+ .post('/test')
328
+ .output(z.object({ id: z.string() }))
329
+ .handle((_, response) => {
330
+ response
331
+ .status(201)
332
+ .header('Location', '/test/123')
333
+ .cookie('session', 'abc123', { httpOnly: true })
334
+ .cookie('theme', 'dark');
335
+ return { id: '123' };
336
+ });
337
+
338
+ const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
339
+ const event = createMockV2Event({ routeKey: 'POST /test' });
340
+ // @ts-ignore
341
+ const response = await adapter.handler(event, mockContext);
342
+
343
+ expect(response.statusCode).toBe(201);
344
+ expect(response.headers).toEqual({ Location: '/test/123' });
345
+ expect(response.multiValueHeaders?.['Set-Cookie']).toEqual([
346
+ 'session=abc123; HttpOnly',
347
+ 'theme=dark',
348
+ ]);
349
+ });
350
+
351
+ it('should delete cookies', async () => {
352
+ const endpoint = e
353
+ .get('/test')
354
+ .output(z.object({ success: z.boolean() }))
355
+ .handle((_, response) => {
356
+ response.deleteCookie('session', {
357
+ path: '/',
358
+ domain: '.example.com',
359
+ });
360
+ return { success: true };
361
+ });
362
+
363
+ const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
364
+ const event = createMockV2Event();
365
+ // @ts-ignore
366
+ const response = await adapter.handler(event, mockContext);
367
+
368
+ expect(response.multiValueHeaders?.['Set-Cookie']).toEqual([
369
+ 'session=; Domain=.example.com; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0',
370
+ ]);
371
+ });
372
+
373
+ it('should use send() method with metadata', async () => {
374
+ const endpoint = e
375
+ .get('/test')
376
+ .output(z.object({ id: z.string() }))
377
+ .handle((_, response) => {
378
+ return response
379
+ .status(201)
380
+ .header('X-Custom', 'value')
381
+ .cookie('session', 'abc123')
382
+ .send({ id: '123' });
383
+ });
384
+
385
+ const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
386
+ const event = createMockV2Event();
387
+ // @ts-ignore
388
+ const response = await adapter.handler(event, mockContext);
389
+
390
+ expect(response.statusCode).toBe(201);
391
+ expect(response.headers).toEqual({ 'X-Custom': 'value' });
392
+ expect(response.multiValueHeaders?.['Set-Cookie']).toEqual([
393
+ 'session=abc123',
394
+ ]);
395
+ expect(response.body).toBe(JSON.stringify({ id: '123' }));
396
+ });
397
+
398
+ it('should return simple response without metadata when not using response builder', async () => {
399
+ const endpoint = e
400
+ .get('/test')
401
+ .output(z.object({ success: z.boolean() }))
402
+ .handle(() => ({ success: true }));
403
+
404
+ const adapter = new AmazonApiGatewayV2Endpoint(envParser, endpoint);
405
+ const event = createMockV2Event();
406
+ // @ts-ignore
407
+ const response = await adapter.handler(event, mockContext);
408
+
409
+ expect(response).toEqual({
410
+ statusCode: 200,
411
+ body: JSON.stringify({ success: true }),
412
+ });
413
+ expect(response.headers).toBeUndefined();
414
+ expect(response.multiValueHeaders).toBeUndefined();
415
+ });
416
+ });
440
417
  });
441
418
  });
@@ -0,0 +1,120 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { Endpoint } from '../Endpoint';
3
+
4
+ describe('Endpoint.createCookies', () => {
5
+ it('should parse single cookie', () => {
6
+ const cookieFn = Endpoint.createCookies('session=abc123');
7
+
8
+ expect(cookieFn('session')).toBe('abc123');
9
+ });
10
+
11
+ it('should parse multiple cookies', () => {
12
+ const cookieFn = Endpoint.createCookies(
13
+ 'session=abc123; theme=dark; lang=en',
14
+ );
15
+
16
+ expect(cookieFn('session')).toBe('abc123');
17
+ expect(cookieFn('theme')).toBe('dark');
18
+ expect(cookieFn('lang')).toBe('en');
19
+ });
20
+
21
+ it('should handle cookies with spaces', () => {
22
+ const cookieFn = Endpoint.createCookies('session=abc123 ; theme=dark');
23
+
24
+ expect(cookieFn('session')).toBe('abc123');
25
+ expect(cookieFn('theme')).toBe('dark');
26
+ });
27
+
28
+ it('should handle URL encoded values', () => {
29
+ const cookieFn = Endpoint.createCookies(
30
+ 'user=John%20Doe; email=john%40example.com',
31
+ );
32
+
33
+ expect(cookieFn('user')).toBe('John Doe');
34
+ expect(cookieFn('email')).toBe('john@example.com');
35
+ });
36
+
37
+ it('should handle cookies with equals sign in value', () => {
38
+ const cookieFn = Endpoint.createCookies(
39
+ 'data=key=value; token=abc=123=xyz',
40
+ );
41
+
42
+ expect(cookieFn('data')).toBe('key=value');
43
+ expect(cookieFn('token')).toBe('abc=123=xyz');
44
+ });
45
+
46
+ it('should return undefined for non-existent cookie', () => {
47
+ const cookieFn = Endpoint.createCookies('session=abc123');
48
+
49
+ expect(cookieFn('nonexistent')).toBeUndefined();
50
+ });
51
+
52
+ it('should handle empty cookie string', () => {
53
+ const cookieFn = Endpoint.createCookies('');
54
+
55
+ expect(cookieFn('session')).toBeUndefined();
56
+ });
57
+
58
+ it('should handle undefined cookie string', () => {
59
+ const cookieFn = Endpoint.createCookies(undefined);
60
+
61
+ expect(cookieFn('session')).toBeUndefined();
62
+ });
63
+
64
+ it('should handle malformed cookies gracefully', () => {
65
+ const cookieFn = Endpoint.createCookies('session=; =value; valid=okay');
66
+
67
+ expect(cookieFn('session')).toBe('');
68
+ expect(cookieFn('valid')).toBe('okay');
69
+ });
70
+
71
+ it('should handle cookies with special characters', () => {
72
+ const cookieFn = Endpoint.createCookies(
73
+ 'token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0',
74
+ );
75
+
76
+ expect(cookieFn('token')).toBe(
77
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0',
78
+ );
79
+ });
80
+
81
+ it('should handle cookies with numeric values', () => {
82
+ const cookieFn = Endpoint.createCookies('count=42; price=19.99');
83
+
84
+ expect(cookieFn('count')).toBe('42');
85
+ expect(cookieFn('price')).toBe('19.99');
86
+ });
87
+
88
+ it('should handle empty cookie value', () => {
89
+ const cookieFn = Endpoint.createCookies('empty=; session=abc123');
90
+
91
+ expect(cookieFn('empty')).toBe('');
92
+ expect(cookieFn('session')).toBe('abc123');
93
+ });
94
+
95
+ it('should preserve case sensitivity in cookie names', () => {
96
+ const cookieFn = Endpoint.createCookies('Session=abc; session=xyz');
97
+
98
+ expect(cookieFn('Session')).toBe('abc');
99
+ expect(cookieFn('session')).toBe('xyz');
100
+ });
101
+
102
+ it('should handle cookies with trailing semicolon', () => {
103
+ const cookieFn = Endpoint.createCookies('session=abc123; theme=dark;');
104
+
105
+ expect(cookieFn('session')).toBe('abc123');
106
+ expect(cookieFn('theme')).toBe('dark');
107
+ });
108
+
109
+ it('should handle complex real-world cookie string', () => {
110
+ const cookieFn = Endpoint.createCookies(
111
+ 'session=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9; user_id=12345; preferences=%7B%22theme%22%3A%22dark%22%7D; _ga=GA1.2.123456789.1234567890; authenticated=true',
112
+ );
113
+
114
+ expect(cookieFn('session')).toBe('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9');
115
+ expect(cookieFn('user_id')).toBe('12345');
116
+ expect(cookieFn('preferences')).toBe('{"theme":"dark"}');
117
+ expect(cookieFn('_ga')).toBe('GA1.2.123456789.1234567890');
118
+ expect(cookieFn('authenticated')).toBe('true');
119
+ });
120
+ });
@@ -468,6 +468,7 @@ describe('Endpoint', () => {
468
468
  services,
469
469
  logger: mockLogger,
470
470
  session: {},
471
+ cookie: vi.fn(),
471
472
  });
472
473
 
473
474
  expect(result).toBe(true);
@@ -497,6 +498,7 @@ describe('Endpoint', () => {
497
498
  services,
498
499
  logger: mockLogger,
499
500
  session: {},
501
+ cookie: vi.fn(),
500
502
  };
501
503
 
502
504
  const result = await endpoint.authorize(mockContext);
@@ -529,6 +531,7 @@ describe('Endpoint', () => {
529
531
  services,
530
532
  logger: mockLogger,
531
533
  session: {},
534
+ cookie: vi.fn(),
532
535
  };
533
536
 
534
537
  const result = endpoint.authorize(mockContext);
@@ -564,6 +567,7 @@ describe('Endpoint', () => {
564
567
  services,
565
568
  logger: mockLogger,
566
569
  session: {},
570
+ cookie: vi.fn(),
567
571
  });
568
572
 
569
573
  expect(result).toBe(true);
@@ -605,6 +609,7 @@ describe('Endpoint', () => {
605
609
  services: { TestService: TestService.register() },
606
610
  logger: mockLogger,
607
611
  session: {},
612
+ cookie: vi.fn(),
608
613
  });
609
614
 
610
615
  expect(result).toBe(true);
@@ -641,6 +646,7 @@ describe('Endpoint', () => {
641
646
  header: vi.fn(),
642
647
  services,
643
648
  logger: testLogger,
649
+ cookie: vi.fn(),
644
650
  session: {},
645
651
  });
646
652
 
@@ -675,6 +681,7 @@ describe('Endpoint', () => {
675
681
  services,
676
682
  logger: mockLogger,
677
683
  session: mockSession,
684
+ cookie: vi.fn(),
678
685
  });
679
686
 
680
687
  expect(result).toBe(true);
@@ -705,6 +712,7 @@ describe('Endpoint', () => {
705
712
  services,
706
713
  logger: mockLogger,
707
714
  session: {},
715
+ cookie: vi.fn(),
708
716
  }),
709
717
  ).rejects.toThrow('Authorization failed');
710
718
  });
@@ -735,6 +743,7 @@ describe('Endpoint', () => {
735
743
  services,
736
744
  logger: mockLogger,
737
745
  session: {},
746
+ cookie: vi.fn(),
738
747
  }),
739
748
  ).rejects.toThrow('Async authorization failed');
740
749
  });
@@ -771,6 +780,7 @@ describe('Endpoint', () => {
771
780
  header: vi.fn().mockReturnValue('Bearer admin-token'),
772
781
  services,
773
782
  logger: mockLogger,
783
+ cookie: vi.fn(),
774
784
  session: { userId: 'admin1', role: 'admin' },
775
785
  });
776
786
 
@@ -780,6 +790,7 @@ describe('Endpoint', () => {
780
790
  const userResult = await endpoint.authorize({
781
791
  header: vi.fn().mockReturnValue('Bearer user-token'),
782
792
  services,
793
+ cookie: vi.fn(),
783
794
  logger: mockLogger,
784
795
  session: { userId: 'user1', role: 'user' },
785
796
  });
@@ -792,6 +803,7 @@ describe('Endpoint', () => {
792
803
  services,
793
804
  logger: mockLogger,
794
805
  session: { userId: 'user1', role: 'admin' },
806
+ cookie: vi.fn(),
795
807
  });
796
808
 
797
809
  expect(noTokenResult).toBe(false);