deno.land / x / opine@2.3.4 / examples / mvc / index.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { superdeno } from "../../test/deps.ts";import { describe, it } from "../../test/utils.ts";import { app } from "./index.ts";
describe("mvc", () => { describe("GET /", function () { it("should redirect to /users", function (done) { superdeno(app) .get("/") .expect("Location", "/users") .expect(302, done); }); });
describe("GET /pet/0", function () { it("should get pet", function (done) { superdeno(app) .get("/pet/0") .expect(200, /Smudge/, done); }); });
describe("GET /pet/0/edit", function () { it("should get pet edit page", function (done) { superdeno(app) .get("/pet/0/edit") .expect(/<form/) .expect(200, /Smudge/, done); }); });
describe("POST /pet/2", function () { it("should update the pet", function (done) { superdeno(app) .post("/pet/2") .set("Content-Type", "application/x-www-form-urlencoded") .send({ pet: { name: "Georgie Porgie" } }) .expect(302, function (err) { if (err) { return done(err); }
superdeno(app) .get("/pet/2/edit") .expect(200, /Georgie Porgie/, done); }); }); });
describe("GET /users", function () { it("should display a list of users", function (done) { superdeno(app) .get("/users") .expect(/<h1>Users<\/h1>/) .expect(/>C</) .expect(/>H</) .expect(/>S</) .expect(200, done); }); });
describe("GET /user/:id", function () { describe("when present", function () { it("should display the user", function (done) { superdeno(app) .get("/user/0") .expect(200, /<h1>C <a href="\/user\/0\/edit">edit/, done); });
it("should display the user's pets", function (done) { superdeno(app) .get("/user/2") .expect(/\/pet\/1">Tilly/) .expect(/\/pet\/2">Georgie/) .expect(200, done); }); });
describe("when not present", function () { it("should 404", function (done) { superdeno(app) .get("/user/123") .expect(404, done); }); }); });
describe("GET /user/:id/edit", function () { it("should display the edit form", function (done) { superdeno(app) .get("/user/1/edit") .expect(/H/) .expect(200, /<form/, done); }); });
describe("PUT /user/:id", function () { it("should 500 on error", function (done) { superdeno(app) .post("/user/1") .send({}) .expect(500, done); });
it("should update the user", function (done) { superdeno(app) .post("/user/1") .set("Content-Type", "application/x-www-form-urlencoded") .send({ user: { name: "Elephant Seal" } }) .expect(302, function (err) { if (err) { return done(err); }
superdeno(app) .get("/user/1/edit") .expect(200, /Elephant Seal/, done); }); }); });
describe("POST /user/:id/pet", function () { it("should create a pet for user", function (done) { superdeno(app) .post("/user/0/pet") .set("Content-Type", "application/x-www-form-urlencoded") .send({ pet: { name: "Bramble" } }) .expect("Location", "/user/0") .expect(302, function (err) { if (err) { return done(err); }
superdeno(app) .get("/user/0") .expect(200, /Bramble/, done); }); }); });});
opine

Version Info

Tagged at
2 years ago