|
| 1 | +import { parseCookies } from "../../open-next/src/adapters/util"; |
| 2 | + |
| 3 | +describe("adapter utils", () => { |
| 4 | + describe("parseCookies", () => { |
| 5 | + it("returns undefined if cookies is empty", () => { |
| 6 | + const cookies = parseCookies(""); |
| 7 | + expect(cookies).toBeUndefined(); |
| 8 | + }); |
| 9 | + it("returns undefined if no cookies", () => { |
| 10 | + const cookies = parseCookies(); |
| 11 | + expect(cookies).toBeUndefined(); |
| 12 | + }); |
| 13 | + it("parse single cookie", () => { |
| 14 | + const cookies = parseCookies( |
| 15 | + "cookie1=value1; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure; Path=/", |
| 16 | + ); |
| 17 | + expect(cookies).toEqual([ |
| 18 | + "cookie1=value1; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure; Path=/", |
| 19 | + ]); |
| 20 | + }); |
| 21 | + it("parse multiple cookies", () => { |
| 22 | + // NOTE: expires is lower case but still works |
| 23 | + const cookies = parseCookies( |
| 24 | + "cookie1=value1; expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure; Path=/, cookie2=value2; HttpOnly; Secure", |
| 25 | + ); |
| 26 | + expect(cookies).toEqual([ |
| 27 | + "cookie1=value1; expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure; Path=/", |
| 28 | + "cookie2=value2; HttpOnly; Secure", |
| 29 | + ]); |
| 30 | + }); |
| 31 | + it("return if cookies is already an array", () => { |
| 32 | + const cookies = parseCookies([ |
| 33 | + "cookie1=value1; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure; Path=/", |
| 34 | + ]); |
| 35 | + expect(cookies).toEqual([ |
| 36 | + "cookie1=value1; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure; Path=/", |
| 37 | + ]); |
| 38 | + }); |
| 39 | + it("parses w/o Expire", () => { |
| 40 | + const cookies = parseCookies( |
| 41 | + "cookie1=value1; HttpOnly; Secure; Path=/, cookie2=value2; HttpOnly=false; Secure=True; Domain=example.com; Path=/api", |
| 42 | + ); |
| 43 | + expect(cookies).toEqual([ |
| 44 | + "cookie1=value1; HttpOnly; Secure; Path=/", |
| 45 | + "cookie2=value2; HttpOnly=false; Secure=True; Domain=example.com; Path=/api", |
| 46 | + ]); |
| 47 | + }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments