diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-09-04 21:21:47 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-09-04 21:30:18 +0200 |
commit | 0e1dc3e7c69995c691e1dd82e3c2bc68748661ca (patch) | |
tree | f2a4b5cffc72e33c902b67083bbaa35b6f22f0ca /server/tests/api/check-params/pods.js | |
parent | b0f9f39ed70299a208d1b388c72de8b7f3510cb7 (diff) | |
download | PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.gz PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.zst PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.zip |
Convert tests to typescript
Diffstat (limited to 'server/tests/api/check-params/pods.js')
-rw-r--r-- | server/tests/api/check-params/pods.js | 280 |
1 files changed, 0 insertions, 280 deletions
diff --git a/server/tests/api/check-params/pods.js b/server/tests/api/check-params/pods.js deleted file mode 100644 index 35ea59093..000000000 --- a/server/tests/api/check-params/pods.js +++ /dev/null | |||
@@ -1,280 +0,0 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const request = require('supertest') | ||
6 | const series = require('async/series') | ||
7 | |||
8 | const loginUtils = require('../../utils/login') | ||
9 | const requestsUtils = require('../../utils/requests') | ||
10 | const serversUtils = require('../../utils/servers') | ||
11 | const usersUtils = require('../../utils/users') | ||
12 | |||
13 | describe('Test pods API validators', function () { | ||
14 | const path = '/api/v1/pods/' | ||
15 | let server = null | ||
16 | |||
17 | // --------------------------------------------------------------- | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(45000) | ||
21 | |||
22 | series([ | ||
23 | function (next) { | ||
24 | serversUtils.flushTests(next) | ||
25 | }, | ||
26 | function (next) { | ||
27 | serversUtils.runServer(1, function (server1) { | ||
28 | server = server1 | ||
29 | |||
30 | next() | ||
31 | }) | ||
32 | }, | ||
33 | function (next) { | ||
34 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
35 | if (err) throw err | ||
36 | server.accessToken = token | ||
37 | |||
38 | next() | ||
39 | }) | ||
40 | } | ||
41 | ], done) | ||
42 | }) | ||
43 | |||
44 | describe('When managing friends', function () { | ||
45 | let userAccessToken = null | ||
46 | |||
47 | before(function (done) { | ||
48 | usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { | ||
49 | server.user = { | ||
50 | username: 'user1', | ||
51 | password: 'password' | ||
52 | } | ||
53 | |||
54 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
55 | if (err) throw err | ||
56 | |||
57 | userAccessToken = accessToken | ||
58 | |||
59 | done() | ||
60 | }) | ||
61 | }) | ||
62 | }) | ||
63 | |||
64 | describe('When making friends', function () { | ||
65 | const body = { | ||
66 | hosts: [ 'localhost:9002' ] | ||
67 | } | ||
68 | |||
69 | it('Should fail without hosts', function (done) { | ||
70 | request(server.url) | ||
71 | .post(path + '/makefriends') | ||
72 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
73 | .set('Accept', 'application/json') | ||
74 | .expect(400, done) | ||
75 | }) | ||
76 | |||
77 | it('Should fail if hosts is not an array', function (done) { | ||
78 | request(server.url) | ||
79 | .post(path + '/makefriends') | ||
80 | .send({ hosts: 'localhost:9002' }) | ||
81 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
82 | .set('Accept', 'application/json') | ||
83 | .expect(400, done) | ||
84 | }) | ||
85 | |||
86 | it('Should fail if the array is not composed by hosts', function (done) { | ||
87 | request(server.url) | ||
88 | .post(path + '/makefriends') | ||
89 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) | ||
90 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
91 | .set('Accept', 'application/json') | ||
92 | .expect(400, done) | ||
93 | }) | ||
94 | |||
95 | it('Should fail if the array is composed with http schemes', function (done) { | ||
96 | request(server.url) | ||
97 | .post(path + '/makefriends') | ||
98 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) | ||
99 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
100 | .set('Accept', 'application/json') | ||
101 | .expect(400, done) | ||
102 | }) | ||
103 | |||
104 | it('Should fail if hosts are not unique', function (done) { | ||
105 | request(server.url) | ||
106 | .post(path + '/makefriends') | ||
107 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | ||
108 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
109 | .set('Accept', 'application/json') | ||
110 | .expect(400, done) | ||
111 | }) | ||
112 | |||
113 | it('Should fail with an invalid token', function (done) { | ||
114 | request(server.url) | ||
115 | .post(path + '/makefriends') | ||
116 | .send(body) | ||
117 | .set('Authorization', 'Bearer faketoken') | ||
118 | .set('Accept', 'application/json') | ||
119 | .expect(401, done) | ||
120 | }) | ||
121 | |||
122 | it('Should fail if the user is not an administrator', function (done) { | ||
123 | request(server.url) | ||
124 | .post(path + '/makefriends') | ||
125 | .send(body) | ||
126 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
127 | .set('Accept', 'application/json') | ||
128 | .expect(403, done) | ||
129 | }) | ||
130 | }) | ||
131 | |||
132 | describe('When quitting friends', function () { | ||
133 | it('Should fail with an invalid token', function (done) { | ||
134 | request(server.url) | ||
135 | .get(path + '/quitfriends') | ||
136 | .query({ start: 'hello' }) | ||
137 | .set('Authorization', 'Bearer faketoken') | ||
138 | .set('Accept', 'application/json') | ||
139 | .expect(401, done) | ||
140 | }) | ||
141 | |||
142 | it('Should fail if the user is not an administrator', function (done) { | ||
143 | request(server.url) | ||
144 | .get(path + '/quitfriends') | ||
145 | .query({ start: 'hello' }) | ||
146 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
147 | .set('Accept', 'application/json') | ||
148 | .expect(403, done) | ||
149 | }) | ||
150 | }) | ||
151 | |||
152 | describe('When removing one friend', function () { | ||
153 | it('Should fail with an invalid token', function (done) { | ||
154 | request(server.url) | ||
155 | .delete(path + '/1') | ||
156 | .set('Authorization', 'Bearer faketoken') | ||
157 | .set('Accept', 'application/json') | ||
158 | .expect(401, done) | ||
159 | }) | ||
160 | |||
161 | it('Should fail if the user is not an administrator', function (done) { | ||
162 | request(server.url) | ||
163 | .delete(path + '/1') | ||
164 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
165 | .set('Accept', 'application/json') | ||
166 | .expect(403, done) | ||
167 | }) | ||
168 | |||
169 | it('Should fail with an undefined id', function (done) { | ||
170 | request(server.url) | ||
171 | .delete(path + '/' + undefined) | ||
172 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
173 | .set('Accept', 'application/json') | ||
174 | .expect(400, done) | ||
175 | }) | ||
176 | |||
177 | it('Should fail with an invalid id', function (done) { | ||
178 | request(server.url) | ||
179 | .delete(path + '/foobar') | ||
180 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
181 | .set('Accept', 'application/json') | ||
182 | .expect(400, done) | ||
183 | }) | ||
184 | |||
185 | it('Should fail if the pod is not a friend', function (done) { | ||
186 | request(server.url) | ||
187 | .delete(path + '/-1') | ||
188 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
189 | .set('Accept', 'application/json') | ||
190 | .expect(404, done) | ||
191 | }) | ||
192 | |||
193 | it('Should succeed with the correct parameters') | ||
194 | }) | ||
195 | }) | ||
196 | |||
197 | describe('When adding a pod', function () { | ||
198 | it('Should fail with nothing', function (done) { | ||
199 | const data = {} | ||
200 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
201 | }) | ||
202 | |||
203 | it('Should fail without public key', function (done) { | ||
204 | const data = { | ||
205 | email: 'testexample.com', | ||
206 | host: 'coucou.com' | ||
207 | } | ||
208 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
209 | }) | ||
210 | |||
211 | it('Should fail without an email', function (done) { | ||
212 | const data = { | ||
213 | host: 'coucou.com', | ||
214 | publicKey: 'mysuperpublickey' | ||
215 | } | ||
216 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
217 | }) | ||
218 | |||
219 | it('Should fail without an invalid email', function (done) { | ||
220 | const data = { | ||
221 | host: 'coucou.com', | ||
222 | email: 'testexample.com', | ||
223 | publicKey: 'mysuperpublickey' | ||
224 | } | ||
225 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
226 | }) | ||
227 | |||
228 | it('Should fail without a host', function (done) { | ||
229 | const data = { | ||
230 | email: 'testexample.com', | ||
231 | publicKey: 'mysuperpublickey' | ||
232 | } | ||
233 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
234 | }) | ||
235 | |||
236 | it('Should fail with an incorrect host', function (done) { | ||
237 | const data = { | ||
238 | host: 'http://coucou.com', | ||
239 | email: 'testexample.com', | ||
240 | publicKey: 'mysuperpublickey' | ||
241 | } | ||
242 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
243 | data.host = 'http://coucou' | ||
244 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
245 | data.host = 'coucou' | ||
246 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
247 | }) | ||
248 | }) | ||
249 | }) | ||
250 | |||
251 | it('Should succeed with the correct parameters', function (done) { | ||
252 | const data = { | ||
253 | host: 'coucou.com', | ||
254 | email: 'test@example.com', | ||
255 | publicKey: 'mysuperpublickey' | ||
256 | } | ||
257 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) | ||
258 | }) | ||
259 | |||
260 | it('Should fail with a host that already exists', function (done) { | ||
261 | const data = { | ||
262 | host: 'coucou.com', | ||
263 | email: 'test@example.com', | ||
264 | publicKey: 'mysuperpublickey' | ||
265 | } | ||
266 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 409) | ||
267 | }) | ||
268 | }) | ||
269 | |||
270 | after(function (done) { | ||
271 | process.kill(-server.app.pid) | ||
272 | |||
273 | // Keep the logs if the test failed | ||
274 | if (this.ok) { | ||
275 | serversUtils.flushTests(done) | ||
276 | } else { | ||
277 | done() | ||
278 | } | ||
279 | }) | ||
280 | }) | ||