aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-02 07:44:57 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-02 07:44:57 -0800
commitbeaf91590acd319e4ac15c14c64c59f45b6a794b (patch)
tree0f9005438753dccf4065f4c85b33ec4968deedea /test/bun.js
parentd84f79bcc16d4e748c8a9400ea1cdb03d7f963fb (diff)
downloadbun-beaf91590acd319e4ac15c14c64c59f45b6a794b.tar.gz
bun-beaf91590acd319e4ac15c14c64c59f45b6a794b.tar.zst
bun-beaf91590acd319e4ac15c14c64c59f45b6a794b.zip
Tests for set-Cookie
Diffstat (limited to 'test/bun.js')
-rw-r--r--test/bun.js/fetch.test.js78
1 files changed, 76 insertions, 2 deletions
diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js
index b25f81409..e62022363 100644
--- a/test/bun.js/fetch.test.js
+++ b/test/bun.js/fetch.test.js
@@ -22,14 +22,88 @@ describe("Headers", () => {
);
});
- it(".count", () => {
+ it(".getSetCookie() with object", () => {
var headers = new Headers({
"content-length": "123",
"content-type": "text/plain",
"x-another-custom-header": "Hello World",
"x-custom-header": "Hello World",
+ "Set-Cookie": "foo=bar; Path=/; HttpOnly",
});
- expect(headers.count).toBe(4);
+ expect(headers.count).toBe(5);
+ expect(headers.getSetCookie()).toEqual(["foo=bar; Path=/; HttpOnly"]);
+ });
+
+ it(".getSetCookie() with array", () => {
+ var headers = new Headers([
+ ["content-length", "123"],
+ ["content-type", "text/plain"],
+ ["x-another-custom-header", "Hello World"],
+ ["x-custom-header", "Hello World"],
+ ["Set-Cookie", "foo=bar; Path=/; HttpOnly"],
+ ["Set-Cookie", "foo2=bar2; Path=/; HttpOnly"],
+ ]);
+ expect(headers.count).toBe(6);
+ expect(headers.getSetCookie()).toEqual([
+ "foo=bar; Path=/; HttpOnly",
+ "foo2=bar2; Path=/; HttpOnly",
+ ]);
+ });
+
+ it("Set-Cookies init", () => {
+ const headers = new Headers([
+ ["Set-Cookie", "foo=bar"],
+ ["Set-Cookie", "bar=baz"],
+ ["X-bun", "abc"],
+ ["X-bun", "def"],
+ ]);
+ const actual = [...headers];
+ expect(actual).toEqual([
+ ["set-cookie", "foo=bar"],
+ ["set-cookie", "bar=baz"],
+ ["x-bun", "abc, def"],
+ ]);
+ expect([...headers.values()]).toEqual(["foo=bar", "bar=baz", "abc, def"]);
+ });
+
+ it("Headers append multiple", () => {
+ const headers = new Headers([
+ ["Set-Cookie", "foo=bar"],
+ ["X-bun", "foo"],
+ ]);
+ headers.append("Set-Cookie", "bar=baz");
+ headers.append("x-bun", "bar");
+ const actual = [...headers];
+
+ // we do not preserve the order
+ // which is kind of bad
+ expect(actual).toEqual([
+ ["set-cookie", "foo=bar"],
+ ["set-cookie", "bar=baz"],
+ ["x-bun", "foo, bar"],
+ ]);
+ });
+
+ it("append duplicate set cookie key", () => {
+ const headers = new Headers([["Set-Cookie", "foo=bar"]]);
+ headers.append("set-Cookie", "foo=baz");
+ headers.append("Set-cookie", "baz=bar");
+ const actual = [...headers];
+ expect(actual).toEqual([
+ ["set-cookie", "foo=baz"],
+ ["set-cookie", "baz=bar"],
+ ]);
+ });
+
+ it("set duplicate cookie key", () => {
+ const headers = new Headers([["Set-Cookie", "foo=bar"]]);
+ headers.set("set-Cookie", "foo=baz");
+ headers.set("set-cookie", "bar=qat");
+ const actual = [...headers];
+ expect(actual).toEqual([
+ ["set-cookie", "foo=baz"],
+ ["set-cookie", "bar=qat"],
+ ]);
});
});