1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoPrivacy } from '../../../../shared/models/videos'
8 flushAndRunMultipleServers, getMyVideos,
12 setAccessTokensToServers, updateVideo,
16 import { join } from 'path'
17 import { waitJobs } from '../../utils/server/jobs'
19 const expect = chai.expect
21 function in10Seconds () {
22 const now = new Date()
23 now.setSeconds(now.getSeconds() + 10)
28 describe('Test video update scheduler', function () {
29 let servers: ServerInfo[] = []
30 let video2UUID: string
32 before(async function () {
36 servers = await flushAndRunMultipleServers(2)
38 await setAccessTokensToServers(servers)
40 await doubleFollow(servers[0], servers[1])
43 it('Should upload a video and schedule an update in 10 seconds', async function () {
46 const videoAttributes = {
48 privacy: VideoPrivacy.PRIVATE,
50 updateAt: in10Seconds().toISOString(),
51 privacy: VideoPrivacy.PUBLIC
55 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
57 await waitJobs(servers)
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)
64 expect(res.body.total).to.equal(0)
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)
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)
79 it('Should wait some seconds and have the video in public privacy', async function () {
83 await waitJobs(servers)
85 for (const server of servers) {
86 const res = await getVideosList(server.url)
88 expect(res.body.total).to.equal(1)
89 expect(res.body.data[0].name).to.equal('video 1')
93 it('Should upload a video without scheduling an update', async function () {
96 const videoAttributes = {
98 privacy: VideoPrivacy.PRIVATE
101 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
102 video2UUID = res.body.video.uuid
104 await waitJobs(servers)
107 it('Should update a video by scheduling an update', async function () {
110 const videoAttributes = {
111 name: 'video 2 updated',
113 updateAt: in10Seconds().toISOString(),
114 privacy: VideoPrivacy.PUBLIC
118 await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes)
119 await waitJobs(servers)
122 it('Should not display the updated video', async function () {
123 for (const server of servers) {
124 const res = await getVideosList(server.url)
126 expect(res.body.total).to.equal(1)
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)
134 const video = res.body.data.find(v => v.uuid === video2UUID)
135 expect(video).not.to.be.undefined
137 expect(video.name).to.equal('video 2 updated')
138 expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
140 expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
141 expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
144 it('Should wait some seconds and have the updated video in public privacy', async function () {
148 await waitJobs(servers)
150 for (const server of servers) {
151 const res = await getVideosList(server.url)
153 expect(res.body.total).to.equal(2)
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')
161 after(async function () {
162 killallServers(servers)