deno.land / x / opine@2.3.4 / test / units / res.cookie.test.ts

res.cookie.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { opine } from "../../mod.ts";import { expect, superdeno } from "../deps.ts";import { describe, it } from "../utils.ts";
describe("res", function () { describe(".cookie(cookie)", function () { it("should set a cookie", function (done) { const app = opine();
app.use(function (req, res) { res.cookie({ name: "name", value: "deno" }).end(); });
superdeno(app) .get("/") .expect("Set-Cookie", "name=deno; Path=/") .expect(200, done); });
it("should raise an exception if no arg is provided", function (done) { const app = opine();
app.use(function (req, res) { (res as any).cookie().end(); });
superdeno(app) .get("/") .expect(500, done); });
it("should raise an expection if args provided are not valid", function ( done, ) { const app = opine();
app.use(function (req, res) { (res as any).cookie({}).end(); });
superdeno(app) .get("/") .expect(500, done); });
it("should allow multiple calls", function (done) { const app = opine();
app.use(function (req, res) { res.cookie({ name: "name", value: "deno" }); res.cookie({ name: "age", value: "1" }); res.cookie({ name: "gender", value: "?" }); res.end(); });
superdeno(app) .get("/") .end(function (err, res) { expect(res.header["set-cookie"]).toEqual( "name=deno; Path=/, age=1; Path=/, gender=?; Path=/", ); done(); }); }); });
describe(".cookie(name, string, options)", function () { it("should set params", function (done) { const app = opine();
app.use(function (req, res) { res.cookie("name", "deno", { httpOnly: true, secure: true }); res.end(); });
superdeno(app) .get("/") .expect("Set-Cookie", "name=deno; Secure; HttpOnly; Path=/") .expect(200, done); });
describe("maxAge", function () { it("should set max-age", function (done) { const app = opine();
app.use(function (req, res) { res.cookie("name", "deno", { maxAge: 1000 }); res.end(); });
superdeno(app) .get("/") .expect("Set-Cookie", /Max-Age=1/, done); }); }); });});
opine

Version Info

Tagged at
2 years ago