-
Notifications
You must be signed in to change notification settings - Fork 0
/
assertResponse.test.ts
118 lines (111 loc) · 3.44 KB
/
assertResponse.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
import { assertRejects } from "https://deno.land/std@0.160.0/testing/asserts.ts";
import { assertResponse } from "../src/assertResponse.ts";
import { Block, _Response } from "../src/types.ts";
Deno.test("[assertResponse] with expectedResponse throws error checking status", async () => {
const expectedResponse = new _Response(null, { status: 400 });
const actualResponse = new _Response(null, { status: 403 });
await assertRejects(async () => {
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
});
});
Deno.test("[assertResponse] with expectedResponse throws error checking statusText", async () => {
const expectedResponse = new _Response(null, {
status: 400,
statusText: "Bad Request",
});
const actualResponse = new _Response(null, {
status: 400,
statusText: "Forbidden",
});
await assertRejects(async () => {
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
});
});
Deno.test("[assertResponse] with no expectedResponse not throws", async () => {
const expectedResponse = new _Response(null, {
status: 400,
statusText: "Bad Request",
});
const actualResponse = new _Response(null, {
status: 400,
statusText: "Bad Request",
});
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
});
Deno.test("[assertResponse] with expectedResponse plain test body", async () => {
const expectedResponse = new _Response("foo", { status: 200 });
const actualResponse = new _Response("foo", { status: 200 });
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
});
Deno.test("[assertResponse] with expectedResponse json body", async () => {
const expectedResponse = new _Response('{"foo": "bar"}', {
status: 200,
headers: { "content-type": "application/json" },
});
const actualResponse = new _Response('{ "foo" : "bar" }', {
status: 200,
headers: { "content-type": "application/json" },
});
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
});
Deno.test("[assertResponse] with expectedResponse json test body with regexp", async () => {
const expectedResponse = new _Response('{"foo": "bar"}', {
status: 200,
headers: { "content-type": "application/json" },
});
const actualResponse = new _Response('{"foo": "bar"}', {
status: 200,
headers: { "content-type": "application/json" },
});
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
});
Deno.test(
"[assertResponse] must throw with different bodies", // { only: true },
async () => {
const expectedResponse = new _Response('{"foo": "bar"}', {
headers: { "content-type": "application/json" },
});
const actualResponse = new _Response('{"foo": "baz"}', {
headers: { "content-type": "application/json" },
});
await assertRejects(async () => {
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
});
},
);
Deno.test(
"[assertResponse] must not throw with same body", // { only: true },
async () => {
const expectedResponse = new _Response('{"foo": "bar"}', {
headers: { "content-type": "application/json" },
});
const actualResponse = new _Response('{ "foo" : "bar" } ', {
headers: { "content-type": "application/json" },
});
await assertResponse(new Block({
expectedResponse,
actualResponse,
}));
},
);