-
Notifications
You must be signed in to change notification settings - Fork 78
/
index_test.ts
96 lines (88 loc) · 2.09 KB
/
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
import test from "blue-tape"
import request from "supertest"
import Ogre, {OgreOpts} from "./"
test(async (t) => {
let table: {
opts?: OgreOpts
method?: string
url: string
status: number
body?: string
upload?: string
contents?: RegExp
}[] = [
{method: "OPTIONS", url: "/", status: 200},
{url: "/not-found", status: 404},
{url: "/", status: 200},
{method: "POST", url: "/convert", status: 400, contents: /no file/i},
{
method: "POST",
url: "/convert",
status: 200,
upload: "./testdata/sample.shp.zip",
},
{
opts: {limit: 5},
method: "POST",
url: "/convert",
status: 500,
upload: "./testdata/sample.shp.zip",
},
{method: "POST", url: "/convertJson", status: 400, contents: /no json/i},
{
method: "POST",
url: "/convertJson",
status: 200,
body: `json=${JSON.stringify({
type: "FeatureCollection",
features: [
{
type: "Feature",
geometry: {type: "Point", coordinates: [102.0, 0.5]},
properties: {prop0: "value0"},
},
],
})}`,
},
{
opts: {limit: 5},
method: "POST",
url: "/convertJson",
status: 500,
body: `json=${JSON.stringify({
type: "FeatureCollection",
features: [
{
type: "Feature",
geometry: {type: "Point", coordinates: [102.0, 0.5]},
properties: {prop0: "value0"},
},
],
})}`,
},
]
for (let tt of table) {
let ogre = new Ogre(tt.opts)
let req
switch (tt.method) {
case "OPTIONS":
req = request(ogre.app).options(tt.url)
break
case "POST":
req = request(ogre.app).post(tt.url).send(tt.body)
break
default:
// 'GET'
req = request(ogre.app).get(tt.url)
break
}
if (tt.upload) {
req = req.attach("upload", tt.upload)
}
let res = await req
t.equal(res.status, tt.status, tt.url)
if (tt.contents) {
t.match(res.text, tt.contents)
}
}
})