]>
Commit | Line | Data |
---|---|---|
0c1cbbfe C |
1 | 'use strict' |
2 | ||
0c1cbbfe C |
3 | const chai = require('chai') |
4 | const expect = chai.expect | |
1a42c9e2 | 5 | const series = require('async/series') |
0c1cbbfe | 6 | |
8d309058 C |
7 | const loginUtils = require('../utils/login') |
8 | const podsUtils = require('../utils/pods') | |
9 | const serversUtils = require('../utils/servers') | |
10 | const usersUtils = require('../utils/users') | |
11 | const videosUtils = require('../utils/videos') | |
0c1cbbfe | 12 | |
0c1cbbfe C |
13 | describe('Test users', function () { |
14 | let server = null | |
bc503c2a | 15 | let accessToken = null |
9bd26629 C |
16 | let accessTokenUser = null |
17 | let videoId = null | |
18 | let userId = null | |
0c1cbbfe C |
19 | |
20 | before(function (done) { | |
21 | this.timeout(20000) | |
22 | ||
1a42c9e2 | 23 | series([ |
0c1cbbfe | 24 | function (next) { |
8d309058 | 25 | serversUtils.flushTests(next) |
0c1cbbfe C |
26 | }, |
27 | function (next) { | |
8d309058 | 28 | serversUtils.runServer(1, function (server1) { |
0c1cbbfe C |
29 | server = server1 |
30 | next() | |
31 | }) | |
32 | } | |
33 | ], done) | |
34 | }) | |
35 | ||
b0ec596c C |
36 | it('Should create a new client') |
37 | ||
38 | it('Should return the first client') | |
39 | ||
40 | it('Should remove the last client') | |
41 | ||
0c1cbbfe C |
42 | it('Should not login with an invalid client id', function (done) { |
43 | const client = { id: 'client', password: server.client.secret } | |
8d309058 | 44 | loginUtils.login(server.url, client, server.user, 400, function (err, res) { |
0c1cbbfe C |
45 | if (err) throw err |
46 | ||
47 | expect(res.body.error).to.equal('invalid_client') | |
48 | done() | |
49 | }) | |
50 | }) | |
51 | ||
52 | it('Should not login with an invalid client password', function (done) { | |
53 | const client = { id: server.client.id, password: 'coucou' } | |
8d309058 | 54 | loginUtils.login(server.url, client, server.user, 400, function (err, res) { |
0c1cbbfe C |
55 | if (err) throw err |
56 | ||
57 | expect(res.body.error).to.equal('invalid_client') | |
58 | done() | |
59 | }) | |
60 | }) | |
61 | ||
62 | it('Should not login with an invalid username', function (done) { | |
63 | const user = { username: 'captain crochet', password: server.user.password } | |
8d309058 | 64 | loginUtils.login(server.url, server.client, user, 400, function (err, res) { |
0c1cbbfe C |
65 | if (err) throw err |
66 | ||
67 | expect(res.body.error).to.equal('invalid_grant') | |
68 | done() | |
69 | }) | |
70 | }) | |
71 | ||
72 | it('Should not login with an invalid password', function (done) { | |
73 | const user = { username: server.user.username, password: 'mewthree' } | |
8d309058 | 74 | loginUtils.login(server.url, server.client, user, 400, function (err, res) { |
0c1cbbfe C |
75 | if (err) throw err |
76 | ||
77 | expect(res.body.error).to.equal('invalid_grant') | |
78 | done() | |
79 | }) | |
80 | }) | |
81 | ||
82 | it('Should not be able to upload a video', function (done) { | |
bc503c2a | 83 | accessToken = 'mysupertoken' |
be587647 C |
84 | |
85 | const name = 'my super name' | |
86 | const description = 'my super description' | |
87 | const tags = [ 'tag1', 'tag2' ] | |
88 | const video = 'video_short.webm' | |
8d309058 | 89 | videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done) |
0c1cbbfe C |
90 | }) |
91 | ||
b3b92647 C |
92 | it('Should not be able to make friends', function (done) { |
93 | accessToken = 'mysupertoken' | |
8d309058 | 94 | podsUtils.makeFriends(server.url, accessToken, 401, done) |
b3b92647 C |
95 | }) |
96 | ||
97 | it('Should not be able to quit friends', function (done) { | |
98 | accessToken = 'mysupertoken' | |
8d309058 | 99 | podsUtils.quitFriends(server.url, accessToken, 401, done) |
b3b92647 C |
100 | }) |
101 | ||
0c1cbbfe | 102 | it('Should be able to login', function (done) { |
8d309058 | 103 | loginUtils.login(server.url, server.client, server.user, 200, function (err, res) { |
0c1cbbfe C |
104 | if (err) throw err |
105 | ||
bc503c2a | 106 | accessToken = res.body.access_token |
0c1cbbfe C |
107 | done() |
108 | }) | |
109 | }) | |
110 | ||
111 | it('Should upload the video with the correct token', function (done) { | |
be587647 C |
112 | const name = 'my super name' |
113 | const description = 'my super description' | |
114 | const tags = [ 'tag1', 'tag2' ] | |
115 | const video = 'video_short.webm' | |
8d309058 | 116 | videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) { |
0c1cbbfe C |
117 | if (err) throw err |
118 | ||
8d309058 | 119 | videosUtils.getVideosList(server.url, function (err, res) { |
0c1cbbfe C |
120 | if (err) throw err |
121 | ||
68ce3ae0 | 122 | const video = res.body.data[0] |
6d8ada5f C |
123 | expect(video.author).to.equal('root') |
124 | ||
bc503c2a | 125 | videoId = video.id |
0c1cbbfe C |
126 | done() |
127 | }) | |
128 | }) | |
129 | }) | |
130 | ||
131 | it('Should upload the video again with the correct token', function (done) { | |
be587647 C |
132 | const name = 'my super name 2' |
133 | const description = 'my super description 2' | |
134 | const tags = [ 'tag1' ] | |
135 | const video = 'video_short.webm' | |
8d309058 | 136 | videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done) |
0c1cbbfe C |
137 | }) |
138 | ||
139 | it('Should not be able to remove the video with an incorrect token', function (done) { | |
8d309058 | 140 | videosUtils.removeVideo(server.url, 'bad_token', videoId, 401, done) |
0c1cbbfe C |
141 | }) |
142 | ||
143 | it('Should not be able to remove the video with the token of another account') | |
144 | ||
145 | it('Should be able to remove the video with the correct token', function (done) { | |
8d309058 | 146 | videosUtils.removeVideo(server.url, accessToken, videoId, done) |
0c1cbbfe C |
147 | }) |
148 | ||
2f372a86 | 149 | it('Should logout (revoke token)') |
0c1cbbfe C |
150 | |
151 | it('Should not be able to upload a video') | |
152 | ||
153 | it('Should not be able to remove a video') | |
154 | ||
155 | it('Should be able to login again') | |
156 | ||
2f372a86 C |
157 | it('Should have an expired access token') |
158 | ||
159 | it('Should refresh the token') | |
160 | ||
161 | it('Should be able to upload a video again') | |
162 | ||
9bd26629 | 163 | it('Should be able to create a new user', function (done) { |
8d309058 | 164 | usersUtils.createUser(server.url, accessToken, 'user_1', 'super password', done) |
9bd26629 C |
165 | }) |
166 | ||
167 | it('Should be able to login with this user', function (done) { | |
168 | server.user = { | |
169 | username: 'user_1', | |
170 | password: 'super password' | |
171 | } | |
172 | ||
8d309058 | 173 | loginUtils.loginAndGetAccessToken(server, function (err, token) { |
9bd26629 C |
174 | if (err) throw err |
175 | ||
176 | accessTokenUser = token | |
177 | ||
178 | done() | |
179 | }) | |
180 | }) | |
181 | ||
99a64bfe | 182 | it('Should be able to get the user informations', function (done) { |
8d309058 | 183 | usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) { |
99a64bfe C |
184 | if (err) throw err |
185 | ||
186 | const user = res.body | |
187 | ||
188 | expect(user.username).to.equal('user_1') | |
ad4a8a1c | 189 | expect(user.email).to.equal('user_1@example.com') |
99a64bfe C |
190 | expect(user.id).to.exist |
191 | ||
192 | done() | |
193 | }) | |
194 | }) | |
195 | ||
9bd26629 C |
196 | it('Should be able to upload a video with this user', function (done) { |
197 | this.timeout(5000) | |
198 | ||
199 | const name = 'my super name' | |
200 | const description = 'my super description' | |
201 | const tags = [ 'tag1', 'tag2', 'tag3' ] | |
202 | const file = 'video_short.webm' | |
8d309058 | 203 | videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done) |
9bd26629 C |
204 | }) |
205 | ||
206 | it('Should list all the users', function (done) { | |
8d309058 | 207 | usersUtils.getUsersList(server.url, function (err, res) { |
9bd26629 C |
208 | if (err) throw err |
209 | ||
5c39adb7 C |
210 | const result = res.body |
211 | const total = result.total | |
212 | const users = result.data | |
9bd26629 | 213 | |
5c39adb7 | 214 | expect(total).to.equal(2) |
9bd26629 C |
215 | expect(users).to.be.an('array') |
216 | expect(users.length).to.equal(2) | |
217 | ||
5c39adb7 C |
218 | const user = users[0] |
219 | expect(user.username).to.equal('user_1') | |
ad4a8a1c | 220 | expect(user.email).to.equal('user_1@example.com') |
5c39adb7 C |
221 | |
222 | const rootUser = users[1] | |
9bd26629 | 223 | expect(rootUser.username).to.equal('root') |
ad4a8a1c | 224 | expect(rootUser.email).to.equal('admin1@example.com') |
5c39adb7 C |
225 | userId = user.id |
226 | ||
227 | done() | |
228 | }) | |
229 | }) | |
230 | ||
231 | it('Should list only the first user by username asc', function (done) { | |
232 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, 'username', function (err, res) { | |
233 | if (err) throw err | |
234 | ||
235 | const result = res.body | |
236 | const total = result.total | |
237 | const users = result.data | |
238 | ||
239 | expect(total).to.equal(2) | |
240 | expect(users.length).to.equal(1) | |
9bd26629 | 241 | |
5c39adb7 C |
242 | const user = users[0] |
243 | expect(user.username).to.equal('root') | |
ad4a8a1c | 244 | expect(user.email).to.equal('admin1@example.com') |
5c39adb7 C |
245 | |
246 | done() | |
247 | }) | |
248 | }) | |
249 | ||
250 | it('Should list only the first user by username desc', function (done) { | |
251 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-username', function (err, res) { | |
252 | if (err) throw err | |
253 | ||
254 | const result = res.body | |
255 | const total = result.total | |
256 | const users = result.data | |
257 | ||
258 | expect(total).to.equal(2) | |
259 | expect(users.length).to.equal(1) | |
260 | ||
261 | const user = users[0] | |
9bd26629 | 262 | expect(user.username).to.equal('user_1') |
ad4a8a1c | 263 | expect(user.email).to.equal('user_1@example.com') |
5c39adb7 C |
264 | |
265 | done() | |
266 | }) | |
267 | }) | |
268 | ||
feb4bdfd C |
269 | it('Should list only the second user by createdAt desc', function (done) { |
270 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdAt', function (err, res) { | |
5c39adb7 C |
271 | if (err) throw err |
272 | ||
273 | const result = res.body | |
274 | const total = result.total | |
275 | const users = result.data | |
276 | ||
277 | expect(total).to.equal(2) | |
278 | expect(users.length).to.equal(1) | |
279 | ||
280 | const user = users[0] | |
281 | expect(user.username).to.equal('user_1') | |
ad4a8a1c | 282 | expect(user.email).to.equal('user_1@example.com') |
5c39adb7 C |
283 | |
284 | done() | |
285 | }) | |
286 | }) | |
287 | ||
feb4bdfd C |
288 | it('Should list all the users by createdAt asc', function (done) { |
289 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdAt', function (err, res) { | |
5c39adb7 C |
290 | if (err) throw err |
291 | ||
292 | const result = res.body | |
293 | const total = result.total | |
294 | const users = result.data | |
295 | ||
296 | expect(total).to.equal(2) | |
297 | expect(users.length).to.equal(2) | |
298 | ||
299 | expect(users[0].username).to.equal('root') | |
ad4a8a1c | 300 | expect(users[0].email).to.equal('admin1@example.com') |
5c39adb7 | 301 | expect(users[1].username).to.equal('user_1') |
ad4a8a1c | 302 | expect(users[1].email).to.equal('user_1@example.com') |
9bd26629 C |
303 | |
304 | done() | |
305 | }) | |
306 | }) | |
307 | ||
308 | it('Should update the user password', function (done) { | |
8d309058 | 309 | usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) { |
9bd26629 C |
310 | if (err) throw err |
311 | ||
312 | server.user.password = 'new password' | |
8d309058 | 313 | loginUtils.login(server.url, server.client, server.user, 200, done) |
9bd26629 C |
314 | }) |
315 | }) | |
316 | ||
317 | it('Should be able to remove this user', function (done) { | |
68a3b9f2 | 318 | usersUtils.removeUser(server.url, userId, accessToken, done) |
9bd26629 C |
319 | }) |
320 | ||
321 | it('Should not be able to login with this user', function (done) { | |
322 | // server.user is already set to user 1 | |
8d309058 | 323 | loginUtils.login(server.url, server.client, server.user, 400, done) |
9bd26629 C |
324 | }) |
325 | ||
326 | it('Should not have videos of this user', function (done) { | |
8d309058 | 327 | videosUtils.getVideosList(server.url, function (err, res) { |
9bd26629 C |
328 | if (err) throw err |
329 | ||
330 | expect(res.body.total).to.equal(1) | |
331 | const video = res.body.data[0] | |
332 | expect(video.author).to.equal('root') | |
333 | ||
334 | done() | |
335 | }) | |
336 | }) | |
337 | ||
0c1cbbfe C |
338 | after(function (done) { |
339 | process.kill(-server.app.pid) | |
340 | ||
341 | // Keep the logs if the test failed | |
342 | if (this.ok) { | |
8d309058 | 343 | serversUtils.flushTests(done) |
0c1cbbfe C |
344 | } else { |
345 | done() | |
346 | } | |
347 | }) | |
348 | }) |