diff options
-rw-r--r-- | scripts/benchmark.ts | 5 | ||||
-rw-r--r-- | server/tests/api/check-params/video-captions.ts | 11 | ||||
-rw-r--r-- | server/tests/api/search/search-videos.ts | 9 | ||||
-rw-r--r-- | server/tests/api/server/follows.ts | 16 | ||||
-rw-r--r-- | server/tests/api/videos/video-captions.ts | 77 | ||||
-rw-r--r-- | server/tests/api/videos/video-imports.ts | 33 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/videos/captions-command.ts | 66 | ||||
-rw-r--r-- | shared/extra-utils/videos/captions.ts | 17 | ||||
-rw-r--r-- | shared/extra-utils/videos/index.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-captions.ts | 72 |
11 files changed, 149 insertions, 164 deletions
diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts index 0cadb36d9..fcfc67bf7 100644 --- a/scripts/benchmark.ts +++ b/scripts/benchmark.ts | |||
@@ -5,7 +5,6 @@ import * as autocannon from 'autocannon' | |||
5 | import { | 5 | import { |
6 | addVideoCommentReply, | 6 | addVideoCommentReply, |
7 | addVideoCommentThread, | 7 | addVideoCommentThread, |
8 | createVideoCaption, | ||
9 | flushAndRunServer, | 8 | flushAndRunServer, |
10 | getVideosList, | 9 | getVideosList, |
11 | killallServers, | 10 | killallServers, |
@@ -244,9 +243,7 @@ async function prepare () { | |||
244 | } | 243 | } |
245 | 244 | ||
246 | for (const caption of [ 'ar', 'fr', 'en', 'zh' ]) { | 245 | for (const caption of [ 'ar', 'fr', 'en', 'zh' ]) { |
247 | await createVideoCaption({ | 246 | await server.captionsCommand.createVideoCaption({ |
248 | url: server.url, | ||
249 | accessToken: server.accessToken, | ||
250 | language: caption, | 247 | language: caption, |
251 | videoId: video.id, | 248 | videoId: video.id, |
252 | fixture: 'subtitle-good2.vtt' | 249 | fixture: 'subtitle-good2.vtt' |
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index c0595c04d..baab0f276 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { VideoCreateResult } from '@shared/models' | 4 | import { HttpStatusCode } from '@shared/core-utils' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
6 | import { | 5 | import { |
7 | buildAbsoluteFixturePath, | 6 | buildAbsoluteFixturePath, |
8 | cleanupTests, | 7 | cleanupTests, |
@@ -15,8 +14,8 @@ import { | |||
15 | setAccessTokensToServers, | 14 | setAccessTokensToServers, |
16 | uploadVideo, | 15 | uploadVideo, |
17 | userLogin | 16 | userLogin |
18 | } from '../../../../shared/extra-utils' | 17 | } from '@shared/extra-utils' |
19 | import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' | 18 | import { VideoCreateResult } from '@shared/models' |
20 | 19 | ||
21 | describe('Test video captions API validator', function () { | 20 | describe('Test video captions API validator', function () { |
22 | const path = '/api/v1/videos/' | 21 | const path = '/api/v1/videos/' |
@@ -159,9 +158,7 @@ describe('Test video captions API validator', function () { | |||
159 | // }) | 158 | // }) |
160 | 159 | ||
161 | it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { | 160 | it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { |
162 | await createVideoCaption({ | 161 | await server.captionsCommand.createVideoCaption({ |
163 | url: server.url, | ||
164 | accessToken: server.accessToken, | ||
165 | language: 'zh', | 162 | language: 'zh', |
166 | videoId: video.uuid, | 163 | videoId: video.uuid, |
167 | fixture: 'subtitle-good.srt', | 164 | fixture: 'subtitle-good.srt', |
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index a0375fbf0..513538917 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts | |||
@@ -4,7 +4,6 @@ import 'mocha' | |||
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | createVideoCaption, | ||
8 | flushAndRunServer, | 7 | flushAndRunServer, |
9 | immutableAssign, | 8 | immutableAssign, |
10 | SearchCommand, | 9 | SearchCommand, |
@@ -54,18 +53,14 @@ describe('Test videos search', function () { | |||
54 | const videoId = res.body.video.id | 53 | const videoId = res.body.video.id |
55 | videoUUID = res.body.video.uuid | 54 | videoUUID = res.body.video.uuid |
56 | 55 | ||
57 | await createVideoCaption({ | 56 | await server.captionsCommand.createVideoCaption({ |
58 | url: server.url, | ||
59 | accessToken: server.accessToken, | ||
60 | language: 'en', | 57 | language: 'en', |
61 | videoId, | 58 | videoId, |
62 | fixture: 'subtitle-good2.vtt', | 59 | fixture: 'subtitle-good2.vtt', |
63 | mimeType: 'application/octet-stream' | 60 | mimeType: 'application/octet-stream' |
64 | }) | 61 | }) |
65 | 62 | ||
66 | await createVideoCaption({ | 63 | await server.captionsCommand.createVideoCaption({ |
67 | url: server.url, | ||
68 | accessToken: server.accessToken, | ||
69 | language: 'aa', | 64 | language: 'aa', |
70 | videoId, | 65 | videoId, |
71 | fixture: 'subtitle-good2.vtt', | 66 | fixture: 'subtitle-good2.vtt', |
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 466932d63..520442c6e 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts | |||
@@ -8,7 +8,6 @@ import { | |||
8 | cleanupTests, | 8 | cleanupTests, |
9 | completeVideoCheck, | 9 | completeVideoCheck, |
10 | createUser, | 10 | createUser, |
11 | createVideoCaption, | ||
12 | dateIsValid, | 11 | dateIsValid, |
13 | deleteVideoComment, | 12 | deleteVideoComment, |
14 | expectAccountFollows, | 13 | expectAccountFollows, |
@@ -17,7 +16,6 @@ import { | |||
17 | getVideoCommentThreads, | 16 | getVideoCommentThreads, |
18 | getVideosList, | 17 | getVideosList, |
19 | getVideoThreadComments, | 18 | getVideoThreadComments, |
20 | listVideoCaptions, | ||
21 | rateVideo, | 19 | rateVideo, |
22 | ServerInfo, | 20 | ServerInfo, |
23 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
@@ -26,7 +24,7 @@ import { | |||
26 | userLogin, | 24 | userLogin, |
27 | waitJobs | 25 | waitJobs |
28 | } from '@shared/extra-utils' | 26 | } from '@shared/extra-utils' |
29 | import { Video, VideoCaption, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' | 27 | import { Video, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' |
30 | 28 | ||
31 | const expect = chai.expect | 29 | const expect = chai.expect |
32 | 30 | ||
@@ -385,9 +383,7 @@ describe('Test follows', function () { | |||
385 | } | 383 | } |
386 | 384 | ||
387 | { | 385 | { |
388 | await createVideoCaption({ | 386 | await servers[2].captionsCommand.createVideoCaption({ |
389 | url: servers[2].url, | ||
390 | accessToken: servers[2].accessToken, | ||
391 | language: 'ar', | 387 | language: 'ar', |
392 | videoId: video4.id, | 388 | videoId: video4.id, |
393 | fixture: 'subtitle-good2.vtt' | 389 | fixture: 'subtitle-good2.vtt' |
@@ -543,11 +539,11 @@ describe('Test follows', function () { | |||
543 | }) | 539 | }) |
544 | 540 | ||
545 | it('Should have propagated captions', async function () { | 541 | it('Should have propagated captions', async function () { |
546 | const res = await listVideoCaptions(servers[0].url, video4.id) | 542 | const body = await servers[0].captionsCommand.listVideoCaptions({ videoId: video4.id }) |
547 | expect(res.body.total).to.equal(1) | 543 | expect(body.total).to.equal(1) |
548 | expect(res.body.data).to.have.lengthOf(1) | 544 | expect(body.data).to.have.lengthOf(1) |
549 | 545 | ||
550 | const caption1: VideoCaption = res.body.data[0] | 546 | const caption1 = body.data[0] |
551 | expect(caption1.language.id).to.equal('ar') | 547 | expect(caption1.language.id).to.equal('ar') |
552 | expect(caption1.language.label).to.equal('Arabic') | 548 | expect(caption1.language.label).to.equal('Arabic') |
553 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/.+-ar.vtt$')) | 549 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/.+-ar.vtt$')) |
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 14ecedfa6..83ee809b8 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts | |||
@@ -1,25 +1,20 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { | 5 | import { |
6 | checkVideoFilesWereRemoved, | 6 | checkVideoFilesWereRemoved, |
7 | cleanupTests, | 7 | cleanupTests, |
8 | doubleFollow, | 8 | doubleFollow, |
9 | flushAndRunMultipleServers, | 9 | flushAndRunMultipleServers, |
10 | removeVideo, | 10 | removeVideo, |
11 | ServerInfo, | ||
12 | setAccessTokensToServers, | ||
13 | testCaptionFile, | ||
11 | uploadVideo, | 14 | uploadVideo, |
12 | wait | 15 | wait, |
13 | } from '../../../../shared/extra-utils' | 16 | waitJobs |
14 | import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' | 17 | } from '@shared/extra-utils' |
15 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
16 | import { | ||
17 | createVideoCaption, | ||
18 | deleteVideoCaption, | ||
19 | listVideoCaptions, | ||
20 | testCaptionFile | ||
21 | } from '../../../../shared/extra-utils/videos/video-captions' | ||
22 | import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' | ||
23 | 18 | ||
24 | const expect = chai.expect | 19 | const expect = chai.expect |
25 | 20 | ||
@@ -47,26 +42,22 @@ describe('Test video captions', function () { | |||
47 | 42 | ||
48 | it('Should list the captions and return an empty list', async function () { | 43 | it('Should list the captions and return an empty list', async function () { |
49 | for (const server of servers) { | 44 | for (const server of servers) { |
50 | const res = await listVideoCaptions(server.url, videoUUID) | 45 | const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) |
51 | expect(res.body.total).to.equal(0) | 46 | expect(body.total).to.equal(0) |
52 | expect(res.body.data).to.have.lengthOf(0) | 47 | expect(body.data).to.have.lengthOf(0) |
53 | } | 48 | } |
54 | }) | 49 | }) |
55 | 50 | ||
56 | it('Should create two new captions', async function () { | 51 | it('Should create two new captions', async function () { |
57 | this.timeout(30000) | 52 | this.timeout(30000) |
58 | 53 | ||
59 | await createVideoCaption({ | 54 | await servers[0].captionsCommand.createVideoCaption({ |
60 | url: servers[0].url, | ||
61 | accessToken: servers[0].accessToken, | ||
62 | language: 'ar', | 55 | language: 'ar', |
63 | videoId: videoUUID, | 56 | videoId: videoUUID, |
64 | fixture: 'subtitle-good1.vtt' | 57 | fixture: 'subtitle-good1.vtt' |
65 | }) | 58 | }) |
66 | 59 | ||
67 | await createVideoCaption({ | 60 | await servers[0].captionsCommand.createVideoCaption({ |
68 | url: servers[0].url, | ||
69 | accessToken: servers[0].accessToken, | ||
70 | language: 'zh', | 61 | language: 'zh', |
71 | videoId: videoUUID, | 62 | videoId: videoUUID, |
72 | fixture: 'subtitle-good2.vtt', | 63 | fixture: 'subtitle-good2.vtt', |
@@ -78,17 +69,17 @@ describe('Test video captions', function () { | |||
78 | 69 | ||
79 | it('Should list these uploaded captions', async function () { | 70 | it('Should list these uploaded captions', async function () { |
80 | for (const server of servers) { | 71 | for (const server of servers) { |
81 | const res = await listVideoCaptions(server.url, videoUUID) | 72 | const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) |
82 | expect(res.body.total).to.equal(2) | 73 | expect(body.total).to.equal(2) |
83 | expect(res.body.data).to.have.lengthOf(2) | 74 | expect(body.data).to.have.lengthOf(2) |
84 | 75 | ||
85 | const caption1: VideoCaption = res.body.data[0] | 76 | const caption1 = body.data[0] |
86 | expect(caption1.language.id).to.equal('ar') | 77 | expect(caption1.language.id).to.equal('ar') |
87 | expect(caption1.language.label).to.equal('Arabic') | 78 | expect(caption1.language.label).to.equal('Arabic') |
88 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) | 79 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) |
89 | await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') | 80 | await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') |
90 | 81 | ||
91 | const caption2: VideoCaption = res.body.data[1] | 82 | const caption2 = body.data[1] |
92 | expect(caption2.language.id).to.equal('zh') | 83 | expect(caption2.language.id).to.equal('zh') |
93 | expect(caption2.language.label).to.equal('Chinese') | 84 | expect(caption2.language.label).to.equal('Chinese') |
94 | expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) | 85 | expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) |
@@ -99,9 +90,7 @@ describe('Test video captions', function () { | |||
99 | it('Should replace an existing caption', async function () { | 90 | it('Should replace an existing caption', async function () { |
100 | this.timeout(30000) | 91 | this.timeout(30000) |
101 | 92 | ||
102 | await createVideoCaption({ | 93 | await servers[0].captionsCommand.createVideoCaption({ |
103 | url: servers[0].url, | ||
104 | accessToken: servers[0].accessToken, | ||
105 | language: 'ar', | 94 | language: 'ar', |
106 | videoId: videoUUID, | 95 | videoId: videoUUID, |
107 | fixture: 'subtitle-good2.vtt' | 96 | fixture: 'subtitle-good2.vtt' |
@@ -112,11 +101,11 @@ describe('Test video captions', function () { | |||
112 | 101 | ||
113 | it('Should have this caption updated', async function () { | 102 | it('Should have this caption updated', async function () { |
114 | for (const server of servers) { | 103 | for (const server of servers) { |
115 | const res = await listVideoCaptions(server.url, videoUUID) | 104 | const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) |
116 | expect(res.body.total).to.equal(2) | 105 | expect(body.total).to.equal(2) |
117 | expect(res.body.data).to.have.lengthOf(2) | 106 | expect(body.data).to.have.lengthOf(2) |
118 | 107 | ||
119 | const caption1: VideoCaption = res.body.data[0] | 108 | const caption1 = body.data[0] |
120 | expect(caption1.language.id).to.equal('ar') | 109 | expect(caption1.language.id).to.equal('ar') |
121 | expect(caption1.language.label).to.equal('Arabic') | 110 | expect(caption1.language.label).to.equal('Arabic') |
122 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) | 111 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) |
@@ -127,9 +116,7 @@ describe('Test video captions', function () { | |||
127 | it('Should replace an existing caption with a srt file and convert it', async function () { | 116 | it('Should replace an existing caption with a srt file and convert it', async function () { |
128 | this.timeout(30000) | 117 | this.timeout(30000) |
129 | 118 | ||
130 | await createVideoCaption({ | 119 | await servers[0].captionsCommand.createVideoCaption({ |
131 | url: servers[0].url, | ||
132 | accessToken: servers[0].accessToken, | ||
133 | language: 'ar', | 120 | language: 'ar', |
134 | videoId: videoUUID, | 121 | videoId: videoUUID, |
135 | fixture: 'subtitle-good.srt' | 122 | fixture: 'subtitle-good.srt' |
@@ -143,11 +130,11 @@ describe('Test video captions', function () { | |||
143 | 130 | ||
144 | it('Should have this caption updated and converted', async function () { | 131 | it('Should have this caption updated and converted', async function () { |
145 | for (const server of servers) { | 132 | for (const server of servers) { |
146 | const res = await listVideoCaptions(server.url, videoUUID) | 133 | const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) |
147 | expect(res.body.total).to.equal(2) | 134 | expect(body.total).to.equal(2) |
148 | expect(res.body.data).to.have.lengthOf(2) | 135 | expect(body.data).to.have.lengthOf(2) |
149 | 136 | ||
150 | const caption1: VideoCaption = res.body.data[0] | 137 | const caption1 = body.data[0] |
151 | expect(caption1.language.id).to.equal('ar') | 138 | expect(caption1.language.id).to.equal('ar') |
152 | expect(caption1.language.label).to.equal('Arabic') | 139 | expect(caption1.language.label).to.equal('Arabic') |
153 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) | 140 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) |
@@ -172,18 +159,18 @@ describe('Test video captions', function () { | |||
172 | it('Should remove one caption', async function () { | 159 | it('Should remove one caption', async function () { |
173 | this.timeout(30000) | 160 | this.timeout(30000) |
174 | 161 | ||
175 | await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar') | 162 | await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) |
176 | 163 | ||
177 | await waitJobs(servers) | 164 | await waitJobs(servers) |
178 | }) | 165 | }) |
179 | 166 | ||
180 | it('Should only list the caption that was not deleted', async function () { | 167 | it('Should only list the caption that was not deleted', async function () { |
181 | for (const server of servers) { | 168 | for (const server of servers) { |
182 | const res = await listVideoCaptions(server.url, videoUUID) | 169 | const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) |
183 | expect(res.body.total).to.equal(1) | 170 | expect(body.total).to.equal(1) |
184 | expect(res.body.data).to.have.lengthOf(1) | 171 | expect(body.data).to.have.lengthOf(1) |
185 | 172 | ||
186 | const caption: VideoCaption = res.body.data[0] | 173 | const caption = body.data[0] |
187 | 174 | ||
188 | expect(caption.language.id).to.equal('zh') | 175 | expect(caption.language.id).to.equal('zh') |
189 | expect(caption.language.label).to.equal('Chinese') | 176 | expect(caption.language.label).to.equal('Chinese') |
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index a4a9132b4..14aed604f 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts | |||
@@ -11,7 +11,6 @@ import { | |||
11 | getVideo, | 11 | getVideo, |
12 | getVideosList, | 12 | getVideosList, |
13 | immutableAssign, | 13 | immutableAssign, |
14 | listVideoCaptions, | ||
15 | ServerInfo, | 14 | ServerInfo, |
16 | setAccessTokensToServers, | 15 | setAccessTokensToServers, |
17 | testCaptionFile | 16 | testCaptionFile |
@@ -25,7 +24,7 @@ import { | |||
25 | getYoutubeVideoUrl, | 24 | getYoutubeVideoUrl, |
26 | importVideo | 25 | importVideo |
27 | } from '../../../../shared/extra-utils/videos/video-imports' | 26 | } from '../../../../shared/extra-utils/videos/video-imports' |
28 | import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' | 27 | import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' |
29 | 28 | ||
30 | const expect = chai.expect | 29 | const expect = chai.expect |
31 | 30 | ||
@@ -36,8 +35,8 @@ describe('Test video imports', function () { | |||
36 | 35 | ||
37 | if (areHttpImportTestsDisabled()) return | 36 | if (areHttpImportTestsDisabled()) return |
38 | 37 | ||
39 | async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { | 38 | async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { |
40 | const resHttp = await getVideo(url, idHttp) | 39 | const resHttp = await getVideo(server.url, idHttp) |
41 | const videoHttp: VideoDetails = resHttp.body | 40 | const videoHttp: VideoDetails = resHttp.body |
42 | 41 | ||
43 | expect(videoHttp.name).to.equal('small video - youtube') | 42 | expect(videoHttp.name).to.equal('small video - youtube') |
@@ -55,9 +54,9 @@ describe('Test video imports', function () { | |||
55 | expect(originallyPublishedAt.getMonth()).to.equal(0) | 54 | expect(originallyPublishedAt.getMonth()).to.equal(0) |
56 | expect(originallyPublishedAt.getFullYear()).to.equal(2019) | 55 | expect(originallyPublishedAt.getFullYear()).to.equal(2019) |
57 | 56 | ||
58 | const resMagnet = await getVideo(url, idMagnet) | 57 | const resMagnet = await getVideo(server.url, idMagnet) |
59 | const videoMagnet: VideoDetails = resMagnet.body | 58 | const videoMagnet: VideoDetails = resMagnet.body |
60 | const resTorrent = await getVideo(url, idTorrent) | 59 | const resTorrent = await getVideo(server.url, idTorrent) |
61 | const videoTorrent: VideoDetails = resTorrent.body | 60 | const videoTorrent: VideoDetails = resTorrent.body |
62 | 61 | ||
63 | for (const video of [ videoMagnet, videoTorrent ]) { | 62 | for (const video of [ videoMagnet, videoTorrent ]) { |
@@ -73,12 +72,12 @@ describe('Test video imports', function () { | |||
73 | expect(videoTorrent.name).to.contain('ä½ å¥½ 世界 720p.mp4') | 72 | expect(videoTorrent.name).to.contain('ä½ å¥½ 世界 720p.mp4') |
74 | expect(videoMagnet.name).to.contain('super peertube2 video') | 73 | expect(videoMagnet.name).to.contain('super peertube2 video') |
75 | 74 | ||
76 | const resCaptions = await listVideoCaptions(url, idHttp) | 75 | const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: idHttp }) |
77 | expect(resCaptions.body.total).to.equal(2) | 76 | expect(bodyCaptions.total).to.equal(2) |
78 | } | 77 | } |
79 | 78 | ||
80 | async function checkVideoServer2 (url: string, id: number | string) { | 79 | async function checkVideoServer2 (server: ServerInfo, id: number | string) { |
81 | const res = await getVideo(url, id) | 80 | const res = await getVideo(server.url, id) |
82 | const video: VideoDetails = res.body | 81 | const video: VideoDetails = res.body |
83 | 82 | ||
84 | expect(video.name).to.equal('my super name') | 83 | expect(video.name).to.equal('my super name') |
@@ -91,8 +90,8 @@ describe('Test video imports', function () { | |||
91 | 90 | ||
92 | expect(video.files).to.have.lengthOf(1) | 91 | expect(video.files).to.have.lengthOf(1) |
93 | 92 | ||
94 | const resCaptions = await listVideoCaptions(url, id) | 93 | const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: id }) |
95 | expect(resCaptions.body.total).to.equal(2) | 94 | expect(bodyCaptions.total).to.equal(2) |
96 | } | 95 | } |
97 | 96 | ||
98 | before(async function () { | 97 | before(async function () { |
@@ -135,8 +134,8 @@ describe('Test video imports', function () { | |||
135 | await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) | 134 | await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) |
136 | await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) | 135 | await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) |
137 | 136 | ||
138 | const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) | 137 | const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id }) |
139 | const videoCaptions: VideoCaption[] = resCaptions.body.data | 138 | const videoCaptions = bodyCaptions.data |
140 | expect(videoCaptions).to.have.lengthOf(2) | 139 | expect(videoCaptions).to.have.lengthOf(2) |
141 | 140 | ||
142 | const enCaption = videoCaptions.find(caption => caption.language.id === 'en') | 141 | const enCaption = videoCaptions.find(caption => caption.language.id === 'en') |
@@ -241,7 +240,7 @@ Ajouter un sous-titre est vraiment facile`) | |||
241 | expect(res.body.data).to.have.lengthOf(3) | 240 | expect(res.body.data).to.have.lengthOf(3) |
242 | 241 | ||
243 | const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data | 242 | const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data |
244 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | 243 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) |
245 | } | 244 | } |
246 | }) | 245 | }) |
247 | 246 | ||
@@ -273,10 +272,10 @@ Ajouter un sous-titre est vraiment facile`) | |||
273 | expect(res.body.total).to.equal(4) | 272 | expect(res.body.total).to.equal(4) |
274 | expect(res.body.data).to.have.lengthOf(4) | 273 | expect(res.body.data).to.have.lengthOf(4) |
275 | 274 | ||
276 | await checkVideoServer2(server.url, res.body.data[0].uuid) | 275 | await checkVideoServer2(server, res.body.data[0].uuid) |
277 | 276 | ||
278 | const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data | 277 | const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data |
279 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | 278 | await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) |
280 | } | 279 | } |
281 | }) | 280 | }) |
282 | 281 | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index a4432902f..170360341 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests' | |||
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | 19 | import { SocketIOCommand } from '../socket' |
20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' | 20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' |
21 | import { LiveCommand, ServicesCommand, BlacklistCommand } from '../videos' | 21 | import { LiveCommand, ServicesCommand, BlacklistCommand, CaptionsCommand } from '../videos' |
22 | import { ConfigCommand } from './config-command' | 22 | import { ConfigCommand } from './config-command' |
23 | import { ContactFormCommand } from './contact-form-command' | 23 | import { ContactFormCommand } from './contact-form-command' |
24 | import { DebugCommand } from './debug-command' | 24 | import { DebugCommand } from './debug-command' |
@@ -103,6 +103,7 @@ interface ServerInfo { | |||
103 | liveCommand?: LiveCommand | 103 | liveCommand?: LiveCommand |
104 | servicesCommand?: ServicesCommand | 104 | servicesCommand?: ServicesCommand |
105 | blacklistCommand?: BlacklistCommand | 105 | blacklistCommand?: BlacklistCommand |
106 | captionsCommand?: CaptionsCommand | ||
106 | } | 107 | } |
107 | 108 | ||
108 | function parallelTests () { | 109 | function parallelTests () { |
@@ -331,6 +332,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
331 | server.liveCommand = new LiveCommand(server) | 332 | server.liveCommand = new LiveCommand(server) |
332 | server.servicesCommand = new ServicesCommand(server) | 333 | server.servicesCommand = new ServicesCommand(server) |
333 | server.blacklistCommand = new BlacklistCommand(server) | 334 | server.blacklistCommand = new BlacklistCommand(server) |
335 | server.captionsCommand = new CaptionsCommand(server) | ||
334 | 336 | ||
335 | res(server) | 337 | res(server) |
336 | }) | 338 | }) |
diff --git a/shared/extra-utils/videos/captions-command.ts b/shared/extra-utils/videos/captions-command.ts new file mode 100644 index 000000000..908b6dae6 --- /dev/null +++ b/shared/extra-utils/videos/captions-command.ts | |||
@@ -0,0 +1,66 @@ | |||
1 | import { ResultList, VideoCaption } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { buildAbsoluteFixturePath } from '../miscs/miscs' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class CaptionsCommand extends AbstractCommand { | ||
7 | |||
8 | createVideoCaption (options: OverrideCommandOptions & { | ||
9 | videoId: string | number | ||
10 | language: string | ||
11 | fixture: string | ||
12 | mimeType?: string | ||
13 | }) { | ||
14 | const { videoId, language, fixture, mimeType } = options | ||
15 | |||
16 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | ||
17 | |||
18 | const captionfile = buildAbsoluteFixturePath(fixture) | ||
19 | const captionfileAttach = mimeType | ||
20 | ? [ captionfile, { contentType: mimeType } ] | ||
21 | : captionfile | ||
22 | |||
23 | return this.putUploadRequest({ | ||
24 | ...options, | ||
25 | |||
26 | path, | ||
27 | fields: {}, | ||
28 | attaches: { | ||
29 | captionfile: captionfileAttach | ||
30 | }, | ||
31 | implicitToken: true, | ||
32 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
33 | }) | ||
34 | } | ||
35 | |||
36 | listVideoCaptions (options: OverrideCommandOptions & { | ||
37 | videoId: string | number | ||
38 | }) { | ||
39 | const { videoId } = options | ||
40 | const path = '/api/v1/videos/' + videoId + '/captions' | ||
41 | |||
42 | return this.getRequestBody<ResultList<VideoCaption>>({ | ||
43 | ...options, | ||
44 | |||
45 | path, | ||
46 | implicitToken: false, | ||
47 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
48 | }) | ||
49 | } | ||
50 | |||
51 | deleteVideoCaption (options: OverrideCommandOptions & { | ||
52 | videoId: string | number | ||
53 | language: string | ||
54 | }) { | ||
55 | const { videoId, language } = options | ||
56 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | ||
57 | |||
58 | return this.deleteRequest({ | ||
59 | ...options, | ||
60 | |||
61 | path, | ||
62 | implicitToken: true, | ||
63 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
64 | }) | ||
65 | } | ||
66 | } | ||
diff --git a/shared/extra-utils/videos/captions.ts b/shared/extra-utils/videos/captions.ts new file mode 100644 index 000000000..2246bd133 --- /dev/null +++ b/shared/extra-utils/videos/captions.ts | |||
@@ -0,0 +1,17 @@ | |||
1 | import { expect } from 'chai' | ||
2 | import * as request from 'supertest' | ||
3 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
4 | |||
5 | async function testCaptionFile (url: string, captionPath: string, containsString: string) { | ||
6 | const res = await request(url) | ||
7 | .get(captionPath) | ||
8 | .expect(HttpStatusCode.OK_200) | ||
9 | |||
10 | expect(res.text).to.contain(containsString) | ||
11 | } | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | export { | ||
16 | testCaptionFile | ||
17 | } | ||
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts index 67f5faf54..03b4756d5 100644 --- a/shared/extra-utils/videos/index.ts +++ b/shared/extra-utils/videos/index.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | export * from './blacklist-command' | 1 | export * from './blacklist-command' |
2 | export * from './captions' | ||
3 | export * from './captions-command' | ||
2 | export * from './live-command' | 4 | export * from './live-command' |
3 | export * from './live' | 5 | export * from './live' |
4 | export * from './services-command' | 6 | export * from './services-command' |
5 | export * from './video-captions' | ||
6 | export * from './video-change-ownership' | 7 | export * from './video-change-ownership' |
7 | export * from './video-channels' | 8 | export * from './video-channels' |
8 | export * from './video-comments' | 9 | export * from './video-comments' |
diff --git a/shared/extra-utils/videos/video-captions.ts b/shared/extra-utils/videos/video-captions.ts deleted file mode 100644 index 62eec7b90..000000000 --- a/shared/extra-utils/videos/video-captions.ts +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests' | ||
2 | import * as request from 'supertest' | ||
3 | import * as chai from 'chai' | ||
4 | import { buildAbsoluteFixturePath } from '../miscs/miscs' | ||
5 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
6 | |||
7 | const expect = chai.expect | ||
8 | |||
9 | function createVideoCaption (args: { | ||
10 | url: string | ||
11 | accessToken: string | ||
12 | videoId: string | number | ||
13 | language: string | ||
14 | fixture: string | ||
15 | mimeType?: string | ||
16 | statusCodeExpected?: number | ||
17 | }) { | ||
18 | const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language | ||
19 | |||
20 | const captionfile = buildAbsoluteFixturePath(args.fixture) | ||
21 | const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile | ||
22 | |||
23 | return makeUploadRequest({ | ||
24 | method: 'PUT', | ||
25 | url: args.url, | ||
26 | path, | ||
27 | token: args.accessToken, | ||
28 | fields: {}, | ||
29 | attaches: { | ||
30 | captionfile: captionfileAttach | ||
31 | }, | ||
32 | statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204 | ||
33 | }) | ||
34 | } | ||
35 | |||
36 | function listVideoCaptions (url: string, videoId: string | number) { | ||
37 | const path = '/api/v1/videos/' + videoId + '/captions' | ||
38 | |||
39 | return makeGetRequest({ | ||
40 | url, | ||
41 | path, | ||
42 | statusCodeExpected: HttpStatusCode.OK_200 | ||
43 | }) | ||
44 | } | ||
45 | |||
46 | function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) { | ||
47 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | ||
48 | |||
49 | return makeDeleteRequest({ | ||
50 | url, | ||
51 | token, | ||
52 | path, | ||
53 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
54 | }) | ||
55 | } | ||
56 | |||
57 | async function testCaptionFile (url: string, captionPath: string, containsString: string) { | ||
58 | const res = await request(url) | ||
59 | .get(captionPath) | ||
60 | .expect(HttpStatusCode.OK_200) | ||
61 | |||
62 | expect(res.text).to.contain(containsString) | ||
63 | } | ||
64 | |||
65 | // --------------------------------------------------------------------------- | ||
66 | |||
67 | export { | ||
68 | createVideoCaption, | ||
69 | listVideoCaptions, | ||
70 | testCaptionFile, | ||
71 | deleteVideoCaption | ||
72 | } | ||