]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users.js
3 const chai
= require('chai')
4 const expect
= chai
.expect
5 const series
= require('async/series')
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')
13 describe('Test users', function () {
15 let accessToken
= null
16 let accessTokenUser
= null
20 before(function (done
) {
25 serversUtils
.flushTests(next
)
28 serversUtils
.runServer(1, function (server1
) {
36 it('Should create a new client')
38 it('Should return the first client')
40 it('Should remove the last client')
42 it('Should not login with an invalid client id', function (done
) {
43 const client
= { id: 'client', password: server
.client
.secret
}
44 loginUtils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
47 expect(res
.body
.error
).to
.equal('invalid_client')
52 it('Should not login with an invalid client password', function (done
) {
53 const client
= { id: server
.client
.id
, password: 'coucou' }
54 loginUtils
.login(server
.url
, client
, server
.user
, 400, function (err
, res
) {
57 expect(res
.body
.error
).to
.equal('invalid_client')
62 it('Should not login with an invalid username', function (done
) {
63 const user
= { username: 'captain crochet', password: server
.user
.password
}
64 loginUtils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
67 expect(res
.body
.error
).to
.equal('invalid_grant')
72 it('Should not login with an invalid password', function (done
) {
73 const user
= { username: server
.user
.username
, password: 'mewthree' }
74 loginUtils
.login(server
.url
, server
.client
, user
, 400, function (err
, res
) {
77 expect(res
.body
.error
).to
.equal('invalid_grant')
82 it('Should not be able to upload a video', function (done
) {
83 accessToken
= 'mysupertoken'
85 const name
= 'my super name'
86 const description
= 'my super description'
87 const tags
= [ 'tag1', 'tag2' ]
88 const video
= 'video_short.webm'
89 videosUtils
.uploadVideo(server
.url
, accessToken
, name
, description
, tags
, video
, 401, done
)
92 it('Should not be able to make friends', function (done
) {
93 accessToken
= 'mysupertoken'
94 podsUtils
.makeFriends(server
.url
, accessToken
, 401, done
)
97 it('Should not be able to quit friends', function (done
) {
98 accessToken
= 'mysupertoken'
99 podsUtils
.quitFriends(server
.url
, accessToken
, 401, done
)
102 it('Should be able to login', function (done
) {
103 loginUtils
.login(server
.url
, server
.client
, server
.user
, 200, function (err
, res
) {
106 accessToken
= res
.body
.access_token
111 it('Should upload the video with the correct token', function (done
) {
112 const name
= 'my super name'
113 const description
= 'my super description'
114 const tags
= [ 'tag1', 'tag2' ]
115 const video
= 'video_short.webm'
116 videosUtils
.uploadVideo(server
.url
, accessToken
, name
, description
, tags
, video
, 204, function (err
, res
) {
119 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
122 const video
= res
.body
.data
[0]
123 expect(video
.author
).to
.equal('root')
131 it('Should upload the video again with the correct token', function (done
) {
132 const name
= 'my super name 2'
133 const description
= 'my super description 2'
134 const tags
= [ 'tag1' ]
135 const video
= 'video_short.webm'
136 videosUtils
.uploadVideo(server
.url
, accessToken
, name
, description
, tags
, video
, 204, done
)
139 it('Should not be able to remove the video with an incorrect token', function (done
) {
140 videosUtils
.removeVideo(server
.url
, 'bad_token', videoId
, 401, done
)
143 it('Should not be able to remove the video with the token of another account')
145 it('Should be able to remove the video with the correct token', function (done
) {
146 videosUtils
.removeVideo(server
.url
, accessToken
, videoId
, done
)
149 it('Should logout (revoke token)')
151 it('Should not be able to upload a video')
153 it('Should not be able to remove a video')
155 it('Should be able to login again')
157 it('Should have an expired access token')
159 it('Should refresh the token')
161 it('Should be able to upload a video again')
163 it('Should be able to create a new user', function (done
) {
164 usersUtils
.createUser(server
.url
, accessToken
, 'user_1', 'super password', done
)
167 it('Should be able to login with this user', function (done
) {
170 password: 'super password'
173 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
176 accessTokenUser
= token
182 it('Should be able to get the user informations', function (done
) {
183 usersUtils
.getUserInformation(server
.url
, accessTokenUser
, function (err
, res
) {
186 const user
= res
.body
188 expect(user
.username
).to
.equal('user_1')
189 expect(user
.id
).to
.exist
195 it('Should be able to upload a video with this user', function (done
) {
198 const name
= 'my super name'
199 const description
= 'my super description'
200 const tags
= [ 'tag1', 'tag2', 'tag3' ]
201 const file
= 'video_short.webm'
202 videosUtils
.uploadVideo(server
.url
, accessTokenUser
, name
, description
, tags
, file
, done
)
205 it('Should list all the users', function (done
) {
206 usersUtils
.getUsersList(server
.url
, function (err
, res
) {
209 const result
= res
.body
210 const total
= result
.total
211 const users
= result
.data
213 expect(total
).to
.equal(2)
214 expect(users
).to
.be
.an('array')
215 expect(users
.length
).to
.equal(2)
217 const user
= users
[0]
218 expect(user
.username
).to
.equal('user_1')
220 const rootUser
= users
[1]
221 expect(rootUser
.username
).to
.equal('root')
228 it('Should list only the first user by username asc', function (done
) {
229 usersUtils
.getUsersListPaginationAndSort(server
.url
, 0, 1, 'username', function (err
, res
) {
232 const result
= res
.body
233 const total
= result
.total
234 const users
= result
.data
236 expect(total
).to
.equal(2)
237 expect(users
.length
).to
.equal(1)
239 const user
= users
[0]
240 expect(user
.username
).to
.equal('root')
246 it('Should list only the first user by username desc', function (done
) {
247 usersUtils
.getUsersListPaginationAndSort(server
.url
, 0, 1, '-username', function (err
, res
) {
250 const result
= res
.body
251 const total
= result
.total
252 const users
= result
.data
254 expect(total
).to
.equal(2)
255 expect(users
.length
).to
.equal(1)
257 const user
= users
[0]
258 expect(user
.username
).to
.equal('user_1')
264 it('Should list only the second user by createdAt desc', function (done
) {
265 usersUtils
.getUsersListPaginationAndSort(server
.url
, 0, 1, '-createdAt', function (err
, res
) {
268 const result
= res
.body
269 const total
= result
.total
270 const users
= result
.data
272 expect(total
).to
.equal(2)
273 expect(users
.length
).to
.equal(1)
275 const user
= users
[0]
276 expect(user
.username
).to
.equal('user_1')
282 it('Should list all the users by createdAt asc', function (done
) {
283 usersUtils
.getUsersListPaginationAndSort(server
.url
, 0, 2, 'createdAt', function (err
, res
) {
286 const result
= res
.body
287 const total
= result
.total
288 const users
= result
.data
290 expect(total
).to
.equal(2)
291 expect(users
.length
).to
.equal(2)
293 expect(users
[0].username
).to
.equal('root')
294 expect(users
[1].username
).to
.equal('user_1')
300 it('Should update the user password', function (done
) {
301 usersUtils
.updateUser(server
.url
, userId
, accessTokenUser
, 'new password', function (err
, res
) {
304 server
.user
.password
= 'new password'
305 loginUtils
.login(server
.url
, server
.client
, server
.user
, 200, done
)
309 it('Should be able to remove this user', function (done
) {
310 usersUtils
.removeUser(server
.url
, userId
, accessToken
, done
)
313 it('Should not be able to login with this user', function (done
) {
314 // server.user is already set to user 1
315 loginUtils
.login(server
.url
, server
.client
, server
.user
, 400, done
)
318 it('Should not have videos of this user', function (done
) {
319 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
322 expect(res
.body
.total
).to
.equal(1)
323 const video
= res
.body
.data
[0]
324 expect(video
.author
).to
.equal('root')
330 after(function (done
) {
331 process
.kill(-server
.app
.pid
)
333 // Keep the logs if the test failed
335 serversUtils
.flushTests(done
)