1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
15 const expect = chai.expect
17 function in10Seconds () {
18 const now = new Date()
19 now.setSeconds(now.getSeconds() + 10)
24 describe('Test video update scheduler', function () {
25 let servers: PeerTubeServer[] = []
26 let video2UUID: string
28 before(async function () {
32 servers = await createMultipleServers(2)
34 await setAccessTokensToServers(servers)
36 await doubleFollow(servers[0], servers[1])
39 it('Should upload a video and schedule an update in 10 seconds', async function () {
44 privacy: VideoPrivacy.PRIVATE,
46 updateAt: in10Seconds().toISOString(),
47 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
51 await servers[0].videos.upload({ attributes })
53 await waitJobs(servers)
56 it('Should not list the video (in privacy mode)', async function () {
57 for (const server of servers) {
58 const { total } = await server.videos.list()
60 expect(total).to.equal(0)
64 it('Should have my scheduled video in my account videos', async function () {
65 const { total, data } = await servers[0].videos.listMyVideos()
66 expect(total).to.equal(1)
68 const videoFromList = data[0]
69 const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid })
71 for (const video of [ videoFromList, videoFromGet ]) {
72 expect(video.name).to.equal('video 1')
73 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
74 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
75 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
79 it('Should wait some seconds and have the video in public privacy', async function () {
83 await waitJobs(servers)
85 for (const server of servers) {
86 const { total, data } = await server.videos.list()
88 expect(total).to.equal(1)
89 expect(data[0].name).to.equal('video 1')
93 it('Should upload a video without scheduling an update', async function () {
98 privacy: VideoPrivacy.PRIVATE
101 const { uuid } = await servers[0].videos.upload({ attributes })
104 await waitJobs(servers)
107 it('Should update a video by scheduling an update', async function () {
111 name: 'video 2 updated',
113 updateAt: in10Seconds().toISOString(),
114 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
118 await servers[0].videos.update({ id: video2UUID, attributes })
119 await waitJobs(servers)
122 it('Should not display the updated video', async function () {
123 for (const server of servers) {
124 const { total } = await server.videos.list()
126 expect(total).to.equal(1)
130 it('Should have my scheduled updated video in my account videos', async function () {
131 const { total, data } = await servers[0].videos.listMyVideos()
132 expect(total).to.equal(2)
134 const video = data.find(v => v.uuid === video2UUID)
135 expect(video).not.to.be.undefined
137 expect(video.name).to.equal('video 2 updated')
138 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
140 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
141 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
144 it('Should wait some seconds and have the updated video in public privacy', async function () {
148 await waitJobs(servers)
150 for (const server of servers) {
151 const { total, data } = await server.videos.list()
152 expect(total).to.equal(2)
154 const video = data.find(v => v.uuid === video2UUID)
155 expect(video).not.to.be.undefined
156 expect(video.name).to.equal('video 2 updated')
160 after(async function () {
161 await cleanupTests(servers)