aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-15 10:02:54 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitd23dd9fbfc4d26026352c10f81d2795ceaf2908a (patch)
treeda82286d423c5e834a1ee2dcd5970076b8263cf1 /server/tests/api/live/live.ts
parent7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (diff)
downloadPeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.gz
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.zst
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.zip
Introduce videos command
Diffstat (limited to 'server/tests/api/live/live.ts')
-rw-r--r--server/tests/api/live/live.ts88
1 files changed, 36 insertions, 52 deletions
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts
index 999a49051..c88143982 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -4,8 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' 6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' 7import { HttpStatusCode } from '@shared/core-utils'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9import { 8import {
10 checkLiveCleanup, 9 checkLiveCleanup,
11 checkLiveSegmentHash, 10 checkLiveSegmentHash,
@@ -13,14 +12,9 @@ import {
13 cleanupTests, 12 cleanupTests,
14 doubleFollow, 13 doubleFollow,
15 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
16 getMyVideosWithFilter,
17 getVideo,
18 getVideosList,
19 getVideosWithFilters,
20 killallServers, 15 killallServers,
21 LiveCommand, 16 LiveCommand,
22 makeRawRequest, 17 makeRawRequest,
23 removeVideo,
24 reRunServer, 18 reRunServer,
25 sendRTMPStream, 19 sendRTMPStream,
26 ServerInfo, 20 ServerInfo,
@@ -29,11 +23,11 @@ import {
29 stopFfmpeg, 23 stopFfmpeg,
30 testFfmpegStreamError, 24 testFfmpegStreamError,
31 testImage, 25 testImage,
32 uploadVideoAndGetId,
33 wait, 26 wait,
34 waitJobs, 27 waitJobs,
35 waitUntilLivePublishedOnAllServers 28 waitUntilLivePublishedOnAllServers
36} from '../../../../shared/extra-utils' 29} from '@shared/extra-utils'
30import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
37 31
38const expect = chai.expect 32const expect = chai.expect
39 33
@@ -99,8 +93,7 @@ describe('Test live', function () {
99 await waitJobs(servers) 93 await waitJobs(servers)
100 94
101 for (const server of servers) { 95 for (const server of servers) {
102 const resVideo = await getVideo(server.url, liveVideoUUID) 96 const video = await server.videosCommand.get({ id: liveVideoUUID })
103 const video: VideoDetails = resVideo.body
104 97
105 expect(video.category.id).to.equal(1) 98 expect(video.category.id).to.equal(1)
106 expect(video.licence.id).to.equal(2) 99 expect(video.licence.id).to.equal(2)
@@ -154,9 +147,7 @@ describe('Test live', function () {
154 await waitJobs(servers) 147 await waitJobs(servers)
155 148
156 for (const server of servers) { 149 for (const server of servers) {
157 const resVideo = await getVideo(server.url, videoId) 150 const video = await server.videosCommand.get({ id: videoId })
158 const video: VideoDetails = resVideo.body
159
160 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) 151 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
161 expect(video.nsfw).to.be.true 152 expect(video.nsfw).to.be.true
162 153
@@ -167,10 +158,10 @@ describe('Test live', function () {
167 158
168 it('Should not have the live listed since nobody streams into', async function () { 159 it('Should not have the live listed since nobody streams into', async function () {
169 for (const server of servers) { 160 for (const server of servers) {
170 const res = await getVideosList(server.url) 161 const { total, data } = await server.videosCommand.list()
171 162
172 expect(res.body.total).to.equal(0) 163 expect(total).to.equal(0)
173 expect(res.body.data).to.have.lengthOf(0) 164 expect(data).to.have.lengthOf(0)
174 } 165 }
175 }) 166 })
176 167
@@ -204,13 +195,13 @@ describe('Test live', function () {
204 it('Delete the live', async function () { 195 it('Delete the live', async function () {
205 this.timeout(10000) 196 this.timeout(10000)
206 197
207 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) 198 await servers[0].videosCommand.remove({ id: liveVideoUUID })
208 await waitJobs(servers) 199 await waitJobs(servers)
209 }) 200 })
210 201
211 it('Should have the live deleted', async function () { 202 it('Should have the live deleted', async function () {
212 for (const server of servers) { 203 for (const server of servers) {
213 await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) 204 await server.videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
214 await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 205 await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
215 } 206 }
216 }) 207 })
@@ -224,7 +215,7 @@ describe('Test live', function () {
224 before(async function () { 215 before(async function () {
225 this.timeout(120000) 216 this.timeout(120000)
226 217
227 vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid 218 vodVideoId = (await servers[0].videosCommand.quickUpload({ name: 'vod video' })).uuid
228 219
229 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } 220 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id }
230 const live = await commands[0].create({ fields: liveOptions }) 221 const live = await commands[0].create({ fields: liveOptions })
@@ -236,19 +227,19 @@ describe('Test live', function () {
236 }) 227 })
237 228
238 it('Should only display lives', async function () { 229 it('Should only display lives', async function () {
239 const res = await getVideosWithFilters(servers[0].url, { isLive: true }) 230 const { data, total } = await servers[0].videosCommand.list({ isLive: true })
240 231
241 expect(res.body.total).to.equal(1) 232 expect(total).to.equal(1)
242 expect(res.body.data).to.have.lengthOf(1) 233 expect(data).to.have.lengthOf(1)
243 expect(res.body.data[0].name).to.equal('live') 234 expect(data[0].name).to.equal('live')
244 }) 235 })
245 236
246 it('Should not display lives', async function () { 237 it('Should not display lives', async function () {
247 const res = await getVideosWithFilters(servers[0].url, { isLive: false }) 238 const { data, total } = await servers[0].videosCommand.list({ isLive: false })
248 239
249 expect(res.body.total).to.equal(1) 240 expect(total).to.equal(1)
250 expect(res.body.data).to.have.lengthOf(1) 241 expect(data).to.have.lengthOf(1)
251 expect(res.body.data[0].name).to.equal('vod video') 242 expect(data[0].name).to.equal('vod video')
252 }) 243 })
253 244
254 it('Should display my lives', async function () { 245 it('Should display my lives', async function () {
@@ -257,24 +248,22 @@ describe('Test live', function () {
257 await stopFfmpeg(ffmpegCommand) 248 await stopFfmpeg(ffmpegCommand)
258 await waitJobs(servers) 249 await waitJobs(servers)
259 250
260 const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) 251 const { data } = await servers[0].videosCommand.listMyVideos({ isLive: true })
261 const videos = res.body.data as Video[]
262 252
263 const result = videos.every(v => v.isLive) 253 const result = data.every(v => v.isLive)
264 expect(result).to.be.true 254 expect(result).to.be.true
265 }) 255 })
266 256
267 it('Should not display my lives', async function () { 257 it('Should not display my lives', async function () {
268 const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false }) 258 const { data } = await servers[0].videosCommand.listMyVideos({ isLive: false })
269 const videos = res.body.data as Video[]
270 259
271 const result = videos.every(v => !v.isLive) 260 const result = data.every(v => !v.isLive)
272 expect(result).to.be.true 261 expect(result).to.be.true
273 }) 262 })
274 263
275 after(async function () { 264 after(async function () {
276 await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId) 265 await servers[0].videosCommand.remove({ id: vodVideoId })
277 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId) 266 await servers[0].videosCommand.remove({ id: liveVideoId })
278 }) 267 })
279 }) 268 })
280 269
@@ -297,9 +286,9 @@ describe('Test live', function () {
297 const { uuid } = await commands[0].create({ fields: liveAttributes }) 286 const { uuid } = await commands[0].create({ fields: liveAttributes })
298 287
299 const live = await commands[0].get({ videoId: uuid }) 288 const live = await commands[0].get({ videoId: uuid })
300 const resVideo = await getVideo(servers[0].url, uuid) 289 const video = await servers[0].videosCommand.get({ id: uuid })
301 290
302 return Object.assign(resVideo.body as VideoDetails, live) 291 return Object.assign(video, live)
303 } 292 }
304 293
305 it('Should not allow a stream without the appropriate path', async function () { 294 it('Should not allow a stream without the appropriate path', async function () {
@@ -327,13 +316,12 @@ describe('Test live', function () {
327 316
328 it('Should list this live now someone stream into it', async function () { 317 it('Should list this live now someone stream into it', async function () {
329 for (const server of servers) { 318 for (const server of servers) {
330 const res = await getVideosList(server.url) 319 const { total, data } = await server.videosCommand.list()
331
332 expect(res.body.total).to.equal(1)
333 expect(res.body.data).to.have.lengthOf(1)
334 320
335 const video: Video = res.body.data[0] 321 expect(total).to.equal(1)
322 expect(data).to.have.lengthOf(1)
336 323
324 const video = data[0]
337 expect(video.name).to.equal('user live') 325 expect(video.name).to.equal('user live')
338 expect(video.isLive).to.be.true 326 expect(video.isLive).to.be.true
339 } 327 }
@@ -355,7 +343,7 @@ describe('Test live', function () {
355 343
356 liveVideo = await createLiveWrapper() 344 liveVideo = await createLiveWrapper()
357 345
358 await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid) 346 await servers[0].videosCommand.remove({ id: liveVideo.uuid })
359 347
360 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) 348 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
361 await testFfmpegStreamError(command, true) 349 await testFfmpegStreamError(command, true)
@@ -379,13 +367,10 @@ describe('Test live', function () {
379 367
380 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { 368 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) {
381 for (const server of servers) { 369 for (const server of servers) {
382 const resList = await getVideosList(server.url) 370 const { data } = await server.videosCommand.list()
383 const videos: Video[] = resList.body.data 371 expect(data.find(v => v.uuid === liveVideoId)).to.exist
384
385 expect(videos.find(v => v.uuid === liveVideoId)).to.exist
386 372
387 const resVideo = await getVideo(server.url, liveVideoId) 373 const video = await server.videosCommand.get({ id: liveVideoId })
388 const video: VideoDetails = resVideo.body
389 374
390 expect(video.streamingPlaylists).to.have.lengthOf(1) 375 expect(video.streamingPlaylists).to.have.lengthOf(1)
391 376
@@ -505,8 +490,7 @@ describe('Test live', function () {
505 } 490 }
506 491
507 for (const server of servers) { 492 for (const server of servers) {
508 const resVideo = await getVideo(server.url, liveVideoId) 493 const video = await server.videosCommand.get({ id: liveVideoId })
509 const video: VideoDetails = resVideo.body
510 494
511 expect(video.state.id).to.equal(VideoState.PUBLISHED) 495 expect(video.state.id).to.equal(VideoState.PUBLISHED)
512 expect(video.duration).to.be.greaterThan(1) 496 expect(video.duration).to.be.greaterThan(1)