aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/login.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/login.js')
-rw-r--r--server/tests/utils/login.js57
1 files changed, 0 insertions, 57 deletions
diff --git a/server/tests/utils/login.js b/server/tests/utils/login.js
deleted file mode 100644
index c984c0baf..000000000
--- a/server/tests/utils/login.js
+++ /dev/null
@@ -1,57 +0,0 @@
1'use strict'
2
3const request = require('supertest')
4
5const loginUtils = {
6 login,
7 loginAndGetAccessToken,
8 getUserAccessToken
9}
10
11// ---------------------- Export functions --------------------
12
13function login (url, client, user, expectedStatus, end) {
14 if (!end) {
15 end = expectedStatus
16 expectedStatus = 200
17 }
18
19 const path = '/api/v1/users/token'
20
21 const body = {
22 client_id: client.id,
23 client_secret: client.secret,
24 username: user.username,
25 password: user.password,
26 response_type: 'code',
27 grant_type: 'password',
28 scope: 'upload'
29 }
30
31 request(url)
32 .post(path)
33 .type('form')
34 .send(body)
35 .expect(expectedStatus)
36 .end(end)
37}
38
39function loginAndGetAccessToken (server, callback) {
40 login(server.url, server.client, server.user, 200, function (err, res) {
41 if (err) return callback(err)
42
43 return callback(null, res.body.access_token)
44 })
45}
46
47function getUserAccessToken (server, user, callback) {
48 login(server.url, server.client, user, 200, function (err, res) {
49 if (err) return callback(err)
50
51 return callback(null, res.body.access_token)
52 })
53}
54
55// ---------------------------------------------------------------------------
56
57module.exports = loginUtils