1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
15 function in10Seconds () {
16 const now = new Date()
17 now.setSeconds(now.getSeconds() + 10)
22 describe('Test video update scheduler', function () {
23 let servers: PeerTubeServer[] = []
24 let video2UUID: string
26 before(async function () {
30 servers = await createMultipleServers(2)
32 await setAccessTokensToServers(servers)
34 await doubleFollow(servers[0], servers[1])
37 it('Should upload a video and schedule an update in 10 seconds', async function () {
42 privacy: VideoPrivacy.PRIVATE,
44 updateAt: in10Seconds().toISOString(),
45 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
49 await servers[0].videos.upload({ attributes })
51 await waitJobs(servers)
54 it('Should not list the video (in privacy mode)', async function () {
55 for (const server of servers) {
56 const { total } = await server.videos.list()
58 expect(total).to.equal(0)
62 it('Should have my scheduled video in my account videos', async function () {
63 const { total, data } = await servers[0].videos.listMyVideos()
64 expect(total).to.equal(1)
66 const videoFromList = data[0]
67 const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid })
69 for (const video of [ videoFromList, videoFromGet ]) {
70 expect(video.name).to.equal('video 1')
71 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
72 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
73 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
77 it('Should wait some seconds and have the video in public privacy', async function () {
81 await waitJobs(servers)
83 for (const server of servers) {
84 const { total, data } = await server.videos.list()
86 expect(total).to.equal(1)
87 expect(data[0].name).to.equal('video 1')
91 it('Should upload a video without scheduling an update', async function () {
96 privacy: VideoPrivacy.PRIVATE
99 const { uuid } = await servers[0].videos.upload({ attributes })
102 await waitJobs(servers)
105 it('Should update a video by scheduling an update', async function () {
109 name: 'video 2 updated',
111 updateAt: in10Seconds().toISOString(),
112 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
116 await servers[0].videos.update({ id: video2UUID, attributes })
117 await waitJobs(servers)
120 it('Should not display the updated video', async function () {
121 for (const server of servers) {
122 const { total } = await server.videos.list()
124 expect(total).to.equal(1)
128 it('Should have my scheduled updated video in my account videos', async function () {
129 const { total, data } = await servers[0].videos.listMyVideos()
130 expect(total).to.equal(2)
132 const video = data.find(v => v.uuid === video2UUID)
133 expect(video).not.to.be.undefined
135 expect(video.name).to.equal('video 2 updated')
136 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
138 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
139 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
142 it('Should wait some seconds and have the updated video in public privacy', async function () {
146 await waitJobs(servers)
148 for (const server of servers) {
149 const { total, data } = await server.videos.list()
150 expect(total).to.equal(2)
152 const video = data.find(v => v.uuid === video2UUID)
153 expect(video).not.to.be.undefined
154 expect(video.name).to.equal('video 2 updated')
158 after(async function () {
159 await cleanupTests(servers)