aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/index.ts1
-rw-r--r--server/tests/api/videos/multiple-servers.ts15
-rw-r--r--server/tests/api/videos/resumable-upload.ts187
-rw-r--r--server/tests/api/videos/single-server.ts724
-rw-r--r--server/tests/api/videos/video-channels.ts82
-rw-r--r--server/tests/api/videos/video-comments.ts3
-rw-r--r--server/tests/api/videos/video-transcoder.ts159
7 files changed, 705 insertions, 466 deletions
diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts
index fc8b447b7..5c07f8926 100644
--- a/server/tests/api/videos/index.ts
+++ b/server/tests/api/videos/index.ts
@@ -1,5 +1,6 @@
1import './audio-only' 1import './audio-only'
2import './multiple-servers' 2import './multiple-servers'
3import './resumable-upload'
3import './single-server' 4import './single-server'
4import './video-captions' 5import './video-captions'
5import './video-change-ownership' 6import './video-change-ownership'
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 55e280e9f..6aa996038 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -1,11 +1,10 @@
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
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import * as request from 'supertest' 6import * as request from 'supertest'
7import { VideoPrivacy } from '../../../../shared/models/videos' 7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
9import { 8import {
10 addVideoChannel, 9 addVideoChannel,
11 checkTmpIsEmpty, 10 checkTmpIsEmpty,
@@ -32,16 +31,16 @@ import {
32 wait, 31 wait,
33 webtorrentAdd 32 webtorrentAdd
34} from '../../../../shared/extra-utils' 33} from '../../../../shared/extra-utils'
34import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
35import { 35import {
36 addVideoCommentReply, 36 addVideoCommentReply,
37 addVideoCommentThread, 37 addVideoCommentThread,
38 deleteVideoComment, 38 deleteVideoComment,
39 findCommentId,
39 getVideoCommentThreads, 40 getVideoCommentThreads,
40 getVideoThreadComments, 41 getVideoThreadComments
41 findCommentId
42} from '../../../../shared/extra-utils/videos/video-comments' 42} from '../../../../shared/extra-utils/videos/video-comments'
43import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 43import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos'
44import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
45 44
46const expect = chai.expect 45const expect = chai.expect
47 46
@@ -181,7 +180,7 @@ describe('Test multiple servers', function () {
181 thumbnailfile: 'thumbnail.jpg', 180 thumbnailfile: 'thumbnail.jpg',
182 previewfile: 'preview.jpg' 181 previewfile: 'preview.jpg'
183 } 182 }
184 await uploadVideo(servers[1].url, userAccessToken, videoAttributes) 183 await uploadVideo(servers[1].url, userAccessToken, videoAttributes, HttpStatusCode.OK_200, 'resumable')
185 184
186 // Transcoding 185 // Transcoding
187 await waitJobs(servers) 186 await waitJobs(servers)
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
new file mode 100644
index 000000000..af9221c43
--- /dev/null
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -0,0 +1,187 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { pathExists, readdir, stat } from 'fs-extra'
6import { join } from 'path'
7import { HttpStatusCode } from '@shared/core-utils'
8import {
9 buildAbsoluteFixturePath,
10 buildServerDirectory,
11 flushAndRunServer,
12 getMyUserInformation,
13 prepareResumableUpload,
14 sendDebugCommand,
15 sendResumableChunks,
16 ServerInfo,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
19 updateUser
20} from '@shared/extra-utils'
21import { MyUser, VideoPrivacy } from '@shared/models'
22
23const expect = chai.expect
24
25// Most classic resumable upload tests are done in other test suites
26
27describe('Test resumable upload', function () {
28 const defaultFixture = 'video_short.mp4'
29 let server: ServerInfo
30 let rootId: number
31
32 async function buildSize (fixture: string, size?: number) {
33 if (size !== undefined) return size
34
35 const baseFixture = buildAbsoluteFixturePath(fixture)
36 return (await stat(baseFixture)).size
37 }
38
39 async function prepareUpload (sizeArg?: number) {
40 const size = await buildSize(defaultFixture, sizeArg)
41
42 const attributes = {
43 name: 'video',
44 channelId: server.videoChannel.id,
45 privacy: VideoPrivacy.PUBLIC,
46 fixture: defaultFixture
47 }
48
49 const mimetype = 'video/mp4'
50
51 const res = await prepareResumableUpload({ url: server.url, token: server.accessToken, attributes, size, mimetype })
52
53 return res.header['location'].split('?')[1]
54 }
55
56 async function sendChunks (options: {
57 pathUploadId: string
58 size?: number
59 expectedStatus?: HttpStatusCode
60 contentLength?: number
61 contentRange?: string
62 contentRangeBuilder?: (start: number, chunk: any) => string
63 }) {
64 const { pathUploadId, expectedStatus, contentLength, contentRangeBuilder } = options
65
66 const size = await buildSize(defaultFixture, options.size)
67 const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture)
68
69 return sendResumableChunks({
70 url: server.url,
71 token: server.accessToken,
72 pathUploadId,
73 videoFilePath: absoluteFilePath,
74 size,
75 contentLength,
76 contentRangeBuilder,
77 specialStatus: expectedStatus
78 })
79 }
80
81 async function checkFileSize (uploadIdArg: string, expectedSize: number | null) {
82 const uploadId = uploadIdArg.replace(/^upload_id=/, '')
83
84 const subPath = join('tmp', 'resumable-uploads', uploadId)
85 const filePath = buildServerDirectory(server, subPath)
86 const exists = await pathExists(filePath)
87
88 if (expectedSize === null) {
89 expect(exists).to.be.false
90 return
91 }
92
93 expect(exists).to.be.true
94
95 expect((await stat(filePath)).size).to.equal(expectedSize)
96 }
97
98 async function countResumableUploads () {
99 const subPath = join('tmp', 'resumable-uploads')
100 const filePath = buildServerDirectory(server, subPath)
101
102 const files = await readdir(filePath)
103 return files.length
104 }
105
106 before(async function () {
107 this.timeout(30000)
108
109 server = await flushAndRunServer(1)
110 await setAccessTokensToServers([ server ])
111 await setDefaultVideoChannel([ server ])
112
113 const res = await getMyUserInformation(server.url, server.accessToken)
114 rootId = (res.body as MyUser).id
115
116 await updateUser({
117 url: server.url,
118 userId: rootId,
119 accessToken: server.accessToken,
120 videoQuota: 10_000_000
121 })
122 })
123
124 describe('Directory cleaning', function () {
125
126 it('Should correctly delete files after an upload', async function () {
127 const uploadId = await prepareUpload()
128 await sendChunks({ pathUploadId: uploadId })
129
130 expect(await countResumableUploads()).to.equal(0)
131 })
132
133 it('Should not delete files after an unfinished upload', async function () {
134 await prepareUpload()
135
136 expect(await countResumableUploads()).to.equal(2)
137 })
138
139 it('Should not delete recent uploads', async function () {
140 await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' })
141
142 expect(await countResumableUploads()).to.equal(2)
143 })
144
145 it('Should delete old uploads', async function () {
146 await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' })
147
148 expect(await countResumableUploads()).to.equal(0)
149 })
150 })
151
152 describe('Resumable upload and chunks', function () {
153
154 it('Should accept the same amount of chunks', async function () {
155 const uploadId = await prepareUpload()
156 await sendChunks({ pathUploadId: uploadId })
157
158 await checkFileSize(uploadId, null)
159 })
160
161 it('Should not accept more chunks than expected', async function () {
162 const size = 100
163 const uploadId = await prepareUpload(size)
164
165 await sendChunks({ pathUploadId: uploadId, expectedStatus: HttpStatusCode.CONFLICT_409 })
166 await checkFileSize(uploadId, 0)
167 })
168
169 it('Should not accept more chunks than expected with an invalid content length/content range', async function () {
170 const uploadId = await prepareUpload(1500)
171
172 await sendChunks({ pathUploadId: uploadId, expectedStatus: HttpStatusCode.BAD_REQUEST_400, contentLength: 1000 })
173 await checkFileSize(uploadId, 0)
174 })
175
176 it('Should not accept more chunks than expected with an invalid content length', async function () {
177 const uploadId = await prepareUpload(500)
178
179 const size = 1000
180
181 const contentRangeBuilder = start => `bytes ${start}-${start + size - 1}/${size}`
182 await sendChunks({ pathUploadId: uploadId, expectedStatus: HttpStatusCode.BAD_REQUEST_400, contentRangeBuilder, contentLength: size })
183 await checkFileSize(uploadId, 0)
184 })
185 })
186
187})
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index a79648bf7..1058a1e9c 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -1,9 +1,9 @@
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
3import 'mocha'
3import * as chai from 'chai' 4import * as chai from 'chai'
4import { keyBy } from 'lodash' 5import { keyBy } from 'lodash'
5import 'mocha' 6
6import { VideoPrivacy } from '../../../../shared/models/videos'
7import { 7import {
8 checkVideoFilesWereRemoved, 8 checkVideoFilesWereRemoved,
9 cleanupTests, 9 cleanupTests,
@@ -28,430 +28,432 @@ import {
28 viewVideo, 28 viewVideo,
29 wait 29 wait
30} from '../../../../shared/extra-utils' 30} from '../../../../shared/extra-utils'
31import { VideoPrivacy } from '../../../../shared/models/videos'
32import { HttpStatusCode } from '@shared/core-utils'
31 33
32const expect = chai.expect 34const expect = chai.expect
33 35
34describe('Test a single server', function () { 36describe('Test a single server', function () {
35 let server: ServerInfo = null
36 let videoId = -1
37 let videoId2 = -1
38 let videoUUID = ''
39 let videosListBase: any[] = null
40
41 const getCheckAttributes = () => ({
42 name: 'my super name',
43 category: 2,
44 licence: 6,
45 language: 'zh',
46 nsfw: true,
47 description: 'my super description',
48 support: 'my super support text',
49 account: {
50 name: 'root',
51 host: 'localhost:' + server.port
52 },
53 isLocal: true,
54 duration: 5,
55 tags: [ 'tag1', 'tag2', 'tag3' ],
56 privacy: VideoPrivacy.PUBLIC,
57 commentsEnabled: true,
58 downloadEnabled: true,
59 channel: {
60 displayName: 'Main root channel',
61 name: 'root_channel',
62 description: '',
63 isLocal: true
64 },
65 fixture: 'video_short.webm',
66 files: [
67 {
68 resolution: 720,
69 size: 218910
70 }
71 ]
72 })
73
74 const updateCheckAttributes = () => ({
75 name: 'my super video updated',
76 category: 4,
77 licence: 2,
78 language: 'ar',
79 nsfw: false,
80 description: 'my super description updated',
81 support: 'my super support text updated',
82 account: {
83 name: 'root',
84 host: 'localhost:' + server.port
85 },
86 isLocal: true,
87 tags: [ 'tagup1', 'tagup2' ],
88 privacy: VideoPrivacy.PUBLIC,
89 duration: 5,
90 commentsEnabled: false,
91 downloadEnabled: false,
92 channel: {
93 name: 'root_channel',
94 displayName: 'Main root channel',
95 description: '',
96 isLocal: true
97 },
98 fixture: 'video_short3.webm',
99 files: [
100 {
101 resolution: 720,
102 size: 292677
103 }
104 ]
105 })
106
107 before(async function () {
108 this.timeout(30000)
109
110 server = await flushAndRunServer(1)
111
112 await setAccessTokensToServers([ server ])
113 })
114
115 it('Should list video categories', async function () {
116 const res = await getVideoCategories(server.url)
117
118 const categories = res.body
119 expect(Object.keys(categories)).to.have.length.above(10)
120
121 expect(categories[11]).to.equal('News & Politics')
122 })
123
124 it('Should list video licences', async function () {
125 const res = await getVideoLicences(server.url)
126
127 const licences = res.body
128 expect(Object.keys(licences)).to.have.length.above(5)
129
130 expect(licences[3]).to.equal('Attribution - No Derivatives')
131 })
132
133 it('Should list video languages', async function () {
134 const res = await getVideoLanguages(server.url)
135
136 const languages = res.body
137 expect(Object.keys(languages)).to.have.length.above(5)
138
139 expect(languages['ru']).to.equal('Russian')
140 })
141
142 it('Should list video privacies', async function () {
143 const res = await getVideoPrivacies(server.url)
144
145 const privacies = res.body
146 expect(Object.keys(privacies)).to.have.length.at.least(3)
147
148 expect(privacies[3]).to.equal('Private')
149 })
150
151 it('Should not have videos', async function () {
152 const res = await getVideosList(server.url)
153
154 expect(res.body.total).to.equal(0)
155 expect(res.body.data).to.be.an('array')
156 expect(res.body.data.length).to.equal(0)
157 })
158 37
159 it('Should upload the video', async function () { 38 function runSuite (mode: 'legacy' | 'resumable') {
160 this.timeout(10000) 39 let server: ServerInfo = null
40 let videoId = -1
41 let videoId2 = -1
42 let videoUUID = ''
43 let videosListBase: any[] = null
161 44
162 const videoAttributes = { 45 const getCheckAttributes = () => ({
163 name: 'my super name', 46 name: 'my super name',
164 category: 2, 47 category: 2,
165 nsfw: true,
166 licence: 6, 48 licence: 6,
167 tags: [ 'tag1', 'tag2', 'tag3' ] 49 language: 'zh',
168 } 50 nsfw: true,
169 const res = await uploadVideo(server.url, server.accessToken, videoAttributes) 51 description: 'my super description',
170 expect(res.body.video).to.not.be.undefined 52 support: 'my super support text',
171 expect(res.body.video.id).to.equal(1) 53 account: {
172 expect(res.body.video.uuid).to.have.length.above(5) 54 name: 'root',
173 55 host: 'localhost:' + server.port
174 videoId = res.body.video.id 56 },
175 videoUUID = res.body.video.uuid 57 isLocal: true,
176 }) 58 duration: 5,
177 59 tags: [ 'tag1', 'tag2', 'tag3' ],
178 it('Should get and seed the uploaded video', async function () { 60 privacy: VideoPrivacy.PUBLIC,
179 this.timeout(5000) 61 commentsEnabled: true,
180 62 downloadEnabled: true,
181 const res = await getVideosList(server.url) 63 channel: {
182 64 displayName: 'Main root channel',
183 expect(res.body.total).to.equal(1) 65 name: 'root_channel',
184 expect(res.body.data).to.be.an('array') 66 description: '',
185 expect(res.body.data.length).to.equal(1) 67 isLocal: true
186 68 },
187 const video = res.body.data[0] 69 fixture: 'video_short.webm',
188 await completeVideoCheck(server.url, video, getCheckAttributes()) 70 files: [
189 }) 71 {
72 resolution: 720,
73 size: 218910
74 }
75 ]
76 })
77
78 const updateCheckAttributes = () => ({
79 name: 'my super video updated',
80 category: 4,
81 licence: 2,
82 language: 'ar',
83 nsfw: false,
84 description: 'my super description updated',
85 support: 'my super support text updated',
86 account: {
87 name: 'root',
88 host: 'localhost:' + server.port
89 },
90 isLocal: true,
91 tags: [ 'tagup1', 'tagup2' ],
92 privacy: VideoPrivacy.PUBLIC,
93 duration: 5,
94 commentsEnabled: false,
95 downloadEnabled: false,
96 channel: {
97 name: 'root_channel',
98 displayName: 'Main root channel',
99 description: '',
100 isLocal: true
101 },
102 fixture: 'video_short3.webm',
103 files: [
104 {
105 resolution: 720,
106 size: 292677
107 }
108 ]
109 })
190 110
191 it('Should get the video by UUID', async function () { 111 before(async function () {
192 this.timeout(5000) 112 this.timeout(30000)
193 113
194 const res = await getVideo(server.url, videoUUID) 114 server = await flushAndRunServer(1)
195 115
196 const video = res.body 116 await setAccessTokensToServers([ server ])
197 await completeVideoCheck(server.url, video, getCheckAttributes()) 117 })
198 })
199 118
200 it('Should have the views updated', async function () { 119 it('Should list video categories', async function () {
201 this.timeout(20000) 120 const res = await getVideoCategories(server.url)
202 121
203 await viewVideo(server.url, videoId) 122 const categories = res.body
204 await viewVideo(server.url, videoId) 123 expect(Object.keys(categories)).to.have.length.above(10)
205 await viewVideo(server.url, videoId)
206 124
207 await wait(1500) 125 expect(categories[11]).to.equal('News & Politics')
126 })
208 127
209 await viewVideo(server.url, videoId) 128 it('Should list video licences', async function () {
210 await viewVideo(server.url, videoId) 129 const res = await getVideoLicences(server.url)
211 130
212 await wait(1500) 131 const licences = res.body
132 expect(Object.keys(licences)).to.have.length.above(5)
213 133
214 await viewVideo(server.url, videoId) 134 expect(licences[3]).to.equal('Attribution - No Derivatives')
215 await viewVideo(server.url, videoId) 135 })
216 136
217 // Wait the repeatable job 137 it('Should list video languages', async function () {
218 await wait(8000) 138 const res = await getVideoLanguages(server.url)
219 139
220 const res = await getVideo(server.url, videoId) 140 const languages = res.body
141 expect(Object.keys(languages)).to.have.length.above(5)
221 142
222 const video = res.body 143 expect(languages['ru']).to.equal('Russian')
223 expect(video.views).to.equal(3) 144 })
224 })
225 145
226 it('Should remove the video', async function () { 146 it('Should list video privacies', async function () {
227 await removeVideo(server.url, server.accessToken, videoId) 147 const res = await getVideoPrivacies(server.url)
228 148
229 await checkVideoFilesWereRemoved(videoUUID, 1) 149 const privacies = res.body
230 }) 150 expect(Object.keys(privacies)).to.have.length.at.least(3)
231 151
232 it('Should not have videos', async function () { 152 expect(privacies[3]).to.equal('Private')
233 const res = await getVideosList(server.url) 153 })
234 154
235 expect(res.body.total).to.equal(0) 155 it('Should not have videos', async function () {
236 expect(res.body.data).to.be.an('array') 156 const res = await getVideosList(server.url)
237 expect(res.body.data).to.have.lengthOf(0)
238 })
239 157
240 it('Should upload 6 videos', async function () { 158 expect(res.body.total).to.equal(0)
241 this.timeout(25000) 159 expect(res.body.data).to.be.an('array')
160 expect(res.body.data.length).to.equal(0)
161 })
242 162
243 const videos = new Set([ 163 it('Should upload the video', async function () {
244 'video_short.mp4', 'video_short.ogv', 'video_short.webm', 164 this.timeout(10000)
245 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
246 ])
247 165
248 for (const video of videos) {
249 const videoAttributes = { 166 const videoAttributes = {
250 name: video + ' name', 167 name: 'my super name',
251 description: video + ' description',
252 category: 2, 168 category: 2,
253 licence: 1,
254 language: 'en',
255 nsfw: true, 169 nsfw: true,
256 tags: [ 'tag1', 'tag2', 'tag3' ], 170 licence: 6,
257 fixture: video 171 tags: [ 'tag1', 'tag2', 'tag3' ]
258 } 172 }
173 const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode)
174 expect(res.body.video).to.not.be.undefined
175 expect(res.body.video.id).to.equal(1)
176 expect(res.body.video.uuid).to.have.length.above(5)
259 177
260 await uploadVideo(server.url, server.accessToken, videoAttributes) 178 videoId = res.body.video.id
261 } 179 videoUUID = res.body.video.uuid
262 }) 180 })
263 181
264 it('Should have the correct durations', async function () { 182 it('Should get and seed the uploaded video', async function () {
265 const res = await getVideosList(server.url) 183 this.timeout(5000)
266
267 expect(res.body.total).to.equal(6)
268 const videos = res.body.data
269 expect(videos).to.be.an('array')
270 expect(videos).to.have.lengthOf(6)
271
272 const videosByName = keyBy<{ duration: number }>(videos, 'name')
273 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
274 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
275 expect(videosByName['video_short.webm name'].duration).to.equal(5)
276 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
277 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
278 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
279 })
280 184
281 it('Should have the correct thumbnails', async function () { 185 const res = await getVideosList(server.url)
282 const res = await getVideosList(server.url)
283 186
284 const videos = res.body.data 187 expect(res.body.total).to.equal(1)
285 // For the next test 188 expect(res.body.data).to.be.an('array')
286 videosListBase = videos 189 expect(res.body.data.length).to.equal(1)
287 190
288 for (const video of videos) { 191 const video = res.body.data[0]
289 const videoName = video.name.replace(' name', '') 192 await completeVideoCheck(server.url, video, getCheckAttributes())
290 await testImage(server.url, videoName, video.thumbnailPath) 193 })
291 }
292 })
293 194
294 it('Should list only the two first videos', async function () { 195 it('Should get the video by UUID', async function () {
295 const res = await getVideosListPagination(server.url, 0, 2, 'name') 196 this.timeout(5000)
296 197
297 const videos = res.body.data 198 const res = await getVideo(server.url, videoUUID)
298 expect(res.body.total).to.equal(6)
299 expect(videos.length).to.equal(2)
300 expect(videos[0].name).to.equal(videosListBase[0].name)
301 expect(videos[1].name).to.equal(videosListBase[1].name)
302 })
303 199
304 it('Should list only the next three videos', async function () { 200 const video = res.body
305 const res = await getVideosListPagination(server.url, 2, 3, 'name') 201 await completeVideoCheck(server.url, video, getCheckAttributes())
202 })
306 203
307 const videos = res.body.data 204 it('Should have the views updated', async function () {
308 expect(res.body.total).to.equal(6) 205 this.timeout(20000)
309 expect(videos.length).to.equal(3)
310 expect(videos[0].name).to.equal(videosListBase[2].name)
311 expect(videos[1].name).to.equal(videosListBase[3].name)
312 expect(videos[2].name).to.equal(videosListBase[4].name)
313 })
314 206
315 it('Should list the last video', async function () { 207 await viewVideo(server.url, videoId)
316 const res = await getVideosListPagination(server.url, 5, 6, 'name') 208 await viewVideo(server.url, videoId)
209 await viewVideo(server.url, videoId)
317 210
318 const videos = res.body.data 211 await wait(1500)
319 expect(res.body.total).to.equal(6)
320 expect(videos.length).to.equal(1)
321 expect(videos[0].name).to.equal(videosListBase[5].name)
322 })
323 212
324 it('Should not have the total field', async function () { 213 await viewVideo(server.url, videoId)
325 const res = await getVideosListPagination(server.url, 5, 6, 'name', true) 214 await viewVideo(server.url, videoId)
326 215
327 const videos = res.body.data 216 await wait(1500)
328 expect(res.body.total).to.not.exist
329 expect(videos.length).to.equal(1)
330 expect(videos[0].name).to.equal(videosListBase[5].name)
331 })
332 217
333 it('Should list and sort by name in descending order', async function () { 218 await viewVideo(server.url, videoId)
334 const res = await getVideosListSort(server.url, '-name') 219 await viewVideo(server.url, videoId)
335
336 const videos = res.body.data
337 expect(res.body.total).to.equal(6)
338 expect(videos.length).to.equal(6)
339 expect(videos[0].name).to.equal('video_short.webm name')
340 expect(videos[1].name).to.equal('video_short.ogv name')
341 expect(videos[2].name).to.equal('video_short.mp4 name')
342 expect(videos[3].name).to.equal('video_short3.webm name')
343 expect(videos[4].name).to.equal('video_short2.webm name')
344 expect(videos[5].name).to.equal('video_short1.webm name')
345
346 videoId = videos[3].uuid
347 videoId2 = videos[5].uuid
348 })
349 220
350 it('Should list and sort by trending in descending order', async function () { 221 // Wait the repeatable job
351 const res = await getVideosListPagination(server.url, 0, 2, '-trending') 222 await wait(8000)
352 223
353 const videos = res.body.data 224 const res = await getVideo(server.url, videoId)
354 expect(res.body.total).to.equal(6)
355 expect(videos.length).to.equal(2)
356 })
357 225
358 it('Should list and sort by hotness in descending order', async function () { 226 const video = res.body
359 const res = await getVideosListPagination(server.url, 0, 2, '-hot') 227 expect(video.views).to.equal(3)
228 })
360 229
361 const videos = res.body.data 230 it('Should remove the video', async function () {
362 expect(res.body.total).to.equal(6) 231 await removeVideo(server.url, server.accessToken, videoId)
363 expect(videos.length).to.equal(2)
364 })
365 232
366 it('Should list and sort by best in descending order', async function () { 233 await checkVideoFilesWereRemoved(videoUUID, 1)
367 const res = await getVideosListPagination(server.url, 0, 2, '-best') 234 })
368 235
369 const videos = res.body.data 236 it('Should not have videos', async function () {
370 expect(res.body.total).to.equal(6) 237 const res = await getVideosList(server.url)
371 expect(videos.length).to.equal(2)
372 })
373 238
374 it('Should update a video', async function () { 239 expect(res.body.total).to.equal(0)
375 const attributes = { 240 expect(res.body.data).to.be.an('array')
376 name: 'my super video updated', 241 expect(res.body.data).to.have.lengthOf(0)
377 category: 4, 242 })
378 licence: 2,
379 language: 'ar',
380 nsfw: false,
381 description: 'my super description updated',
382 commentsEnabled: false,
383 downloadEnabled: false,
384 tags: [ 'tagup1', 'tagup2' ]
385 }
386 await updateVideo(server.url, server.accessToken, videoId, attributes)
387 })
388 243
389 it('Should filter by tags and category', async function () { 244 it('Should upload 6 videos', async function () {
390 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) 245 this.timeout(25000)
391 expect(res1.body.total).to.equal(1)
392 expect(res1.body.data[0].name).to.equal('my super video updated')
393 246
394 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) 247 const videos = new Set([
395 expect(res2.body.total).to.equal(0) 248 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
396 }) 249 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
250 ])
397 251
398 it('Should have the video updated', async function () { 252 for (const video of videos) {
399 this.timeout(60000) 253 const videoAttributes = {
254 name: video + ' name',
255 description: video + ' description',
256 category: 2,
257 licence: 1,
258 language: 'en',
259 nsfw: true,
260 tags: [ 'tag1', 'tag2', 'tag3' ],
261 fixture: video
262 }
400 263
401 const res = await getVideo(server.url, videoId) 264 await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode)
402 const video = res.body 265 }
266 })
267
268 it('Should have the correct durations', async function () {
269 const res = await getVideosList(server.url)
270
271 expect(res.body.total).to.equal(6)
272 const videos = res.body.data
273 expect(videos).to.be.an('array')
274 expect(videos).to.have.lengthOf(6)
275
276 const videosByName = keyBy<{ duration: number }>(videos, 'name')
277 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
278 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
279 expect(videosByName['video_short.webm name'].duration).to.equal(5)
280 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
281 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
282 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
283 })
284
285 it('Should have the correct thumbnails', async function () {
286 const res = await getVideosList(server.url)
287
288 const videos = res.body.data
289 // For the next test
290 videosListBase = videos
291
292 for (const video of videos) {
293 const videoName = video.name.replace(' name', '')
294 await testImage(server.url, videoName, video.thumbnailPath)
295 }
296 })
297
298 it('Should list only the two first videos', async function () {
299 const res = await getVideosListPagination(server.url, 0, 2, 'name')
300
301 const videos = res.body.data
302 expect(res.body.total).to.equal(6)
303 expect(videos.length).to.equal(2)
304 expect(videos[0].name).to.equal(videosListBase[0].name)
305 expect(videos[1].name).to.equal(videosListBase[1].name)
306 })
307
308 it('Should list only the next three videos', async function () {
309 const res = await getVideosListPagination(server.url, 2, 3, 'name')
310
311 const videos = res.body.data
312 expect(res.body.total).to.equal(6)
313 expect(videos.length).to.equal(3)
314 expect(videos[0].name).to.equal(videosListBase[2].name)
315 expect(videos[1].name).to.equal(videosListBase[3].name)
316 expect(videos[2].name).to.equal(videosListBase[4].name)
317 })
318
319 it('Should list the last video', async function () {
320 const res = await getVideosListPagination(server.url, 5, 6, 'name')
321
322 const videos = res.body.data
323 expect(res.body.total).to.equal(6)
324 expect(videos.length).to.equal(1)
325 expect(videos[0].name).to.equal(videosListBase[5].name)
326 })
327
328 it('Should not have the total field', async function () {
329 const res = await getVideosListPagination(server.url, 5, 6, 'name', true)
330
331 const videos = res.body.data
332 expect(res.body.total).to.not.exist
333 expect(videos.length).to.equal(1)
334 expect(videos[0].name).to.equal(videosListBase[5].name)
335 })
336
337 it('Should list and sort by name in descending order', async function () {
338 const res = await getVideosListSort(server.url, '-name')
339
340 const videos = res.body.data
341 expect(res.body.total).to.equal(6)
342 expect(videos.length).to.equal(6)
343 expect(videos[0].name).to.equal('video_short.webm name')
344 expect(videos[1].name).to.equal('video_short.ogv name')
345 expect(videos[2].name).to.equal('video_short.mp4 name')
346 expect(videos[3].name).to.equal('video_short3.webm name')
347 expect(videos[4].name).to.equal('video_short2.webm name')
348 expect(videos[5].name).to.equal('video_short1.webm name')
349
350 videoId = videos[3].uuid
351 videoId2 = videos[5].uuid
352 })
353
354 it('Should list and sort by trending in descending order', async function () {
355 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
356
357 const videos = res.body.data
358 expect(res.body.total).to.equal(6)
359 expect(videos.length).to.equal(2)
360 })
361
362 it('Should list and sort by hotness in descending order', async function () {
363 const res = await getVideosListPagination(server.url, 0, 2, '-hot')
364
365 const videos = res.body.data
366 expect(res.body.total).to.equal(6)
367 expect(videos.length).to.equal(2)
368 })
369
370 it('Should list and sort by best in descending order', async function () {
371 const res = await getVideosListPagination(server.url, 0, 2, '-best')
372
373 const videos = res.body.data
374 expect(res.body.total).to.equal(6)
375 expect(videos.length).to.equal(2)
376 })
377
378 it('Should update a video', async function () {
379 const attributes = {
380 name: 'my super video updated',
381 category: 4,
382 licence: 2,
383 language: 'ar',
384 nsfw: false,
385 description: 'my super description updated',
386 commentsEnabled: false,
387 downloadEnabled: false,
388 tags: [ 'tagup1', 'tagup2' ]
389 }
390 await updateVideo(server.url, server.accessToken, videoId, attributes)
391 })
403 392
404 await completeVideoCheck(server.url, video, updateCheckAttributes()) 393 it('Should filter by tags and category', async function () {
405 }) 394 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
395 expect(res1.body.total).to.equal(1)
396 expect(res1.body.data[0].name).to.equal('my super video updated')
406 397
407 it('Should update only the tags of a video', async function () { 398 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
408 const attributes = { 399 expect(res2.body.total).to.equal(0)
409 tags: [ 'supertag', 'tag1', 'tag2' ] 400 })
410 }
411 await updateVideo(server.url, server.accessToken, videoId, attributes)
412 401
413 const res = await getVideo(server.url, videoId) 402 it('Should have the video updated', async function () {
414 const video = res.body 403 this.timeout(60000)
415 404
416 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) 405 const res = await getVideo(server.url, videoId)
417 }) 406 const video = res.body
418 407
419 it('Should update only the description of a video', async function () { 408 await completeVideoCheck(server.url, video, updateCheckAttributes())
420 const attributes = { 409 })
421 description: 'hello everybody'
422 }
423 await updateVideo(server.url, server.accessToken, videoId, attributes)
424 410
425 const res = await getVideo(server.url, videoId) 411 it('Should update only the tags of a video', async function () {
426 const video = res.body 412 const attributes = {
413 tags: [ 'supertag', 'tag1', 'tag2' ]
414 }
415 await updateVideo(server.url, server.accessToken, videoId, attributes)
427 416
428 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) 417 const res = await getVideo(server.url, videoId)
429 await completeVideoCheck(server.url, video, expectedAttributes) 418 const video = res.body
430 })
431 419
432 it('Should like a video', async function () { 420 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes))
433 await rateVideo(server.url, server.accessToken, videoId, 'like') 421 })
434 422
435 const res = await getVideo(server.url, videoId) 423 it('Should update only the description of a video', async function () {
436 const video = res.body 424 const attributes = {
425 description: 'hello everybody'
426 }
427 await updateVideo(server.url, server.accessToken, videoId, attributes)
437 428
438 expect(video.likes).to.equal(1) 429 const res = await getVideo(server.url, videoId)
439 expect(video.dislikes).to.equal(0) 430 const video = res.body
440 })
441 431
442 it('Should dislike the same video', async function () { 432 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
443 await rateVideo(server.url, server.accessToken, videoId, 'dislike') 433 await completeVideoCheck(server.url, video, expectedAttributes)
434 })
444 435
445 const res = await getVideo(server.url, videoId) 436 it('Should like a video', async function () {
446 const video = res.body 437 await rateVideo(server.url, server.accessToken, videoId, 'like')
447 438
448 expect(video.likes).to.equal(0) 439 const res = await getVideo(server.url, videoId)
449 expect(video.dislikes).to.equal(1) 440 const video = res.body
450 })
451 441
452 it('Should sort by originallyPublishedAt', async function () { 442 expect(video.likes).to.equal(1)
453 { 443 expect(video.dislikes).to.equal(0)
444 })
454 445
446 it('Should dislike the same video', async function () {
447 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
448
449 const res = await getVideo(server.url, videoId)
450 const video = res.body
451
452 expect(video.likes).to.equal(0)
453 expect(video.dislikes).to.equal(1)
454 })
455
456 it('Should sort by originallyPublishedAt', async function () {
455 { 457 {
456 const now = new Date() 458 const now = new Date()
457 const attributes = { originallyPublishedAt: now.toISOString() } 459 const attributes = { originallyPublishedAt: now.toISOString() }
@@ -483,10 +485,18 @@ describe('Test a single server', function () {
483 expect(names[4]).to.equal('video_short.ogv name') 485 expect(names[4]).to.equal('video_short.ogv name')
484 expect(names[5]).to.equal('video_short.mp4 name') 486 expect(names[5]).to.equal('video_short.mp4 name')
485 } 487 }
486 } 488 })
489
490 after(async function () {
491 await cleanupTests([ server ])
492 })
493 }
494
495 describe('Legacy upload', function () {
496 runSuite('legacy')
487 }) 497 })
488 498
489 after(async function () { 499 describe('Resumable upload', function () {
490 await cleanupTests([ server ]) 500 runSuite('resumable')
491 }) 501 })
492}) 502})
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index d12d58e75..7e7ad028c 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { basename } from 'path' 5import { basename } from 'path'
6import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
6import { 7import {
7 cleanupTests, 8 cleanupTests,
8 createUser, 9 createUser,
@@ -13,6 +14,7 @@ import {
13 getVideo, 14 getVideo,
14 getVideoChannel, 15 getVideoChannel,
15 getVideoChannelVideos, 16 getVideoChannelVideos,
17 setDefaultVideoChannel,
16 testImage, 18 testImage,
17 updateVideo, 19 updateVideo,
18 updateVideoChannelImage, 20 updateVideoChannelImage,
@@ -33,7 +35,6 @@ import {
33} from '../../../../shared/extra-utils/index' 35} from '../../../../shared/extra-utils/index'
34import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 36import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
35import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' 37import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
36import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
37 38
38const expect = chai.expect 39const expect = chai.expect
39 40
@@ -47,9 +48,10 @@ async function findChannel (server: ServerInfo, channelId: number) {
47describe('Test video channels', function () { 48describe('Test video channels', function () {
48 let servers: ServerInfo[] 49 let servers: ServerInfo[]
49 let userInfo: User 50 let userInfo: User
50 let firstVideoChannelId: number
51 let secondVideoChannelId: number 51 let secondVideoChannelId: number
52 let totoChannel: number
52 let videoUUID: string 53 let videoUUID: string
54 let accountName: string
53 55
54 before(async function () { 56 before(async function () {
55 this.timeout(60000) 57 this.timeout(60000)
@@ -57,16 +59,9 @@ describe('Test video channels', function () {
57 servers = await flushAndRunMultipleServers(2) 59 servers = await flushAndRunMultipleServers(2)
58 60
59 await setAccessTokensToServers(servers) 61 await setAccessTokensToServers(servers)
60 await doubleFollow(servers[0], servers[1]) 62 await setDefaultVideoChannel(servers)
61
62 {
63 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
64 const user: User = res.body
65
66 firstVideoChannelId = user.videoChannels[0].id
67 }
68 63
69 await waitJobs(servers) 64 await doubleFollow(servers[0], servers[1])
70 }) 65 })
71 66
72 it('Should have one video channel (created with root)', async () => { 67 it('Should have one video channel (created with root)', async () => {
@@ -116,12 +111,14 @@ describe('Test video channels', function () {
116 expect(videoChannels[1].displayName).to.equal('second video channel') 111 expect(videoChannels[1].displayName).to.equal('second video channel')
117 expect(videoChannels[1].description).to.equal('super video channel description') 112 expect(videoChannels[1].description).to.equal('super video channel description')
118 expect(videoChannels[1].support).to.equal('super video channel support text') 113 expect(videoChannels[1].support).to.equal('super video channel support text')
114
115 accountName = userInfo.account.name + '@' + userInfo.account.host
119 }) 116 })
120 117
121 it('Should have two video channels when getting account channels on server 1', async function () { 118 it('Should have two video channels when getting account channels on server 1', async function () {
122 const res = await getAccountVideoChannelsList({ 119 const res = await getAccountVideoChannelsList({
123 url: servers[0].url, 120 url: servers[0].url,
124 accountName: userInfo.account.name + '@' + userInfo.account.host 121 accountName
125 }) 122 })
126 123
127 expect(res.body.total).to.equal(2) 124 expect(res.body.total).to.equal(2)
@@ -142,7 +139,7 @@ describe('Test video channels', function () {
142 { 139 {
143 const res = await getAccountVideoChannelsList({ 140 const res = await getAccountVideoChannelsList({
144 url: servers[0].url, 141 url: servers[0].url,
145 accountName: userInfo.account.name + '@' + userInfo.account.host, 142 accountName,
146 start: 0, 143 start: 0,
147 count: 1, 144 count: 1,
148 sort: 'createdAt' 145 sort: 'createdAt'
@@ -158,7 +155,7 @@ describe('Test video channels', function () {
158 { 155 {
159 const res = await getAccountVideoChannelsList({ 156 const res = await getAccountVideoChannelsList({
160 url: servers[0].url, 157 url: servers[0].url,
161 accountName: userInfo.account.name + '@' + userInfo.account.host, 158 accountName,
162 start: 0, 159 start: 0,
163 count: 1, 160 count: 1,
164 sort: '-createdAt' 161 sort: '-createdAt'
@@ -174,7 +171,7 @@ describe('Test video channels', function () {
174 { 171 {
175 const res = await getAccountVideoChannelsList({ 172 const res = await getAccountVideoChannelsList({
176 url: servers[0].url, 173 url: servers[0].url,
177 accountName: userInfo.account.name + '@' + userInfo.account.host, 174 accountName,
178 start: 1, 175 start: 1,
179 count: 1, 176 count: 1,
180 sort: '-createdAt' 177 sort: '-createdAt'
@@ -191,7 +188,7 @@ describe('Test video channels', function () {
191 it('Should have one video channel when getting account channels on server 2', async function () { 188 it('Should have one video channel when getting account channels on server 2', async function () {
192 const res = await getAccountVideoChannelsList({ 189 const res = await getAccountVideoChannelsList({
193 url: servers[1].url, 190 url: servers[1].url,
194 accountName: userInfo.account.name + '@' + userInfo.account.host 191 accountName
195 }) 192 })
196 193
197 expect(res.body.total).to.equal(1) 194 expect(res.body.total).to.equal(1)
@@ -379,7 +376,7 @@ describe('Test video channels', function () {
379 it('Should change the video channel of a video', async function () { 376 it('Should change the video channel of a video', async function () {
380 this.timeout(10000) 377 this.timeout(10000)
381 378
382 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId }) 379 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: servers[0].videoChannel.id })
383 380
384 await waitJobs(servers) 381 await waitJobs(servers)
385 }) 382 })
@@ -419,7 +416,8 @@ describe('Test video channels', function () {
419 it('Should create the main channel with an uuid if there is a conflict', async function () { 416 it('Should create the main channel with an uuid if there is a conflict', async function () {
420 { 417 {
421 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } 418 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
422 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) 419 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
420 totoChannel = res.body.videoChannel.id
423 } 421 }
424 422
425 { 423 {
@@ -438,7 +436,7 @@ describe('Test video channels', function () {
438 { 436 {
439 const res = await getAccountVideoChannelsList({ 437 const res = await getAccountVideoChannelsList({
440 url: servers[0].url, 438 url: servers[0].url,
441 accountName: userInfo.account.name + '@' + userInfo.account.host, 439 accountName,
442 withStats: true 440 withStats: true
443 }) 441 })
444 442
@@ -456,7 +454,7 @@ describe('Test video channels', function () {
456 } 454 }
457 455
458 { 456 {
459 // video has been posted on channel firstVideoChannelId since last update 457 // video has been posted on channel servers[0].videoChannel.id since last update
460 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') 458 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1')
461 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') 459 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1')
462 460
@@ -465,10 +463,10 @@ describe('Test video channels', function () {
465 463
466 const res = await getAccountVideoChannelsList({ 464 const res = await getAccountVideoChannelsList({
467 url: servers[0].url, 465 url: servers[0].url,
468 accountName: userInfo.account.name + '@' + userInfo.account.host, 466 accountName,
469 withStats: true 467 withStats: true
470 }) 468 })
471 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId) 469 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === servers[0].videoChannel.id)
472 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) 470 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
473 } 471 }
474 }) 472 })
@@ -476,7 +474,7 @@ describe('Test video channels', function () {
476 it('Should report correct videos count', async function () { 474 it('Should report correct videos count', async function () {
477 const res = await getAccountVideoChannelsList({ 475 const res = await getAccountVideoChannelsList({
478 url: servers[0].url, 476 url: servers[0].url,
479 accountName: userInfo.account.name + '@' + userInfo.account.host, 477 accountName,
480 withStats: true 478 withStats: true
481 }) 479 })
482 const channels: VideoChannel[] = res.body.data 480 const channels: VideoChannel[] = res.body.data
@@ -492,7 +490,7 @@ describe('Test video channels', function () {
492 { 490 {
493 const res = await getAccountVideoChannelsList({ 491 const res = await getAccountVideoChannelsList({
494 url: servers[0].url, 492 url: servers[0].url,
495 accountName: userInfo.account.name + '@' + userInfo.account.host, 493 accountName,
496 search: 'root' 494 search: 'root'
497 }) 495 })
498 expect(res.body.total).to.equal(1) 496 expect(res.body.total).to.equal(1)
@@ -504,7 +502,7 @@ describe('Test video channels', function () {
504 { 502 {
505 const res = await getAccountVideoChannelsList({ 503 const res = await getAccountVideoChannelsList({
506 url: servers[0].url, 504 url: servers[0].url,
507 accountName: userInfo.account.name + '@' + userInfo.account.host, 505 accountName,
508 search: 'does not exist' 506 search: 'does not exist'
509 }) 507 })
510 expect(res.body.total).to.equal(0) 508 expect(res.body.total).to.equal(0)
@@ -514,6 +512,40 @@ describe('Test video channels', function () {
514 } 512 }
515 }) 513 })
516 514
515 it('Should list channels by updatedAt desc if a video has been uploaded', async function () {
516 this.timeout(30000)
517
518 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: totoChannel })
519 await waitJobs(servers)
520
521 for (const server of servers) {
522 const res = await getAccountVideoChannelsList({
523 url: server.url,
524 accountName,
525 sort: '-updatedAt'
526 })
527
528 const channels: VideoChannel[] = res.body.data
529 expect(channels[0].name).to.equal('toto_channel')
530 expect(channels[1].name).to.equal('root_channel')
531 }
532
533 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id })
534 await waitJobs(servers)
535
536 for (const server of servers) {
537 const res = await getAccountVideoChannelsList({
538 url: server.url,
539 accountName,
540 sort: '-updatedAt'
541 })
542
543 const channels: VideoChannel[] = res.body.data
544 expect(channels[0].name).to.equal('root_channel')
545 expect(channels[1].name).to.equal('toto_channel')
546 }
547 })
548
517 after(async function () { 549 after(async function () {
518 await cleanupTests(servers) 550 await cleanupTests(servers)
519 }) 551 })
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 615e0ea45..a5ff3a39d 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5 5import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models'
6import { cleanupTests, testImage } from '../../../../shared/extra-utils' 6import { cleanupTests, testImage } from '../../../../shared/extra-utils'
7import { 7import {
8 createUser, 8 createUser,
@@ -22,7 +22,6 @@ import {
22 getVideoCommentThreads, 22 getVideoCommentThreads,
23 getVideoThreadComments 23 getVideoThreadComments
24} from '../../../../shared/extra-utils/videos/video-comments' 24} from '../../../../shared/extra-utils/videos/video-comments'
25import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
26 25
27const expect = chai.expect 26const expect = chai.expect
28 27
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index 1c99f26df..ea5ffd239 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -361,106 +361,117 @@ describe('Test video transcoding', function () {
361 361
362 describe('Audio upload', function () { 362 describe('Audio upload', function () {
363 363
364 before(async function () { 364 function runSuite (mode: 'legacy' | 'resumable') {
365 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { 365
366 transcoding: { 366 before(async function () {
367 hls: { enabled: true }, 367 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, {
368 webtorrent: { enabled: true }, 368 transcoding: {
369 resolutions: { 369 hls: { enabled: true },
370 '0p': false, 370 webtorrent: { enabled: true },
371 '240p': false, 371 resolutions: {
372 '360p': false, 372 '0p': false,
373 '480p': false, 373 '240p': false,
374 '720p': false, 374 '360p': false,
375 '1080p': false, 375 '480p': false,
376 '1440p': false, 376 '720p': false,
377 '2160p': false 377 '1080p': false,
378 '1440p': false,
379 '2160p': false
380 }
378 } 381 }
379 } 382 })
380 }) 383 })
381 })
382
383 it('Should merge an audio file with the preview file', async function () {
384 this.timeout(60_000)
385
386 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
387 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg)
388 384
389 await waitJobs(servers) 385 it('Should merge an audio file with the preview file', async function () {
386 this.timeout(60_000)
390 387
391 for (const server of servers) { 388 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
392 const res = await getVideosList(server.url) 389 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
393 390
394 const video = res.body.data.find(v => v.name === 'audio_with_preview') 391 await waitJobs(servers)
395 const res2 = await getVideo(server.url, video.id)
396 const videoDetails: VideoDetails = res2.body
397 392
398 expect(videoDetails.files).to.have.lengthOf(1) 393 for (const server of servers) {
394 const res = await getVideosList(server.url)
399 395
400 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) 396 const video = res.body.data.find(v => v.name === 'audio_with_preview')
401 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) 397 const res2 = await getVideo(server.url, video.id)
398 const videoDetails: VideoDetails = res2.body
402 399
403 const magnetUri = videoDetails.files[0].magnetUri 400 expect(videoDetails.files).to.have.lengthOf(1)
404 expect(magnetUri).to.contain('.mp4')
405 }
406 })
407 401
408 it('Should upload an audio file and choose a default background image', async function () { 402 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
409 this.timeout(60_000) 403 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
410 404
411 const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } 405 const magnetUri = videoDetails.files[0].magnetUri
412 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg) 406 expect(magnetUri).to.contain('.mp4')
407 }
408 })
413 409
414 await waitJobs(servers) 410 it('Should upload an audio file and choose a default background image', async function () {
411 this.timeout(60_000)
415 412
416 for (const server of servers) { 413 const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' }
417 const res = await getVideosList(server.url) 414 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
418 415
419 const video = res.body.data.find(v => v.name === 'audio_without_preview') 416 await waitJobs(servers)
420 const res2 = await getVideo(server.url, video.id)
421 const videoDetails = res2.body
422 417
423 expect(videoDetails.files).to.have.lengthOf(1) 418 for (const server of servers) {
419 const res = await getVideosList(server.url)
424 420
425 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) 421 const video = res.body.data.find(v => v.name === 'audio_without_preview')
426 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) 422 const res2 = await getVideo(server.url, video.id)
423 const videoDetails = res2.body
427 424
428 const magnetUri = videoDetails.files[0].magnetUri 425 expect(videoDetails.files).to.have.lengthOf(1)
429 expect(magnetUri).to.contain('.mp4')
430 }
431 })
432 426
433 it('Should upload an audio file and create an audio version only', async function () { 427 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
434 this.timeout(60_000) 428 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
435 429
436 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { 430 const magnetUri = videoDetails.files[0].magnetUri
437 transcoding: { 431 expect(magnetUri).to.contain('.mp4')
438 hls: { enabled: true },
439 webtorrent: { enabled: true },
440 resolutions: {
441 '0p': true,
442 '240p': false,
443 '360p': false
444 }
445 } 432 }
446 }) 433 })
447 434
448 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } 435 it('Should upload an audio file and create an audio version only', async function () {
449 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg) 436 this.timeout(60_000)
437
438 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, {
439 transcoding: {
440 hls: { enabled: true },
441 webtorrent: { enabled: true },
442 resolutions: {
443 '0p': true,
444 '240p': false,
445 '360p': false
446 }
447 }
448 })
450 449
451 await waitJobs(servers) 450 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
451 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
452 452
453 for (const server of servers) { 453 await waitJobs(servers)
454 const res2 = await getVideo(server.url, resVideo.body.video.id) 454
455 const videoDetails: VideoDetails = res2.body 455 for (const server of servers) {
456 const res2 = await getVideo(server.url, resVideo.body.video.id)
457 const videoDetails: VideoDetails = res2.body
456 458
457 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { 459 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
458 expect(files).to.have.lengthOf(2) 460 expect(files).to.have.lengthOf(2)
459 expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined 461 expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined
462 }
460 } 463 }
461 }
462 464
463 await updateConfigForTranscoding(servers[1]) 465 await updateConfigForTranscoding(servers[1])
466 })
467 }
468
469 describe('Legacy upload', function () {
470 runSuite('legacy')
471 })
472
473 describe('Resumable upload', function () {
474 runSuite('resumable')
464 }) 475 })
465 }) 476 })
466 477