]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/users.js
Remove livereload module (role of webpack now)
[github/Chocobozzz/PeerTube.git] / server / tests / api / users.js
CommitLineData
0c1cbbfe
C
1'use strict'
2
3const async = require('async')
4const chai = require('chai')
5const expect = chai.expect
6const pathUtils = require('path')
7
8const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
9webtorrent.silent = true
10
11const utils = require('./utils')
12
13describe('Test users', function () {
14 let server = null
bc503c2a
C
15 let accessToken = null
16 let videoId
0c1cbbfe
C
17
18 before(function (done) {
19 this.timeout(20000)
20
21 async.series([
22 function (next) {
23 utils.flushTests(next)
24 },
25 function (next) {
26 utils.runServer(1, function (server1) {
27 server = server1
28 next()
29 })
30 }
31 ], done)
32 })
33
b0ec596c
C
34 it('Should create a new client')
35
36 it('Should return the first client')
37
38 it('Should remove the last client')
39
0c1cbbfe
C
40 it('Should not login with an invalid client id', function (done) {
41 const client = { id: 'client', password: server.client.secret }
42 utils.login(server.url, client, server.user, 400, function (err, res) {
43 if (err) throw err
44
45 expect(res.body.error).to.equal('invalid_client')
46 done()
47 })
48 })
49
50 it('Should not login with an invalid client password', function (done) {
51 const client = { id: server.client.id, password: 'coucou' }
52 utils.login(server.url, client, server.user, 400, function (err, res) {
53 if (err) throw err
54
55 expect(res.body.error).to.equal('invalid_client')
56 done()
57 })
58 })
59
60 it('Should not login with an invalid username', function (done) {
61 const user = { username: 'captain crochet', password: server.user.password }
62 utils.login(server.url, server.client, user, 400, function (err, res) {
63 if (err) throw err
64
65 expect(res.body.error).to.equal('invalid_grant')
66 done()
67 })
68 })
69
70 it('Should not login with an invalid password', function (done) {
71 const user = { username: server.user.username, password: 'mewthree' }
72 utils.login(server.url, server.client, user, 400, function (err, res) {
73 if (err) throw err
74
75 expect(res.body.error).to.equal('invalid_grant')
76 done()
77 })
78 })
79
80 it('Should not be able to upload a video', function (done) {
bc503c2a 81 accessToken = 'mysupertoken'
be587647
C
82
83 const name = 'my super name'
84 const description = 'my super description'
85 const tags = [ 'tag1', 'tag2' ]
86 const video = 'video_short.webm'
87 utils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
0c1cbbfe
C
88 })
89
b3b92647
C
90 it('Should not be able to make friends', function (done) {
91 accessToken = 'mysupertoken'
92 utils.makeFriends(server.url, accessToken, 401, done)
93 })
94
95 it('Should not be able to quit friends', function (done) {
96 accessToken = 'mysupertoken'
97 utils.quitFriends(server.url, accessToken, 401, done)
98 })
99
0c1cbbfe
C
100 it('Should be able to login', function (done) {
101 utils.login(server.url, server.client, server.user, 200, function (err, res) {
102 if (err) throw err
103
bc503c2a 104 accessToken = res.body.access_token
0c1cbbfe
C
105 done()
106 })
107 })
108
109 it('Should upload the video with the correct token', function (done) {
be587647
C
110 const name = 'my super name'
111 const description = 'my super description'
112 const tags = [ 'tag1', 'tag2' ]
113 const video = 'video_short.webm'
114 utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
0c1cbbfe
C
115 if (err) throw err
116
117 utils.getVideosList(server.url, function (err, res) {
118 if (err) throw err
119
68ce3ae0 120 const video = res.body.data[0]
6d8ada5f
C
121 expect(video.author).to.equal('root')
122
bc503c2a 123 videoId = video.id
0c1cbbfe
C
124 done()
125 })
126 })
127 })
128
129 it('Should upload the video again with the correct token', function (done) {
be587647
C
130 const name = 'my super name 2'
131 const description = 'my super description 2'
132 const tags = [ 'tag1' ]
133 const video = 'video_short.webm'
134 utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
0c1cbbfe
C
135 })
136
137 it('Should not be able to remove the video with an incorrect token', function (done) {
bc503c2a 138 utils.removeVideo(server.url, 'bad_token', videoId, 401, done)
0c1cbbfe
C
139 })
140
141 it('Should not be able to remove the video with the token of another account')
142
143 it('Should be able to remove the video with the correct token', function (done) {
bc503c2a 144 utils.removeVideo(server.url, accessToken, videoId, done)
0c1cbbfe
C
145 })
146
147 it('Should logout')
148
149 it('Should not be able to upload a video')
150
151 it('Should not be able to remove a video')
152
153 it('Should be able to login again')
154
155 after(function (done) {
156 process.kill(-server.app.pid)
157
158 // Keep the logs if the test failed
159 if (this.ok) {
160 utils.flushTests(done)
161 } else {
162 done()
163 }
164 })
165})