]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/login.js
Server: remove useless hash affectations
[github/Chocobozzz/PeerTube.git] / server / tests / utils / login.js
CommitLineData
8d309058
C
1'use strict'
2
3const request = require('supertest')
4
5const loginUtils = {
c4403b29
C
6 login,
7 loginAndGetAccessToken
8d309058
C
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