diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-07 22:09:59 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-07 22:09:59 +0200 |
commit | 8d30905858245f12a42fc327d2d57cbfe062d548 (patch) | |
tree | 9bd590872fbb753782f2ebbb9516db0414022d70 /server/tests/utils/login.js | |
parent | 58b2ba55a90f05f24661e664b1fb0a3486f037e8 (diff) | |
download | PeerTube-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.js | 48 |
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 | |||
3 | const request = require('supertest') | ||
4 | |||
5 | const loginUtils = { | ||
6 | login: login, | ||
7 | loginAndGetAccessToken: loginAndGetAccessToken | ||
8 | } | ||
9 | |||
10 | // ---------------------- Export functions -------------------- | ||
11 | |||
12 | function 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 | |||
38 | function 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 | |||
48 | module.exports = loginUtils | ||