diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/utils.js | 21 | ||||
-rw-r--r-- | server/tests/real-world/tools/get-access-token.js | 44 | ||||
-rw-r--r-- | server/tests/real-world/tools/upload-directory.js | 67 | ||||
-rw-r--r-- | server/tests/real-world/tools/upload.js | 57 |
4 files changed, 188 insertions, 1 deletions
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js index 314269b5c..3cc769f26 100644 --- a/server/tests/api/utils.js +++ b/server/tests/api/utils.js | |||
@@ -11,6 +11,7 @@ const testUtils = { | |||
11 | dateIsValid: dateIsValid, | 11 | dateIsValid: dateIsValid, |
12 | flushTests: flushTests, | 12 | flushTests: flushTests, |
13 | getAllVideosListBy: getAllVideosListBy, | 13 | getAllVideosListBy: getAllVideosListBy, |
14 | getClient: getClient, | ||
14 | getFriendsList: getFriendsList, | 15 | getFriendsList: getFriendsList, |
15 | getVideo: getVideo, | 16 | getVideo: getVideo, |
16 | getVideosList: getVideosList, | 17 | getVideosList: getVideosList, |
@@ -60,6 +61,17 @@ function getAllVideosListBy (url, end) { | |||
60 | .end(end) | 61 | .end(end) |
61 | } | 62 | } |
62 | 63 | ||
64 | function getClient (url, end) { | ||
65 | const path = '/api/v1/users/client' | ||
66 | |||
67 | request(url) | ||
68 | .get(path) | ||
69 | .set('Accept', 'application/json') | ||
70 | .expect(200) | ||
71 | .expect('Content-Type', /json/) | ||
72 | .end(end) | ||
73 | } | ||
74 | |||
63 | function getFriendsList (url, end) { | 75 | function getFriendsList (url, end) { |
64 | const path = '/api/v1/pods/' | 76 | const path = '/api/v1/pods/' |
65 | 77 | ||
@@ -390,7 +402,14 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia | |||
390 | req.field('tags[' + i + ']', tags[i]) | 402 | req.field('tags[' + i + ']', tags[i]) |
391 | } | 403 | } |
392 | 404 | ||
393 | req.attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture)) | 405 | let filepath = '' |
406 | if (pathUtils.isAbsolute(fixture)) { | ||
407 | filepath = fixture | ||
408 | } else { | ||
409 | filepath = pathUtils.join(__dirname, 'fixtures', fixture) | ||
410 | } | ||
411 | |||
412 | req.attach('videofile', filepath) | ||
394 | .expect(specialStatus) | 413 | .expect(specialStatus) |
395 | .end(end) | 414 | .end(end) |
396 | } | 415 | } |
diff --git a/server/tests/real-world/tools/get-access-token.js b/server/tests/real-world/tools/get-access-token.js new file mode 100644 index 000000000..4f98e9c9f --- /dev/null +++ b/server/tests/real-world/tools/get-access-token.js | |||
@@ -0,0 +1,44 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const program = require('commander') | ||
4 | |||
5 | const utils = require('../../api/utils') | ||
6 | |||
7 | program | ||
8 | .option('-u, --url <url>', 'Server url') | ||
9 | .option('-n, --username <username>', 'Username') | ||
10 | .option('-p, --password <token>', 'Password') | ||
11 | .parse(process.argv) | ||
12 | |||
13 | if ( | ||
14 | !program.url || | ||
15 | !program.username || | ||
16 | !program.password | ||
17 | ) { | ||
18 | throw new Error('All arguments are required.') | ||
19 | } | ||
20 | |||
21 | const server = { | ||
22 | url: program.url, | ||
23 | user: { | ||
24 | username: program.username, | ||
25 | password: program.password | ||
26 | }, | ||
27 | client: { | ||
28 | id: null, | ||
29 | secret: null | ||
30 | } | ||
31 | } | ||
32 | |||
33 | utils.getClient(program.url, function (err, res) { | ||
34 | if (err) throw err | ||
35 | |||
36 | server.client.id = res.body.client_id | ||
37 | server.client.secret = res.body.client_secret | ||
38 | |||
39 | utils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
40 | if (err) throw err | ||
41 | |||
42 | console.log(accessToken) | ||
43 | }) | ||
44 | }) | ||
diff --git a/server/tests/real-world/tools/upload-directory.js b/server/tests/real-world/tools/upload-directory.js new file mode 100644 index 000000000..aed7a1fd8 --- /dev/null +++ b/server/tests/real-world/tools/upload-directory.js | |||
@@ -0,0 +1,67 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const program = require('commander') | ||
4 | const eachSeries = require('async/eachSeries') | ||
5 | const exec = require('child_process').exec | ||
6 | const fs = require('fs') | ||
7 | const path = require('path') | ||
8 | |||
9 | program | ||
10 | .option('-u, --url <url>', 'Server url') | ||
11 | .option('-n, --username <username>', 'Username') | ||
12 | .option('-p, --password <token>', 'Password') | ||
13 | .option('-i, --directory <directory>', 'Videos directory absolute path') | ||
14 | .option('-d, --description <description>', 'Video description') | ||
15 | .option('-t, --tags <tags>', 'Video tags', list) | ||
16 | .parse(process.argv) | ||
17 | |||
18 | if ( | ||
19 | !program.url || | ||
20 | !program.username || | ||
21 | !program.password || | ||
22 | !program.directory || | ||
23 | !program.description || | ||
24 | !program.tags | ||
25 | ) { | ||
26 | throw new Error('All arguments are required.') | ||
27 | } | ||
28 | |||
29 | exec('node ./get-access-token -u "' + program.url + '" -n "' + program.username + '" -p "' + program.password + '"', function (err, stdout) { | ||
30 | if (err) throw err | ||
31 | |||
32 | const accessToken = stdout.replace('\n', '') | ||
33 | |||
34 | fs.readdir(program.directory, function (err, files) { | ||
35 | if (err) throw err | ||
36 | |||
37 | eachSeries(files, function (file, callbackEach) { | ||
38 | const video = { | ||
39 | tags: program.tags, | ||
40 | name: file, | ||
41 | description: program.description | ||
42 | } | ||
43 | |||
44 | let command = 'node ./upload' | ||
45 | command += ' -u "' + program.url + '"' | ||
46 | command += ' -a "' + accessToken + '"' | ||
47 | command += ' -n "' + video.name + '"' | ||
48 | command += ' -d "' + video.description + '"' | ||
49 | command += ' -t "' + video.tags.join(',') + '"' | ||
50 | command += ' -f "' + path.join(program.directory, file) + '"' | ||
51 | |||
52 | exec(command, function (err, stdout) { | ||
53 | if (err) console.log(err) | ||
54 | |||
55 | console.log(stdout) | ||
56 | |||
57 | return callbackEach() | ||
58 | }) | ||
59 | }) | ||
60 | }) | ||
61 | }) | ||
62 | |||
63 | // ---------------------------------------------------------------------------- | ||
64 | |||
65 | function list (val) { | ||
66 | return val.split(',') | ||
67 | } | ||
diff --git a/server/tests/real-world/tools/upload.js b/server/tests/real-world/tools/upload.js new file mode 100644 index 000000000..39b4c9b40 --- /dev/null +++ b/server/tests/real-world/tools/upload.js | |||
@@ -0,0 +1,57 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const program = require('commander') | ||
4 | const fs = require('fs') | ||
5 | |||
6 | const utils = require('../../api/utils') | ||
7 | |||
8 | program | ||
9 | .option('-u, --url <url>', 'Server url') | ||
10 | .option('-a, --access-token <token>', 'Access token') | ||
11 | .option('-n, --name <name>', 'Video name') | ||
12 | .option('-d, --description <description>', 'Video description') | ||
13 | .option('-t, --tags <tags>', 'Video tags', list) | ||
14 | .option('-f, --file <file>', 'Video absolute file path') | ||
15 | .parse(process.argv) | ||
16 | |||
17 | if ( | ||
18 | !program.url || | ||
19 | !program.accessToken || | ||
20 | !program.name || | ||
21 | !program.description || | ||
22 | !program.tags || | ||
23 | !Array.isArray(program.tags) || | ||
24 | program.tags.length === 0 || | ||
25 | !program.file | ||
26 | ) { | ||
27 | throw new Error('All arguments are required.') | ||
28 | } | ||
29 | |||
30 | fs.access(program.file, fs.F_OK, function (err) { | ||
31 | if (err) throw err | ||
32 | |||
33 | upload( | ||
34 | program.url, | ||
35 | program.accessToken, | ||
36 | program.name, | ||
37 | program.description, | ||
38 | program.tags, | ||
39 | program.file | ||
40 | ) | ||
41 | }) | ||
42 | |||
43 | // ---------------------------------------------------------------------------- | ||
44 | |||
45 | function list (val) { | ||
46 | return val.split(',') | ||
47 | } | ||
48 | |||
49 | function upload (url, accessToken, name, description, tags, file) { | ||
50 | console.log('Uploading %s video...', program.name) | ||
51 | |||
52 | utils.uploadVideo(url, accessToken, name, description, tags, file, function (err) { | ||
53 | if (err) throw err | ||
54 | |||
55 | console.log('Video uploaded.') | ||
56 | }) | ||
57 | } | ||