-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest.js
175 lines (134 loc) · 4.48 KB
/
test.js
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
process.env.NODE_ENV = "test";
const request = require("supertest");
const server = require("./server");
describe("FlexSearch Server (RESTful)", function(){
it("responds to /", async function(){
await request("http://localhost:6780")
.get("/")
.expect(200);
});
it("not responds to /notfound", async function(){
await request("http://localhost:6780")
.get("/notfound")
.expect(404);
});
it("index content", async function(){
await request("http://localhost:6780")
.post("/add/0/foo")
.send()
.expect(200);
await request("http://localhost:6780")
.post("/add/1/bar")
.send()
.expect(200);
await request("http://localhost:6780")
.post("/add/2/foobar")
.send()
.expect(200);
});
it("update content", async function(){
await request("http://localhost:6780")
.post("/update/0/foobar")
.send()
.expect(200);
await request("http://localhost:6780")
.post("/update/1/foo")
.send()
.expect(200);
await request("http://localhost:6780")
.post("/update/2/bar")
.send()
.expect(200);
});
it("search content", async function(){
await request("http://localhost:6780")
.get("/search/foo")
.set('Accept', 'application/json')
.expect(["0","1"]);
await request("http://localhost:6780")
.get("/search/bar")
.set('Accept', 'application/json')
.expect(["2"]);
await request("http://localhost:6780")
.get("/search/foobar")
.set('Accept', 'application/json')
.expect(["0"])
});
it("remove content", async function(){
await request("http://localhost:6780")
.post("/remove/0")
.send()
.expect(200);
await request("http://localhost:6780")
.post("/remove/1")
.send()
.expect(200);
await request("http://localhost:6780")
.post("/remove/2")
.send()
.expect(200);
// check:
await request("http://localhost:6780")
.get("/search/foo")
.set('Accept', 'application/json')
.expect([]);
await request("http://localhost:6780")
.get("/search/bar")
.set('Accept', 'application/json')
.expect([]);
await request("http://localhost:6780")
.get("/search/foobar")
.set('Accept', 'application/json')
.expect([])
});
});
describe("FlexSearch Server (JSON)", function(){
it("index content", async function(){
await request("http://localhost:6780")
.post("/add")
.send([{id: 0, content: "foo"}, {id: 1, content: "bar"}, {id: 2, content: "foobar"}])
.expect(200);
});
it("update content", async function(){
await request("http://localhost:6780")
.post("/update")
.send([{id: 0, content: "foobar"}, {id: 1, content: "foo"}, {id: 2, content: "bar"}])
.expect(200);
});
it("search content", async function(){
await request("http://localhost:6780")
.get("/search/foo")
.set('Accept', 'application/json')
.expect([0,1]);
await request("http://localhost:6780")
.get("/search/bar")
.set('Accept', 'application/json')
.expect([2]);
await request("http://localhost:6780")
.get("/search/foobar")
.set('Accept', 'application/json')
.expect([0])
});
it("remove content", async function(){
await request("http://localhost:6780")
.post("/remove")
.send([0, 1, 2])
.expect(200);
// check:
await request("http://localhost:6780")
.get("/search/foo")
.set('Accept', 'application/json')
.expect([]);
await request("http://localhost:6780")
.get("/search/bar")
.set('Accept', 'application/json')
.expect([]);
await request("http://localhost:6780")
.get("/search/foobar")
.set('Accept', 'application/json')
.expect([])
.then(function(){
server.close();
})
});
});