diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-09-04 21:21:47 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-09-04 21:30:18 +0200 |
commit | 0e1dc3e7c69995c691e1dd82e3c2bc68748661ca (patch) | |
tree | f2a4b5cffc72e33c902b67083bbaa35b6f22f0ca /server/tests/utils/login.js | |
parent | b0f9f39ed70299a208d1b388c72de8b7f3510cb7 (diff) | |
download | PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.gz PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.zst PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.zip |
Convert tests to typescript
Diffstat (limited to 'server/tests/utils/login.js')
-rw-r--r-- | server/tests/utils/login.js | 57 |
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 | |||
3 | const request = require('supertest') | ||
4 | |||
5 | const loginUtils = { | ||
6 | login, | ||
7 | loginAndGetAccessToken, | ||
8 | getUserAccessToken | ||
9 | } | ||
10 | |||
11 | // ---------------------- Export functions -------------------- | ||
12 | |||
13 | function 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 | |||
39 | function 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 | |||
47 | function 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 | |||
57 | module.exports = loginUtils | ||