1 | var chai = require('chai')
|
2 | var should = chai.should()
|
3 |
|
4 | chai.use(require('chai-http'))
|
5 |
|
6 | var request = chai.request(require("./server"))
|
7 |
|
8 | describe("HelperResp", () => {
|
9 | describe("#unauth", () => {
|
10 | it("should respond with 401 UNAUTHORIZED", (done) => {
|
11 | request.get("/unauth")
|
12 | .end((err, res) => {
|
13 | res.should.have.status(401)
|
14 | res.body.error.should.be.ok
|
15 | res.body.data.should.be.eql("UNAUTHORIZED ACCESS")
|
16 |
|
17 | done()
|
18 | })
|
19 | })
|
20 | it("should send the required response status message", (done) => {
|
21 | request.get("/unauth?comments=UNAUTHORIZED")
|
22 | .end((err, res) => {
|
23 | res.should.have.status(401)
|
24 | res.body.error.should.be.ok
|
25 | res.body.data.should.be.eql("UNAUTHORIZED")
|
26 |
|
27 | done()
|
28 | })
|
29 | })
|
30 | })
|
31 |
|
32 | describe("#serverError", () => {
|
33 | it("should responed with 500 INTERNAL SERVER ERROR", (done) => {
|
34 | request.get("/serverError")
|
35 | .end((err, res) => {
|
36 | res.should.have.status(500)
|
37 | res.body.error.should.be.ok
|
38 | res.body.data.should.be.eql("INTERNAL SERVER ERROR")
|
39 |
|
40 | done()
|
41 | })
|
42 | })
|
43 | it("should send the required response status message", (done) => {
|
44 | request.get("/serverError?comments=Server-Error")
|
45 | .end((err, res) => {
|
46 | res.should.have.status(500)
|
47 | res.body.error.should.be.ok
|
48 | res.body.data.should.be.eql("Server-Error")
|
49 |
|
50 | done()
|
51 | })
|
52 | })
|
53 | })
|
54 |
|
55 | describe("#handleResult", () => {
|
56 | it("should respond with 200 [] when there is no content", (done) => {
|
57 | request.get("/handleResult")
|
58 | .end((err, res) => {
|
59 | res.should.have.status(200)
|
60 | res.body.error.should.not.be.ok
|
61 | res.body.data.should.be.an('array')
|
62 | res.body.data.length.should.be.eql(0)
|
63 |
|
64 | done()
|
65 | })
|
66 | })
|
67 | it("should respond with 200 {} If there is content", (done) => {
|
68 | request.get("/handleResult?name=test&age=21")
|
69 | .end((err, res) => {
|
70 | res.should.have.status(200)
|
71 | res.body.error.should.not.be.ok
|
72 | res.body.data.should.be.an('object')
|
73 | should.exist(res.body.data.name)
|
74 | res.body.data.name.should.be.eql("test")
|
75 |
|
76 | done()
|
77 | })
|
78 | })
|
79 | it("should respond with 200 with data in response as array", (done) => {
|
80 | request.get("/handleResult/array")
|
81 | .end((err, res) => {
|
82 | res.should.have.status(200)
|
83 | res.body.error.should.not.be.ok
|
84 | res.body.data.should.be.an('array')
|
85 | res.body.data.length.should.be.eql(0)
|
86 |
|
87 | done()
|
88 | })
|
89 | })
|
90 | it("should respond with 200 with data in response as object", (done) => {
|
91 | request.get("/handleResult/object")
|
92 | .end((err, res) => {
|
93 | res.should.have.status(200)
|
94 | res.body.error.should.not.be.ok
|
95 | res.body.data.should.be.an('object')
|
96 | Object.keys(res.body.data).length.should.be.eql(0)
|
97 |
|
98 | done()
|
99 | })
|
100 | })
|
101 | it("should respond with 500 Error if there was some error", (done) => {
|
102 | request.get("/handleResult/error").end((err, res) => {
|
103 | should.exist(err)
|
104 | err.should.be.an.instanceOf(Error);
|
105 | res.should.have.status(500);
|
106 | res.body.error.should.be.ok;
|
107 | res.body.data.should.be.an("array");
|
108 | res.body.data.length.should.be.eql(0);
|
109 |
|
110 | done();
|
111 | })
|
112 | })
|
113 | })
|
114 |
|
115 | describe("#success", function() {
|
116 | it("should respond with http success", (done) => {
|
117 | request.get("/success")
|
118 | .end((err, res) => {
|
119 | res.should.have.status(200)
|
120 | res.body.error.should.not.be.ok;
|
121 | res.body.data.should.be.an("object")
|
122 | res.body.data.name.should.be.eql("test")
|
123 |
|
124 | done();
|
125 | })
|
126 | })
|
127 | })
|
128 |
|
129 | describe("#failed", function() {
|
130 | it("should respond with http failure", (done) => {
|
131 | request.get("/failed")
|
132 | .end((err, res) => {
|
133 | res.should.have.status(400)
|
134 | res.body.error.should.be.ok;
|
135 | res.body.data.should.be.a("string")
|
136 | res.body.data.should.be.eql("Invalid Data")
|
137 |
|
138 | done();
|
139 | })
|
140 | })
|
141 | })
|
142 |
|
143 | describe("#post", () => {
|
144 | it("should respond with HTTP created", (done) => {
|
145 | request.post("/post")
|
146 | .end((err, res) => {
|
147 | res.should.have.status(201)
|
148 | res.body.error.should.not.be.ok;
|
149 | res.body.data.should.be.an("object")
|
150 | res.body.data.created.should.be.ok;
|
151 |
|
152 | done()
|
153 | })
|
154 | })
|
155 | })
|
156 |
|
157 |
|
158 | describe("#put", () => {
|
159 | it("should respond with HTTP accepted", (done) => {
|
160 | request.put("/put")
|
161 | .end((err, res) => {
|
162 | res.should.have.status(202)
|
163 | res.body.error.should.not.be.ok;
|
164 | res.body.data.should.be.an("object")
|
165 | res.body.data.accepted.should.be.ok;
|
166 |
|
167 | done()
|
168 | })
|
169 | })
|
170 | })
|
171 |
|
172 | describe("#delete", () => {
|
173 | it("should respond with HTTP Delete", (done) => {
|
174 | request.delete("/remove")
|
175 | .end((err, res) => {
|
176 | res.should.have.status(202)
|
177 | res.body.error.should.not.be.ok;
|
178 | res.body.data.should.be.an("object")
|
179 | res.body.data.remove.should.be.ok;
|
180 |
|
181 | done()
|
182 | })
|
183 | })
|
184 | })
|
185 |
|
186 | describe("#get", () => {
|
187 | it("should respond with HTTP List []", (done) => {
|
188 | request.get("/list")
|
189 | .end((err, res) => {
|
190 | res.should.have.status(200)
|
191 | res.body.error.should.not.be.ok;
|
192 | res.body.data.should.be.an('object')
|
193 | res.body.data.count.should.be.eql(0)
|
194 | res.body.data.list.length.should.be.eql(0);
|
195 |
|
196 | done()
|
197 | })
|
198 | })
|
199 | it("should respond with HTTP get /:id", (done) => {
|
200 | request.get("/get/testname")
|
201 | .end((err, res) => {
|
202 | res.should.have.status(200)
|
203 | res.body.error.should.not.be.ok;
|
204 | res.body.data.should.be.an("object")
|
205 | res.body.data.name.should.be.eql("testname")
|
206 |
|
207 | done()
|
208 | })
|
209 | })
|
210 | })
|
211 | }) |
\ | No newline at end of file |