diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-09-07 15:27:35 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-09-07 15:54:34 +0200 |
commit | fdbda9e3d6564ec908733c7019305f6a3c363a9f (patch) | |
tree | c596034156f167e7cfafe41c4a3fc6adda488a0d /server | |
parent | 04de542abd940f9d2ca213fba3c68580c6c9b78a (diff) | |
download | PeerTube-fdbda9e3d6564ec908733c7019305f6a3c363a9f.tar.gz PeerTube-fdbda9e3d6564ec908733c7019305f6a3c363a9f.tar.zst PeerTube-fdbda9e3d6564ec908733c7019305f6a3c363a9f.zip |
Add tests for npm run scripts
Diffstat (limited to 'server')
22 files changed, 212 insertions, 32 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index f8dd45533..2ec7e6515 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts | |||
@@ -25,8 +25,15 @@ function isTestInstance () { | |||
25 | } | 25 | } |
26 | 26 | ||
27 | function root () { | 27 | function root () { |
28 | // We are in /dist/helpers/utils.js | 28 | // We are in /helpers/utils.js |
29 | return join(__dirname, '..', '..', '..') | 29 | const paths = [ __dirname, '..', '..' ] |
30 | |||
31 | // We are under /dist directory | ||
32 | if (process.mainModule.filename.endsWith('.ts') === false) { | ||
33 | paths.push('..') | ||
34 | } | ||
35 | |||
36 | return join.apply(null, paths) | ||
30 | } | 37 | } |
31 | 38 | ||
32 | function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { | 39 | function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { |
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index f6bb02c8e..8d215a416 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -1,3 +1,5 @@ | |||
1 | import 'express-validator' | ||
2 | |||
1 | function exists (value: any) { | 3 | function exists (value: any) { |
2 | return value !== undefined && value !== null | 4 | return value !== undefined && value !== null |
3 | } | 5 | } |
diff --git a/server/helpers/custom-validators/pods.ts b/server/helpers/custom-validators/pods.ts index f2ca520c0..844bfdf78 100644 --- a/server/helpers/custom-validators/pods.ts +++ b/server/helpers/custom-validators/pods.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import 'express-validator' | ||
2 | 3 | ||
3 | import { isArray, exists } from './misc' | 4 | import { isArray, exists } from './misc' |
4 | import { isTestInstance } from '../core-utils' | 5 | import { isTestInstance } from '../core-utils' |
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts index 49f76e909..e5c76f3ca 100644 --- a/server/helpers/custom-validators/remote/videos.ts +++ b/server/helpers/custom-validators/remote/videos.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import 'express-validator' | ||
1 | import { has, values } from 'lodash' | 2 | import { has, values } from 'lodash' |
2 | 3 | ||
3 | import { | 4 | import { |
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 00061f9df..805437efa 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import 'express-validator' | ||
3 | 4 | ||
4 | import { exists } from './misc' | 5 | import { exists } from './misc' |
5 | import { CONSTRAINTS_FIELDS, USER_ROLES } from '../../initializers' | 6 | import { CONSTRAINTS_FIELDS, USER_ROLES } from '../../initializers' |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 8b3a26644..1d27e47fc 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import 'express-validator' | ||
3 | import 'multer' | 4 | import 'multer' |
4 | 5 | ||
5 | import { | 6 | import { |
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index d04c8db1b..d59fd3655 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -8,26 +8,25 @@ import { CONFIG } from './constants' | |||
8 | // Do not use barrel, we need to load database first | 8 | // Do not use barrel, we need to load database first |
9 | import { logger } from '../helpers/logger' | 9 | import { logger } from '../helpers/logger' |
10 | import { isTestInstance, readdirPromise } from '../helpers/core-utils' | 10 | import { isTestInstance, readdirPromise } from '../helpers/core-utils' |
11 | import { | 11 | |
12 | ApplicationModel, | 12 | import { VideoModel } from './../models/video/video-interface' |
13 | AuthorModel, | 13 | import { VideoTagModel } from './../models/video/video-tag-interface' |
14 | JobModel, | 14 | import { BlacklistedVideoModel } from './../models/video/video-blacklist-interface' |
15 | OAuthClientModel, | 15 | import { VideoFileModel } from './../models/video/video-file-interface' |
16 | OAuthTokenModel, | 16 | import { VideoAbuseModel } from './../models/video/video-abuse-interface' |
17 | PodModel, | 17 | import { UserModel } from './../models/user/user-interface' |
18 | RequestModel, | 18 | import { UserVideoRateModel } from './../models/user/user-video-rate-interface' |
19 | RequestToPodModel, | 19 | import { TagModel } from './../models/video/tag-interface' |
20 | RequestVideoEventModel, | 20 | import { RequestModel } from './../models/request/request-interface' |
21 | RequestVideoQaduModel, | 21 | import { RequestVideoQaduModel } from './../models/request/request-video-qadu-interface' |
22 | TagModel, | 22 | import { RequestVideoEventModel } from './../models/request/request-video-event-interface' |
23 | UserModel, | 23 | import { RequestToPodModel } from './../models/request/request-to-pod-interface' |
24 | UserVideoRateModel, | 24 | import { PodModel } from './../models/pod/pod-interface' |
25 | VideoAbuseModel, | 25 | import { OAuthTokenModel } from './../models/oauth/oauth-token-interface' |
26 | BlacklistedVideoModel, | 26 | import { OAuthClientModel } from './../models/oauth/oauth-client-interface' |
27 | VideoFileModel, | 27 | import { JobModel } from './../models/job/job-interface' |
28 | VideoTagModel, | 28 | import { AuthorModel } from './../models/video/author-interface' |
29 | VideoModel | 29 | import { ApplicationModel } from './../models/application/application-interface' |
30 | } from '../models' | ||
31 | 30 | ||
32 | const dbname = CONFIG.DATABASE.DBNAME | 31 | const dbname = CONFIG.DATABASE.DBNAME |
33 | const username = CONFIG.DATABASE.USERNAME | 32 | const username = CONFIG.DATABASE.USERNAME |
diff --git a/server/models/oauth/oauth-token-interface.ts b/server/models/oauth/oauth-token-interface.ts index 97af3c815..0c947bde8 100644 --- a/server/models/oauth/oauth-token-interface.ts +++ b/server/models/oauth/oauth-token-interface.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { UserModel } from '../user' | 4 | import { UserModel } from '../user/user-interface' |
5 | 5 | ||
6 | export type OAuthTokenInfo = { | 6 | export type OAuthTokenInfo = { |
7 | refreshToken: string | 7 | refreshToken: string |
diff --git a/server/models/request/request-interface.ts b/server/models/request/request-interface.ts index 7b0ee4df9..dae35651b 100644 --- a/server/models/request/request-interface.ts +++ b/server/models/request/request-interface.ts | |||
@@ -2,7 +2,7 @@ import * as Sequelize from 'sequelize' | |||
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { AbstractRequestClass } from './abstract-request-interface' | 4 | import { AbstractRequestClass } from './abstract-request-interface' |
5 | import { PodInstance, PodAttributes } from '../pod' | 5 | import { PodInstance, PodAttributes } from '../pod/pod-interface' |
6 | import { RequestEndpoint } from '../../../shared/models/request-scheduler.model' | 6 | import { RequestEndpoint } from '../../../shared/models/request-scheduler.model' |
7 | 7 | ||
8 | export type RequestsGrouped = { | 8 | export type RequestsGrouped = { |
diff --git a/server/models/request/request-video-event-interface.ts b/server/models/request/request-video-event-interface.ts index a5032e1b1..26cabe3ba 100644 --- a/server/models/request/request-video-event-interface.ts +++ b/server/models/request/request-video-event-interface.ts | |||
@@ -2,8 +2,8 @@ import * as Sequelize from 'sequelize' | |||
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { AbstractRequestClass, AbstractRequestToPodClass } from './abstract-request-interface' | 4 | import { AbstractRequestClass, AbstractRequestToPodClass } from './abstract-request-interface' |
5 | import { VideoInstance } from '../video' | 5 | import { VideoInstance } from '../video/video-interface' |
6 | import { PodInstance } from '../pod' | 6 | import { PodInstance } from '../pod/pod-interface' |
7 | 7 | ||
8 | import { RequestVideoEventType } from '../../../shared/models/request-scheduler.model' | 8 | import { RequestVideoEventType } from '../../../shared/models/request-scheduler.model' |
9 | 9 | ||
diff --git a/server/models/request/request-video-qadu-interface.ts b/server/models/request/request-video-qadu-interface.ts index 9a172a4d4..b7b7b1ecc 100644 --- a/server/models/request/request-video-qadu-interface.ts +++ b/server/models/request/request-video-qadu-interface.ts | |||
@@ -2,8 +2,8 @@ import * as Sequelize from 'sequelize' | |||
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { AbstractRequestClass, AbstractRequestToPodClass } from './abstract-request-interface' | 4 | import { AbstractRequestClass, AbstractRequestToPodClass } from './abstract-request-interface' |
5 | import { VideoInstance } from '../video' | 5 | import { VideoInstance } from '../video/video-interface' |
6 | import { PodInstance } from '../pod' | 6 | import { PodInstance } from '../pod/pod-interface' |
7 | 7 | ||
8 | import { RequestVideoQaduType } from '../../../shared/models/request-scheduler.model' | 8 | import { RequestVideoQaduType } from '../../../shared/models/request-scheduler.model' |
9 | 9 | ||
diff --git a/server/models/video/author-interface.ts b/server/models/video/author-interface.ts index dbcb85b17..52a00a1d3 100644 --- a/server/models/video/author-interface.ts +++ b/server/models/video/author-interface.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { PodInstance } from '../pod' | 4 | import { PodInstance } from '../pod/pod-interface' |
5 | 5 | ||
6 | export namespace AuthorMethods { | 6 | export namespace AuthorMethods { |
7 | export type FindOrCreateAuthor = ( | 7 | export type FindOrCreateAuthor = ( |
diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts index abc82f7ac..978268926 100644 --- a/server/models/video/video-abuse-interface.ts +++ b/server/models/video/video-abuse-interface.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { PodInstance } from '../pod' | 4 | import { PodInstance } from '../pod/pod-interface' |
5 | import { ResultList } from '../../../shared' | 5 | import { ResultList } from '../../../shared' |
6 | 6 | ||
7 | // Don't use barrel, import just what we need | 7 | // Don't use barrel, import just what we need |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 8c69fe189..1134525f0 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -378,6 +378,8 @@ createTorrentAndSetInfoHash = function (this: VideoInstance, videoFile: VideoFil | |||
378 | return createTorrentPromise(this.getVideoFilePath(videoFile), options) | 378 | return createTorrentPromise(this.getVideoFilePath(videoFile), options) |
379 | .then(torrent => { | 379 | .then(torrent => { |
380 | const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) | 380 | const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) |
381 | logger.info('Creating torrent %s.', filePath) | ||
382 | |||
381 | return writeFilePromise(filePath, torrent).then(() => torrent) | 383 | return writeFilePromise(filePath, torrent).then(() => torrent) |
382 | }) | 384 | }) |
383 | .then(torrent => { | 385 | .then(torrent => { |
diff --git a/server/tests/cli/index.ts b/server/tests/cli/index.ts new file mode 100644 index 000000000..e5a19ff10 --- /dev/null +++ b/server/tests/cli/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | // Order of the tests we want to execute | ||
2 | import './reset-password' | ||
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts new file mode 100644 index 000000000..bbf0b3d11 --- /dev/null +++ b/server/tests/cli/reset-password.ts | |||
@@ -0,0 +1,45 @@ | |||
1 | import 'mocha' | ||
2 | |||
3 | import { | ||
4 | createUser, | ||
5 | execCLI, | ||
6 | flushTests, | ||
7 | getEnvCli, | ||
8 | killallServers, | ||
9 | login, | ||
10 | runServer, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers | ||
13 | } from '../utils' | ||
14 | |||
15 | describe('Test reset password scripts', function () { | ||
16 | let server: ServerInfo | ||
17 | |||
18 | before(async function () { | ||
19 | this.timeout(30000) | ||
20 | |||
21 | await flushTests() | ||
22 | server = await runServer(1) | ||
23 | await setAccessTokensToServers([ server ]) | ||
24 | |||
25 | await createUser(server.url, server.accessToken, 'user_1', 'super password') | ||
26 | }) | ||
27 | |||
28 | it('Should change the user password from CLI', async function () { | ||
29 | this.timeout(20000) | ||
30 | |||
31 | const env = getEnvCli(server) | ||
32 | await execCLI(`echo coucou | ${env} npm run reset-password -- -u user_1`) | ||
33 | |||
34 | await login(server.url, server.client, { username: 'user_1', password: 'coucou' }, 200) | ||
35 | }) | ||
36 | |||
37 | after(async function () { | ||
38 | killallServers([ server ]) | ||
39 | |||
40 | // Keep the logs if the test failed | ||
41 | if (this['ok']) { | ||
42 | await flushTests() | ||
43 | } | ||
44 | }) | ||
45 | }) | ||
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts new file mode 100644 index 000000000..af9703b32 --- /dev/null +++ b/server/tests/cli/update-host.ts | |||
@@ -0,0 +1,71 @@ | |||
1 | import 'mocha' | ||
2 | import * as chai from 'chai' | ||
3 | const expect = chai.expect | ||
4 | |||
5 | import { | ||
6 | execCLI, | ||
7 | flushTests, | ||
8 | getEnvCli, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | parseTorrentVideo, | ||
12 | runServer, | ||
13 | ServerInfo, | ||
14 | setAccessTokensToServers, | ||
15 | uploadVideo | ||
16 | } from '../utils' | ||
17 | |||
18 | describe('Test update host scripts', function () { | ||
19 | let server: ServerInfo | ||
20 | |||
21 | before(async function () { | ||
22 | this.timeout(30000) | ||
23 | |||
24 | await flushTests() | ||
25 | |||
26 | const overrideConfig = { | ||
27 | webserver: { | ||
28 | port: 9256 | ||
29 | } | ||
30 | } | ||
31 | server = await runServer(1, overrideConfig) | ||
32 | await setAccessTokensToServers([ server ]) | ||
33 | |||
34 | // Upload two videos for our needs | ||
35 | const videoAttributes = {} | ||
36 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
37 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
38 | }) | ||
39 | |||
40 | it('Should update torrent hosts', async function () { | ||
41 | this.timeout(20000) | ||
42 | |||
43 | killallServers([ server ]) | ||
44 | server = await runServer(1) | ||
45 | |||
46 | const env = getEnvCli(server) | ||
47 | await execCLI(`${env} npm run update-host`) | ||
48 | |||
49 | const res = await getVideosList(server.url) | ||
50 | const videos = res.body.data | ||
51 | |||
52 | expect(videos[0].files[0].magnetUri).to.contain('localhost%3A9001%2Ftracker%2Fsocket') | ||
53 | expect(videos[0].files[0].magnetUri).to.contain('localhost%3A9001%2Fstatic%2Fwebseed%2F') | ||
54 | |||
55 | expect(videos[1].files[0].magnetUri).to.contain('localhost%3A9001%2Ftracker%2Fsocket') | ||
56 | expect(videos[1].files[0].magnetUri).to.contain('localhost%3A9001%2Fstatic%2Fwebseed%2F') | ||
57 | |||
58 | const torrent = await parseTorrentVideo(server, videos[0].uuid) | ||
59 | expect(torrent.announce[0]).to.equal('ws://localhost:9001/tracker/socket') | ||
60 | expect(torrent.urlList[0]).to.contain('http://localhost:9001/static/webseed') | ||
61 | }) | ||
62 | |||
63 | after(async function () { | ||
64 | killallServers([ server ]) | ||
65 | |||
66 | // Keep the logs if the test failed | ||
67 | if (this['ok']) { | ||
68 | await flushTests() | ||
69 | } | ||
70 | }) | ||
71 | }) | ||
diff --git a/server/tests/index.ts b/server/tests/index.ts index 26f0816b7..a7dd0d824 100644 --- a/server/tests/index.ts +++ b/server/tests/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | // Order of the tests we want to execute | 1 | // Order of the tests we want to execute |
2 | import './client' | 2 | import './client' |
3 | import './api/' | 3 | import './api/' |
4 | import './cli/' | ||
diff --git a/server/tests/utils/cli.ts b/server/tests/utils/cli.ts new file mode 100644 index 000000000..5f07a832e --- /dev/null +++ b/server/tests/utils/cli.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { exec } from 'child_process' | ||
2 | |||
3 | import { ServerInfo } from './servers' | ||
4 | |||
5 | function getEnvCli (server?: ServerInfo) { | ||
6 | return `NODE_ENV=test NODE_APP_INSTANCE=${server.serverNumber}` | ||
7 | } | ||
8 | |||
9 | async function execCLI (command: string) { | ||
10 | return new Promise((res, rej) => { | ||
11 | exec(command, (err, stdout, stderr) => { | ||
12 | if (err) return rej(err) | ||
13 | |||
14 | return res(stdout) | ||
15 | }) | ||
16 | }) | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | execCLI, | ||
23 | getEnvCli | ||
24 | } | ||
diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 9077b0568..0fa28f2af 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './cli' | ||
1 | export * from './clients' | 2 | export * from './clients' |
2 | export * from './config' | 3 | export * from './config' |
3 | export * from './login' | 4 | export * from './login' |
diff --git a/server/tests/utils/servers.ts b/server/tests/utils/servers.ts index 272a8935e..88027f74e 100644 --- a/server/tests/utils/servers.ts +++ b/server/tests/utils/servers.ts | |||
@@ -5,6 +5,7 @@ interface ServerInfo { | |||
5 | app: ChildProcess, | 5 | app: ChildProcess, |
6 | url: string | 6 | url: string |
7 | host: string | 7 | host: string |
8 | serverNumber: number | ||
8 | 9 | ||
9 | client: { | 10 | client: { |
10 | id: string, | 11 | id: string, |
@@ -65,9 +66,10 @@ function flushTests () { | |||
65 | }) | 66 | }) |
66 | } | 67 | } |
67 | 68 | ||
68 | function runServer (serverNumber: number) { | 69 | function runServer (serverNumber: number, configOverride?: Object) { |
69 | const server: ServerInfo = { | 70 | const server: ServerInfo = { |
70 | app: null, | 71 | app: null, |
72 | serverNumber: serverNumber, | ||
71 | url: `http://localhost:${9000 + serverNumber}`, | 73 | url: `http://localhost:${9000 + serverNumber}`, |
72 | host: `localhost:${9000 + serverNumber}`, | 74 | host: `localhost:${9000 + serverNumber}`, |
73 | client: { | 75 | client: { |
@@ -98,6 +100,11 @@ function runServer (serverNumber: number) { | |||
98 | const env = Object.create(process.env) | 100 | const env = Object.create(process.env) |
99 | env['NODE_ENV'] = 'test' | 101 | env['NODE_ENV'] = 'test' |
100 | env['NODE_APP_INSTANCE'] = serverNumber.toString() | 102 | env['NODE_APP_INSTANCE'] = serverNumber.toString() |
103 | |||
104 | if (configOverride !== undefined) { | ||
105 | env['NODE_CONFIG'] = JSON.stringify(configOverride) | ||
106 | } | ||
107 | |||
101 | const options = { | 108 | const options = { |
102 | silent: true, | 109 | silent: true, |
103 | env: env, | 110 | env: env, |
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 42b7dd05a..509a2430a 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts | |||
@@ -1,8 +1,11 @@ | |||
1 | import { readFile } from 'fs' | ||
1 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
2 | import { join, isAbsolute } from 'path' | 3 | import { join, isAbsolute } from 'path' |
4 | import * as parseTorrent from 'parse-torrent' | ||
3 | 5 | ||
4 | import { makeGetRequest } from './requests' | 6 | import { makeGetRequest } from './requests' |
5 | import { readFilePromise } from './miscs' | 7 | import { readFilePromise } from './miscs' |
8 | import { ServerInfo } from './servers' | ||
6 | 9 | ||
7 | type VideoAttributes = { | 10 | type VideoAttributes = { |
8 | name?: string | 11 | name?: string |
@@ -232,6 +235,17 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string | |||
232 | .expect(specialStatus) | 235 | .expect(specialStatus) |
233 | } | 236 | } |
234 | 237 | ||
238 | function parseTorrentVideo (server: ServerInfo, videoUUID: string) { | ||
239 | return new Promise<any>((res, rej) => { | ||
240 | const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', videoUUID + '.torrent') | ||
241 | readFile(torrentPath, (err, data) => { | ||
242 | if (err) return rej(err) | ||
243 | |||
244 | return res(parseTorrent(data)) | ||
245 | }) | ||
246 | }) | ||
247 | } | ||
248 | |||
235 | // --------------------------------------------------------------------------- | 249 | // --------------------------------------------------------------------------- |
236 | 250 | ||
237 | export { | 251 | export { |
@@ -250,5 +264,6 @@ export { | |||
250 | testVideoImage, | 264 | testVideoImage, |
251 | uploadVideo, | 265 | uploadVideo, |
252 | updateVideo, | 266 | updateVideo, |
253 | rateVideo | 267 | rateVideo, |
268 | parseTorrentVideo | ||
254 | } | 269 | } |