]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-schedule-update.ts
7865b343954f91312a28b7fdfb56b144ccd3f126
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-schedule-update.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { VideoPrivacy } from '@shared/models'
6 import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13 } from '@shared/server-commands'
14
15 const expect = chai.expect
16
17 function in10Seconds () {
18 const now = new Date()
19 now.setSeconds(now.getSeconds() + 10)
20
21 return now
22 }
23
24 describe('Test video update scheduler', function () {
25 let servers: PeerTubeServer[] = []
26 let video2UUID: string
27
28 before(async function () {
29 this.timeout(30000)
30
31 // Run servers
32 servers = await createMultipleServers(2)
33
34 await setAccessTokensToServers(servers)
35
36 await doubleFollow(servers[0], servers[1])
37 })
38
39 it('Should upload a video and schedule an update in 10 seconds', async function () {
40 this.timeout(10000)
41
42 const attributes = {
43 name: 'video 1',
44 privacy: VideoPrivacy.PRIVATE,
45 scheduleUpdate: {
46 updateAt: in10Seconds().toISOString(),
47 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
48 }
49 }
50
51 await servers[0].videos.upload({ attributes })
52
53 await waitJobs(servers)
54 })
55
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()
59
60 expect(total).to.equal(0)
61 }
62 })
63
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)
67
68 const videoFromList = data[0]
69 const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid })
70
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)
76 }
77 })
78
79 it('Should wait some seconds and have the video in public privacy', async function () {
80 this.timeout(50000)
81
82 await wait(15000)
83 await waitJobs(servers)
84
85 for (const server of servers) {
86 const { total, data } = await server.videos.list()
87
88 expect(total).to.equal(1)
89 expect(data[0].name).to.equal('video 1')
90 }
91 })
92
93 it('Should upload a video without scheduling an update', async function () {
94 this.timeout(10000)
95
96 const attributes = {
97 name: 'video 2',
98 privacy: VideoPrivacy.PRIVATE
99 }
100
101 const { uuid } = await servers[0].videos.upload({ attributes })
102 video2UUID = uuid
103
104 await waitJobs(servers)
105 })
106
107 it('Should update a video by scheduling an update', async function () {
108 this.timeout(10000)
109
110 const attributes = {
111 name: 'video 2 updated',
112 scheduleUpdate: {
113 updateAt: in10Seconds().toISOString(),
114 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
115 }
116 }
117
118 await servers[0].videos.update({ id: video2UUID, attributes })
119 await waitJobs(servers)
120 })
121
122 it('Should not display the updated video', async function () {
123 for (const server of servers) {
124 const { total } = await server.videos.list()
125
126 expect(total).to.equal(1)
127 }
128 })
129
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)
133
134 const video = data.find(v => v.uuid === video2UUID)
135 expect(video).not.to.be.undefined
136
137 expect(video.name).to.equal('video 2 updated')
138 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
139
140 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
141 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
142 })
143
144 it('Should wait some seconds and have the updated video in public privacy', async function () {
145 this.timeout(20000)
146
147 await wait(15000)
148 await waitJobs(servers)
149
150 for (const server of servers) {
151 const { total, data } = await server.videos.list()
152 expect(total).to.equal(2)
153
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')
157 }
158 })
159
160 after(async function () {
161 await cleanupTests(servers)
162 })
163 })