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