X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideo-schedule-update.ts;h=73f1519d9dddf9373a8ca3ea9daaf1b42600477b;hb=b1dbb9fefc870a90b25f5c0153589f45c9e75e3e;hp=b19a9116aafcb84697c2f94696b4acd4a48c43e2;hpb=94565d52bb2883e09f16d1363170ac9c0dccb7a1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index b19a9116a..73f1519d9 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -1,24 +1,16 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' -import 'mocha' -import { VideoPrivacy } from '../../../../shared/models/videos' +import { expect } from 'chai' +import { wait } from '@shared/core-utils' +import { VideoPrivacy } from '@shared/models' import { + cleanupTests, + createMultipleServers, doubleFollow, - flushAndRunMultipleServers, - getMyVideos, - getVideosList, - getVideoWithToken, - killallServers, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - updateVideo, - uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' - -const expect = chai.expect + waitJobs +} from '@shared/server-commands' function in10Seconds () { const now = new Date() @@ -28,14 +20,14 @@ function in10Seconds () { } describe('Test video update scheduler', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video2UUID: string before(async function () { this.timeout(30000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) @@ -45,35 +37,34 @@ describe('Test video update scheduler', function () { it('Should upload a video and schedule an update in 10 seconds', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 1', privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: in10Seconds().toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) }) it('Should not list the video (in privacy mode)', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total } = await server.videos.list() - expect(res.body.total).to.equal(0) + expect(total).to.equal(0) } }) it('Should have my scheduled video in my account videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - expect(res.body.total).to.equal(1) + const { total, data } = await servers[0].videos.listMyVideos() + expect(total).to.equal(1) - const videoFromList = res.body.data[0] - const res2 = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoFromList.uuid) - const videoFromGet = res2.body + const videoFromList = data[0] + const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid }) for (const video of [ videoFromList, videoFromGet ]) { expect(video.name).to.equal('video 1') @@ -84,29 +75,29 @@ describe('Test video update scheduler', function () { }) it('Should wait some seconds and have the video in public privacy', async function () { - this.timeout(20000) + this.timeout(50000) await wait(15000) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videos.list() - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('video 1') + expect(total).to.equal(1) + expect(data[0].name).to.equal('video 1') } }) it('Should upload a video without scheduling an update', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 2', privacy: VideoPrivacy.PRIVATE } - const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - video2UUID = res.body.video.uuid + const { uuid } = await servers[0].videos.upload({ attributes }) + video2UUID = uuid await waitJobs(servers) }) @@ -114,31 +105,31 @@ describe('Test video update scheduler', function () { it('Should update a video by scheduling an update', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 2 updated', scheduleUpdate: { updateAt: in10Seconds().toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes) + await servers[0].videos.update({ id: video2UUID, attributes }) await waitJobs(servers) }) it('Should not display the updated video', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total } = await server.videos.list() - expect(res.body.total).to.equal(1) + expect(total).to.equal(1) } }) it('Should have my scheduled updated video in my account videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - expect(res.body.total).to.equal(2) + const { total, data } = await servers[0].videos.listMyVideos() + expect(total).to.equal(2) - const video = res.body.data.find(v => v.uuid === video2UUID) + const video = data.find(v => v.uuid === video2UUID) expect(video).not.to.be.undefined expect(video.name).to.equal('video 2 updated') @@ -155,17 +146,16 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(2) + const { total, data } = await server.videos.list() + expect(total).to.equal(2) - const video = res.body.data.find(v => v.uuid === video2UUID) + const video = data.find(v => v.uuid === video2UUID) expect(video).not.to.be.undefined expect(video.name).to.equal('video 2 updated') } }) after(async function () { - killallServers(servers) + await cleanupTests(servers) }) })