aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-04 22:32:36 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-04 22:33:38 +0200
commit9bd2662976a75d3b03364cdbe6419e57c80f99a6 (patch)
tree0b5289660f843a8ba7f13aa79d458f53c94b36d9 /server/tests/api/users.js
parente4c556196d7b31111f17596840d2e1d60caa7dcb (diff)
downloadPeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.gz
PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.zst
PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.zip
Implement user API (create, update, remove, list)
Diffstat (limited to 'server/tests/api/users.js')
-rw-r--r--server/tests/api/users.js83
1 files changed, 82 insertions, 1 deletions
diff --git a/server/tests/api/users.js b/server/tests/api/users.js
index 68ba9de33..c711d6b64 100644
--- a/server/tests/api/users.js
+++ b/server/tests/api/users.js
@@ -13,7 +13,9 @@ const utils = require('./utils')
13describe('Test users', function () { 13describe('Test users', function () {
14 let server = null 14 let server = null
15 let accessToken = null 15 let accessToken = null
16 let videoId 16 let accessTokenUser = null
17 let videoId = null
18 let userId = null
17 19
18 before(function (done) { 20 before(function (done) {
19 this.timeout(20000) 21 this.timeout(20000)
@@ -158,6 +160,85 @@ describe('Test users', function () {
158 160
159 it('Should be able to upload a video again') 161 it('Should be able to upload a video again')
160 162
163 it('Should be able to create a new user', function (done) {
164 utils.createUser(server.url, accessToken, 'user_1', 'super password', done)
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
173 utils.loginAndGetAccessToken(server, function (err, token) {
174 if (err) throw err
175
176 accessTokenUser = token
177
178 done()
179 })
180 })
181
182 it('Should be able to upload a video with this user', function (done) {
183 this.timeout(5000)
184
185 const name = 'my super name'
186 const description = 'my super description'
187 const tags = [ 'tag1', 'tag2', 'tag3' ]
188 const file = 'video_short.webm'
189 utils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done)
190 })
191
192 it('Should list all the users', function (done) {
193 utils.getUsersList(server.url, function (err, res) {
194 if (err) throw err
195
196 const users = res.body.data
197
198 expect(users).to.be.an('array')
199 expect(users.length).to.equal(2)
200
201 const rootUser = users[0]
202 expect(rootUser.username).to.equal('root')
203
204 const user = users[1]
205 expect(user.username).to.equal('user_1')
206 userId = user.id
207
208 done()
209 })
210 })
211
212 it('Should update the user password', function (done) {
213 utils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) {
214 if (err) throw err
215
216 server.user.password = 'new password'
217 utils.login(server.url, server.client, server.user, 200, done)
218 })
219 })
220
221 it('Should be able to remove this user', function (done) {
222 utils.removeUser(server.url, accessToken, 'user_1', done)
223 })
224
225 it('Should not be able to login with this user', function (done) {
226 // server.user is already set to user 1
227 utils.login(server.url, server.client, server.user, 400, done)
228 })
229
230 it('Should not have videos of this user', function (done) {
231 utils.getVideosList(server.url, function (err, res) {
232 if (err) throw err
233
234 expect(res.body.total).to.equal(1)
235 const video = res.body.data[0]
236 expect(video.author).to.equal('root')
237
238 done()
239 })
240 })
241
161 after(function (done) { 242 after(function (done) {
162 process.kill(-server.app.pid) 243 process.kill(-server.app.pid)
163 244