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 () {
40 privacy: VideoPrivacy.PRIVATE,
42 updateAt: in10Seconds().toISOString(),
43 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
47 await servers[0].videos.upload({ attributes })
49 await waitJobs(servers)
52 it('Should not list the video (in privacy mode)', async function () {
53 for (const server of servers) {
54 const { total } = await server.videos.list()
56 expect(total).to.equal(0)
60 it('Should have my scheduled video in my account videos', async function () {
61 const { total, data } = await servers[0].videos.listMyVideos()
62 expect(total).to.equal(1)
64 const videoFromList = data[0]
65 const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid })
67 for (const video of [ videoFromList, videoFromGet ]) {
68 expect(video.name).to.equal('video 1')
69 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
70 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
71 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
75 it('Should wait some seconds and have the video in public privacy', async function () {
79 await waitJobs(servers)
81 for (const server of servers) {
82 const { total, data } = await server.videos.list()
84 expect(total).to.equal(1)
85 expect(data[0].name).to.equal('video 1')
89 it('Should upload a video without scheduling an update', async function () {
92 privacy: VideoPrivacy.PRIVATE
95 const { uuid } = await servers[0].videos.upload({ attributes })
98 await waitJobs(servers)
101 it('Should update a video by scheduling an update', async function () {
103 name: 'video 2 updated',
105 updateAt: in10Seconds().toISOString(),
106 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
110 await servers[0].videos.update({ id: video2UUID, attributes })
111 await waitJobs(servers)
114 it('Should not display the updated video', async function () {
115 for (const server of servers) {
116 const { total } = await server.videos.list()
118 expect(total).to.equal(1)
122 it('Should have my scheduled updated video in my account videos', async function () {
123 const { total, data } = await servers[0].videos.listMyVideos()
124 expect(total).to.equal(2)
126 const video = data.find(v => v.uuid === video2UUID)
127 expect(video).not.to.be.undefined
129 expect(video.name).to.equal('video 2 updated')
130 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
132 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
133 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
136 it('Should wait some seconds and have the updated video in public privacy', async function () {
140 await waitJobs(servers)
142 for (const server of servers) {
143 const { total, data } = await server.videos.list()
144 expect(total).to.equal(2)
146 const video = data.find(v => v.uuid === video2UUID)
147 expect(video).not.to.be.undefined
148 expect(video.name).to.equal('video 2 updated')
152 after(async function () {
153 await cleanupTests(servers)