1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
13 } from '@shared/extra-utils'
14 import { VideoPrivacy } from '@shared/models'
16 const expect = chai.expect
18 function in10Seconds () {
19 const now = new Date()
20 now.setSeconds(now.getSeconds() + 10)
25 describe('Test video update scheduler', function () {
26 let servers: PeerTubeServer[] = []
27 let video2UUID: string
29 before(async function () {
33 servers = await createMultipleServers(2)
35 await setAccessTokensToServers(servers)
37 await doubleFollow(servers[0], servers[1])
40 it('Should upload a video and schedule an update in 10 seconds', async function () {
45 privacy: VideoPrivacy.PRIVATE,
47 updateAt: in10Seconds().toISOString(),
48 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
52 await servers[0].videos.upload({ attributes })
54 await waitJobs(servers)
57 it('Should not list the video (in privacy mode)', async function () {
58 for (const server of servers) {
59 const { total } = await server.videos.list()
61 expect(total).to.equal(0)
65 it('Should have my scheduled video in my account videos', async function () {
66 const { total, data } = await servers[0].videos.listMyVideos()
67 expect(total).to.equal(1)
69 const videoFromList = data[0]
70 const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid })
72 for (const video of [ videoFromList, videoFromGet ]) {
73 expect(video.name).to.equal('video 1')
74 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
75 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
76 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
80 it('Should wait some seconds and have the video in public privacy', async function () {
84 await waitJobs(servers)
86 for (const server of servers) {
87 const { total, data } = await server.videos.list()
89 expect(total).to.equal(1)
90 expect(data[0].name).to.equal('video 1')
94 it('Should upload a video without scheduling an update', async function () {
99 privacy: VideoPrivacy.PRIVATE
102 const { uuid } = await servers[0].videos.upload({ attributes })
105 await waitJobs(servers)
108 it('Should update a video by scheduling an update', async function () {
112 name: 'video 2 updated',
114 updateAt: in10Seconds().toISOString(),
115 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
119 await servers[0].videos.update({ id: video2UUID, attributes })
120 await waitJobs(servers)
123 it('Should not display the updated video', async function () {
124 for (const server of servers) {
125 const { total } = await server.videos.list()
127 expect(total).to.equal(1)
131 it('Should have my scheduled updated video in my account videos', async function () {
132 const { total, data } = await servers[0].videos.listMyVideos()
133 expect(total).to.equal(2)
135 const video = data.find(v => v.uuid === video2UUID)
136 expect(video).not.to.be.undefined
138 expect(video.name).to.equal('video 2 updated')
139 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
141 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
142 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
145 it('Should wait some seconds and have the updated video in public privacy', async function () {
149 await waitJobs(servers)
151 for (const server of servers) {
152 const { total, data } = await server.videos.list()
153 expect(total).to.equal(2)
155 const video = data.find(v => v.uuid === video2UUID)
156 expect(video).not.to.be.undefined
157 expect(video.name).to.equal('video 2 updated')
161 after(async function () {
162 await cleanupTests(servers)