]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-schedule-update.ts
Add ability for uploaders to schedule video update
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-schedule-update.ts
CommitLineData
2baea0c7
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { VideoPrivacy } from '../../../../shared/models/videos'
6import {
7 doubleFollow,
8 flushAndRunMultipleServers, getMyVideos,
9 getVideosList,
10 killallServers,
11 ServerInfo,
12 setAccessTokensToServers, updateVideo,
13 uploadVideo,
14 wait
15} from '../../utils'
16import { join } from 'path'
17import { waitJobs } from '../../utils/server/jobs'
18
19const expect = chai.expect
20
21function in10Seconds () {
22 const now = new Date()
23 now.setSeconds(now.getSeconds() + 10)
24
25 return now
26}
27
28describe('Test video update scheduler', function () {
29 let servers: ServerInfo[] = []
30 let video2UUID: string
31
32 before(async function () {
33 this.timeout(30000)
34
35 // Run servers
36 servers = await flushAndRunMultipleServers(2)
37
38 await setAccessTokensToServers(servers)
39
40 await doubleFollow(servers[0], servers[1])
41 })
42
43 it('Should upload a video and schedule an update in 10 seconds', async function () {
44 this.timeout(10000)
45
46 const videoAttributes = {
47 name: 'video 1',
48 privacy: VideoPrivacy.PRIVATE,
49 scheduleUpdate: {
50 updateAt: in10Seconds().toISOString(),
51 privacy: VideoPrivacy.PUBLIC
52 }
53 }
54
55 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
56
57 await waitJobs(servers)
58 })
59
60 it('Should not list the video (in privacy mode)', async function () {
61 for (const server of servers) {
62 const res = await getVideosList(server.url)
63
64 expect(res.body.total).to.equal(0)
65 }
66 })
67
68 it('Should have my scheduled video in my account videos', async function () {
69 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
70 expect(res.body.total).to.equal(1)
71
72 const video = res.body.data[0]
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)
77 })
78
79 it('Should wait some seconds and have the video in public privacy', async function () {
80 this.timeout(20000)
81
82 await wait(10000)
83 await waitJobs(servers)
84
85 for (const server of servers) {
86 const res = await getVideosList(server.url)
87
88 expect(res.body.total).to.equal(1)
89 expect(res.body.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 videoAttributes = {
97 name: 'video 2',
98 privacy: VideoPrivacy.PRIVATE
99 }
100
101 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
102 video2UUID = res.body.video.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 videoAttributes = {
111 name: 'video 2 updated',
112 scheduleUpdate: {
113 updateAt: in10Seconds().toISOString(),
114 privacy: VideoPrivacy.PUBLIC
115 }
116 }
117
118 await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes)
119 await waitJobs(servers)
120 })
121
122 it('Should not display the updated video', async function () {
123 for (const server of servers) {
124 const res = await getVideosList(server.url)
125
126 expect(res.body.total).to.equal(1)
127 }
128 })
129
130 it('Should have my scheduled updated video in my account videos', async function () {
131 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
132 expect(res.body.total).to.equal(2)
133
134 const video = res.body.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(10000)
148 await waitJobs(servers)
149
150 for (const server of servers) {
151 const res = await getVideosList(server.url)
152
153 expect(res.body.total).to.equal(2)
154
155 const video = res.body.data.find(v => v.uuid === video2UUID)
156 expect(video).not.to.be.undefined
157 expect(video.name).to.equal('video 2 updated')
158 }
159 })
160
161 after(async function () {
162 killallServers(servers)
163 })
164})