1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoPrivacy } from '../../../../shared/models/videos'
8 flushAndRunMultipleServers,
14 setAccessTokensToServers,
19 import { join } from 'path'
20 import { waitJobs } from '../../utils/server/jobs'
22 const expect = chai.expect
24 function in10Seconds () {
25 const now = new Date()
26 now.setSeconds(now.getSeconds() + 10)
31 describe('Test video update scheduler', function () {
32 let servers: ServerInfo[] = []
33 let video2UUID: string
35 before(async function () {
39 servers = await flushAndRunMultipleServers(2)
41 await setAccessTokensToServers(servers)
43 await doubleFollow(servers[0], servers[1])
46 it('Should upload a video and schedule an update in 10 seconds', async function () {
49 const videoAttributes = {
51 privacy: VideoPrivacy.PRIVATE,
53 updateAt: in10Seconds().toISOString(),
54 privacy: VideoPrivacy.PUBLIC
58 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
60 await waitJobs(servers)
63 it('Should not list the video (in privacy mode)', async function () {
64 for (const server of servers) {
65 const res = await getVideosList(server.url)
67 expect(res.body.total).to.equal(0)
71 it('Should have my scheduled video in my account videos', async function () {
72 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
73 expect(res.body.total).to.equal(1)
75 const videoFromList = res.body.data[0]
76 const res2 = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoFromList.uuid)
77 const videoFromGet = res2.body
79 for (const video of [ videoFromList, videoFromGet ]) {
80 expect(video.name).to.equal('video 1')
81 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
82 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
83 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
87 it('Should wait some seconds and have the video in public privacy', async function () {
91 await waitJobs(servers)
93 for (const server of servers) {
94 const res = await getVideosList(server.url)
96 expect(res.body.total).to.equal(1)
97 expect(res.body.data[0].name).to.equal('video 1')
101 it('Should upload a video without scheduling an update', async function () {
104 const videoAttributes = {
106 privacy: VideoPrivacy.PRIVATE
109 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
110 video2UUID = res.body.video.uuid
112 await waitJobs(servers)
115 it('Should update a video by scheduling an update', async function () {
118 const videoAttributes = {
119 name: 'video 2 updated',
121 updateAt: in10Seconds().toISOString(),
122 privacy: VideoPrivacy.PUBLIC
126 await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes)
127 await waitJobs(servers)
130 it('Should not display the updated video', async function () {
131 for (const server of servers) {
132 const res = await getVideosList(server.url)
134 expect(res.body.total).to.equal(1)
138 it('Should have my scheduled updated video in my account videos', async function () {
139 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
140 expect(res.body.total).to.equal(2)
142 const video = res.body.data.find(v => v.uuid === video2UUID)
143 expect(video).not.to.be.undefined
145 expect(video.name).to.equal('video 2 updated')
146 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
148 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
149 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
152 it('Should wait some seconds and have the updated video in public privacy', async function () {
156 await waitJobs(servers)
158 for (const server of servers) {
159 const res = await getVideosList(server.url)
161 expect(res.body.total).to.equal(2)
163 const video = res.body.data.find(v => v.uuid === video2UUID)
164 expect(video).not.to.be.undefined
165 expect(video.name).to.equal('video 2 updated')
169 after(async function () {
170 killallServers(servers)