diff options
Diffstat (limited to 'server/tests/api/users.js')
-rw-r--r-- | server/tests/api/users.js | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/server/tests/api/users.js b/server/tests/api/users.js index e1d4a8cf4..6f9eef181 100644 --- a/server/tests/api/users.js +++ b/server/tests/api/users.js | |||
@@ -5,11 +5,14 @@ const expect = chai.expect | |||
5 | const pathUtils = require('path') | 5 | const pathUtils = require('path') |
6 | const series = require('async/series') | 6 | const series = require('async/series') |
7 | 7 | ||
8 | const loginUtils = require('../utils/login') | ||
9 | const podsUtils = require('../utils/pods') | ||
10 | const serversUtils = require('../utils/servers') | ||
11 | const usersUtils = require('../utils/users') | ||
12 | const videosUtils = require('../utils/videos') | ||
8 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) | 13 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) |
9 | webtorrent.silent = true | 14 | webtorrent.silent = true |
10 | 15 | ||
11 | const utils = require('./utils') | ||
12 | |||
13 | describe('Test users', function () { | 16 | describe('Test users', function () { |
14 | let server = null | 17 | let server = null |
15 | let accessToken = null | 18 | let accessToken = null |
@@ -22,10 +25,10 @@ describe('Test users', function () { | |||
22 | 25 | ||
23 | series([ | 26 | series([ |
24 | function (next) { | 27 | function (next) { |
25 | utils.flushTests(next) | 28 | serversUtils.flushTests(next) |
26 | }, | 29 | }, |
27 | function (next) { | 30 | function (next) { |
28 | utils.runServer(1, function (server1) { | 31 | serversUtils.runServer(1, function (server1) { |
29 | server = server1 | 32 | server = server1 |
30 | next() | 33 | next() |
31 | }) | 34 | }) |
@@ -41,7 +44,7 @@ describe('Test users', function () { | |||
41 | 44 | ||
42 | it('Should not login with an invalid client id', function (done) { | 45 | it('Should not login with an invalid client id', function (done) { |
43 | const client = { id: 'client', password: server.client.secret } | 46 | const client = { id: 'client', password: server.client.secret } |
44 | utils.login(server.url, client, server.user, 400, function (err, res) { | 47 | loginUtils.login(server.url, client, server.user, 400, function (err, res) { |
45 | if (err) throw err | 48 | if (err) throw err |
46 | 49 | ||
47 | expect(res.body.error).to.equal('invalid_client') | 50 | expect(res.body.error).to.equal('invalid_client') |
@@ -51,7 +54,7 @@ describe('Test users', function () { | |||
51 | 54 | ||
52 | it('Should not login with an invalid client password', function (done) { | 55 | it('Should not login with an invalid client password', function (done) { |
53 | const client = { id: server.client.id, password: 'coucou' } | 56 | const client = { id: server.client.id, password: 'coucou' } |
54 | utils.login(server.url, client, server.user, 400, function (err, res) { | 57 | loginUtils.login(server.url, client, server.user, 400, function (err, res) { |
55 | if (err) throw err | 58 | if (err) throw err |
56 | 59 | ||
57 | expect(res.body.error).to.equal('invalid_client') | 60 | expect(res.body.error).to.equal('invalid_client') |
@@ -61,7 +64,7 @@ describe('Test users', function () { | |||
61 | 64 | ||
62 | it('Should not login with an invalid username', function (done) { | 65 | it('Should not login with an invalid username', function (done) { |
63 | const user = { username: 'captain crochet', password: server.user.password } | 66 | const user = { username: 'captain crochet', password: server.user.password } |
64 | utils.login(server.url, server.client, user, 400, function (err, res) { | 67 | loginUtils.login(server.url, server.client, user, 400, function (err, res) { |
65 | if (err) throw err | 68 | if (err) throw err |
66 | 69 | ||
67 | expect(res.body.error).to.equal('invalid_grant') | 70 | expect(res.body.error).to.equal('invalid_grant') |
@@ -71,7 +74,7 @@ describe('Test users', function () { | |||
71 | 74 | ||
72 | it('Should not login with an invalid password', function (done) { | 75 | it('Should not login with an invalid password', function (done) { |
73 | const user = { username: server.user.username, password: 'mewthree' } | 76 | const user = { username: server.user.username, password: 'mewthree' } |
74 | utils.login(server.url, server.client, user, 400, function (err, res) { | 77 | loginUtils.login(server.url, server.client, user, 400, function (err, res) { |
75 | if (err) throw err | 78 | if (err) throw err |
76 | 79 | ||
77 | expect(res.body.error).to.equal('invalid_grant') | 80 | expect(res.body.error).to.equal('invalid_grant') |
@@ -86,21 +89,21 @@ describe('Test users', function () { | |||
86 | const description = 'my super description' | 89 | const description = 'my super description' |
87 | const tags = [ 'tag1', 'tag2' ] | 90 | const tags = [ 'tag1', 'tag2' ] |
88 | const video = 'video_short.webm' | 91 | const video = 'video_short.webm' |
89 | utils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done) | 92 | videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done) |
90 | }) | 93 | }) |
91 | 94 | ||
92 | it('Should not be able to make friends', function (done) { | 95 | it('Should not be able to make friends', function (done) { |
93 | accessToken = 'mysupertoken' | 96 | accessToken = 'mysupertoken' |
94 | utils.makeFriends(server.url, accessToken, 401, done) | 97 | podsUtils.makeFriends(server.url, accessToken, 401, done) |
95 | }) | 98 | }) |
96 | 99 | ||
97 | it('Should not be able to quit friends', function (done) { | 100 | it('Should not be able to quit friends', function (done) { |
98 | accessToken = 'mysupertoken' | 101 | accessToken = 'mysupertoken' |
99 | utils.quitFriends(server.url, accessToken, 401, done) | 102 | podsUtils.quitFriends(server.url, accessToken, 401, done) |
100 | }) | 103 | }) |
101 | 104 | ||
102 | it('Should be able to login', function (done) { | 105 | it('Should be able to login', function (done) { |
103 | utils.login(server.url, server.client, server.user, 200, function (err, res) { | 106 | loginUtils.login(server.url, server.client, server.user, 200, function (err, res) { |
104 | if (err) throw err | 107 | if (err) throw err |
105 | 108 | ||
106 | accessToken = res.body.access_token | 109 | accessToken = res.body.access_token |
@@ -113,10 +116,10 @@ describe('Test users', function () { | |||
113 | const description = 'my super description' | 116 | const description = 'my super description' |
114 | const tags = [ 'tag1', 'tag2' ] | 117 | const tags = [ 'tag1', 'tag2' ] |
115 | const video = 'video_short.webm' | 118 | const video = 'video_short.webm' |
116 | utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) { | 119 | videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) { |
117 | if (err) throw err | 120 | if (err) throw err |
118 | 121 | ||
119 | utils.getVideosList(server.url, function (err, res) { | 122 | videosUtils.getVideosList(server.url, function (err, res) { |
120 | if (err) throw err | 123 | if (err) throw err |
121 | 124 | ||
122 | const video = res.body.data[0] | 125 | const video = res.body.data[0] |
@@ -133,17 +136,17 @@ describe('Test users', function () { | |||
133 | const description = 'my super description 2' | 136 | const description = 'my super description 2' |
134 | const tags = [ 'tag1' ] | 137 | const tags = [ 'tag1' ] |
135 | const video = 'video_short.webm' | 138 | const video = 'video_short.webm' |
136 | utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done) | 139 | videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done) |
137 | }) | 140 | }) |
138 | 141 | ||
139 | it('Should not be able to remove the video with an incorrect token', function (done) { | 142 | it('Should not be able to remove the video with an incorrect token', function (done) { |
140 | utils.removeVideo(server.url, 'bad_token', videoId, 401, done) | 143 | videosUtils.removeVideo(server.url, 'bad_token', videoId, 401, done) |
141 | }) | 144 | }) |
142 | 145 | ||
143 | it('Should not be able to remove the video with the token of another account') | 146 | it('Should not be able to remove the video with the token of another account') |
144 | 147 | ||
145 | it('Should be able to remove the video with the correct token', function (done) { | 148 | it('Should be able to remove the video with the correct token', function (done) { |
146 | utils.removeVideo(server.url, accessToken, videoId, done) | 149 | videosUtils.removeVideo(server.url, accessToken, videoId, done) |
147 | }) | 150 | }) |
148 | 151 | ||
149 | it('Should logout (revoke token)') | 152 | it('Should logout (revoke token)') |
@@ -161,7 +164,7 @@ describe('Test users', function () { | |||
161 | it('Should be able to upload a video again') | 164 | it('Should be able to upload a video again') |
162 | 165 | ||
163 | it('Should be able to create a new user', function (done) { | 166 | it('Should be able to create a new user', function (done) { |
164 | utils.createUser(server.url, accessToken, 'user_1', 'super password', done) | 167 | usersUtils.createUser(server.url, accessToken, 'user_1', 'super password', done) |
165 | }) | 168 | }) |
166 | 169 | ||
167 | it('Should be able to login with this user', function (done) { | 170 | it('Should be able to login with this user', function (done) { |
@@ -170,7 +173,7 @@ describe('Test users', function () { | |||
170 | password: 'super password' | 173 | password: 'super password' |
171 | } | 174 | } |
172 | 175 | ||
173 | utils.loginAndGetAccessToken(server, function (err, token) { | 176 | loginUtils.loginAndGetAccessToken(server, function (err, token) { |
174 | if (err) throw err | 177 | if (err) throw err |
175 | 178 | ||
176 | accessTokenUser = token | 179 | accessTokenUser = token |
@@ -180,7 +183,7 @@ describe('Test users', function () { | |||
180 | }) | 183 | }) |
181 | 184 | ||
182 | it('Should be able to get the user informations', function (done) { | 185 | it('Should be able to get the user informations', function (done) { |
183 | utils.getUserInformation(server.url, accessTokenUser, function (err, res) { | 186 | usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) { |
184 | if (err) throw err | 187 | if (err) throw err |
185 | 188 | ||
186 | const user = res.body | 189 | const user = res.body |
@@ -199,11 +202,11 @@ describe('Test users', function () { | |||
199 | const description = 'my super description' | 202 | const description = 'my super description' |
200 | const tags = [ 'tag1', 'tag2', 'tag3' ] | 203 | const tags = [ 'tag1', 'tag2', 'tag3' ] |
201 | const file = 'video_short.webm' | 204 | const file = 'video_short.webm' |
202 | utils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done) | 205 | videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done) |
203 | }) | 206 | }) |
204 | 207 | ||
205 | it('Should list all the users', function (done) { | 208 | it('Should list all the users', function (done) { |
206 | utils.getUsersList(server.url, function (err, res) { | 209 | usersUtils.getUsersList(server.url, function (err, res) { |
207 | if (err) throw err | 210 | if (err) throw err |
208 | 211 | ||
209 | const users = res.body.data | 212 | const users = res.body.data |
@@ -223,25 +226,25 @@ describe('Test users', function () { | |||
223 | }) | 226 | }) |
224 | 227 | ||
225 | it('Should update the user password', function (done) { | 228 | it('Should update the user password', function (done) { |
226 | utils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) { | 229 | usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) { |
227 | if (err) throw err | 230 | if (err) throw err |
228 | 231 | ||
229 | server.user.password = 'new password' | 232 | server.user.password = 'new password' |
230 | utils.login(server.url, server.client, server.user, 200, done) | 233 | loginUtils.login(server.url, server.client, server.user, 200, done) |
231 | }) | 234 | }) |
232 | }) | 235 | }) |
233 | 236 | ||
234 | it('Should be able to remove this user', function (done) { | 237 | it('Should be able to remove this user', function (done) { |
235 | utils.removeUser(server.url, accessToken, 'user_1', done) | 238 | usersUtils.removeUser(server.url, accessToken, 'user_1', done) |
236 | }) | 239 | }) |
237 | 240 | ||
238 | it('Should not be able to login with this user', function (done) { | 241 | it('Should not be able to login with this user', function (done) { |
239 | // server.user is already set to user 1 | 242 | // server.user is already set to user 1 |
240 | utils.login(server.url, server.client, server.user, 400, done) | 243 | loginUtils.login(server.url, server.client, server.user, 400, done) |
241 | }) | 244 | }) |
242 | 245 | ||
243 | it('Should not have videos of this user', function (done) { | 246 | it('Should not have videos of this user', function (done) { |
244 | utils.getVideosList(server.url, function (err, res) { | 247 | videosUtils.getVideosList(server.url, function (err, res) { |
245 | if (err) throw err | 248 | if (err) throw err |
246 | 249 | ||
247 | expect(res.body.total).to.equal(1) | 250 | expect(res.body.total).to.equal(1) |
@@ -257,7 +260,7 @@ describe('Test users', function () { | |||
257 | 260 | ||
258 | // Keep the logs if the test failed | 261 | // Keep the logs if the test failed |
259 | if (this.ok) { | 262 | if (this.ok) { |
260 | utils.flushTests(done) | 263 | serversUtils.flushTests(done) |
261 | } else { | 264 | } else { |
262 | done() | 265 | done() |
263 | } | 266 | } |