aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/login.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-07 22:09:59 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-07 22:09:59 +0200
commit8d30905858245f12a42fc327d2d57cbfe062d548 (patch)
tree9bd590872fbb753782f2ebbb9516db0414022d70 /server/tests/utils/login.js
parent58b2ba55a90f05f24661e664b1fb0a3486f037e8 (diff)
downloadPeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.tar.gz
PeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.tar.zst
PeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.zip
Server: split tests utils in multiple files
Diffstat (limited to 'server/tests/utils/login.js')
-rw-r--r--server/tests/utils/login.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/server/tests/utils/login.js b/server/tests/utils/login.js
new file mode 100644
index 000000000..1a5d75bc4
--- /dev/null
+++ b/server/tests/utils/login.js
@@ -0,0 +1,48 @@
1'use strict'
2
3const request = require('supertest')
4
5const loginUtils = {
6 login: login,
7 loginAndGetAccessToken: loginAndGetAccessToken
8}
9
10// ---------------------- Export functions --------------------
11
12function login (url, client, user, expectedStatus, end) {
13 if (!end) {
14 end = expectedStatus
15 expectedStatus = 200
16 }
17
18 const path = '/api/v1/users/token'
19
20 const body = {
21 client_id: client.id,
22 client_secret: client.secret,
23 username: user.username,
24 password: user.password,
25 response_type: 'code',
26 grant_type: 'password',
27 scope: 'upload'
28 }
29
30 request(url)
31 .post(path)
32 .type('form')
33 .send(body)
34 .expect(expectedStatus)
35 .end(end)
36}
37
38function loginAndGetAccessToken (server, callback) {
39 login(server.url, server.client, server.user, 200, function (err, res) {
40 if (err) return callback(err)
41
42 return callback(null, res.body.access_token)
43 })
44}
45
46// ---------------------------------------------------------------------------
47
48module.exports = loginUtils