From 4af3100b6d89e637bac56ee9bb1ac4c66087021a Mon Sep 17 00:00:00 2001 From: Jacob Hampton Date: Sat, 13 Jan 2024 22:36:12 +0000 Subject: [PATCH] build cookie function test --- __tests__/util/http.test.ts | 22 ++++++++++++++++++++++ lib/server.ts | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 __tests__/util/http.test.ts diff --git a/__tests__/util/http.test.ts b/__tests__/util/http.test.ts new file mode 100644 index 0000000..11d057a --- /dev/null +++ b/__tests__/util/http.test.ts @@ -0,0 +1,22 @@ +import { CookieOptions } from '../../lib'; +import { buildCookie } from '../../lib/util/http'; + +describe('buildCookie', () => { + it('should build a cookie string with the provided options', () => { + const cookie = 'myCookie'; + const options: CookieOptions = { + expires: new Date('2022-12-31'), + httpOnly: true, + secure: true, + path: '/my-path', + domain: 'example.com', + sameSite: 'Strict' + }; + + const expectedCookieString = + 'myCookie; Expires=Sat, 31 Dec 2022 00:00:00 GMT; HttpOnly; Secure; Path=/my-path; Domain=example.com; SameSite=Strict'; + const result = buildCookie(cookie, options); + + expect(result).toEqual(expectedCookieString); + }); +}); diff --git a/lib/server.ts b/lib/server.ts index 96a10c5..e891c8f 100644 --- a/lib/server.ts +++ b/lib/server.ts @@ -10,7 +10,7 @@ import { Request, StatusCodes, ConsumeRoute -} from './@types/index'; +} from './@types'; import ConsumeRequest from './wrapper/request'; import security from './security/securityMiddleware'; import { isMiddleware } from './util/function';