2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2022-08-17 09:44:32 -04:00
|
|
|
import { expect } from 'chai'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { wait } from '@shared/core-utils'
|
|
|
|
import { VideoPrivacy } from '@shared/models'
|
2018-06-14 12:06:56 -04:00
|
|
|
import {
|
2019-04-24 09:10:37 -04:00
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createMultipleServers,
|
2021-07-16 08:27:30 -04:00
|
|
|
doubleFollow,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2018-06-15 10:52:15 -04:00
|
|
|
setAccessTokensToServers,
|
2021-07-15 04:02:54 -04:00
|
|
|
waitJobs
|
2021-12-17 03:29:23 -05:00
|
|
|
} from '@shared/server-commands'
|
2018-06-14 12:06:56 -04:00
|
|
|
|
|
|
|
function in10Seconds () {
|
|
|
|
const now = new Date()
|
|
|
|
now.setSeconds(now.getSeconds() + 10)
|
|
|
|
|
|
|
|
return now
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test video update scheduler', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let servers: PeerTubeServer[] = []
|
2018-06-14 12:06:56 -04:00
|
|
|
let video2UUID: string
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
// Run servers
|
2021-07-16 03:47:51 -04:00
|
|
|
servers = await createMultipleServers(2)
|
2018-06-14 12:06:56 -04:00
|
|
|
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload a video and schedule an update in 10 seconds', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
const attributes = {
|
2018-06-14 12:06:56 -04:00
|
|
|
name: 'video 1',
|
|
|
|
privacy: VideoPrivacy.PRIVATE,
|
|
|
|
scheduleUpdate: {
|
|
|
|
updateAt: in10Seconds().toISOString(),
|
2021-07-15 04:02:54 -04:00
|
|
|
privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
|
2018-06-14 12:06:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].videos.upload({ attributes })
|
2018-06-14 12:06:56 -04:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not list the video (in privacy mode)', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await server.videos.list()
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(0)
|
2018-06-14 12:06:56 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have my scheduled video in my account videos', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total, data } = await servers[0].videos.listMyVideos()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(1)
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
const videoFromList = data[0]
|
2021-07-16 03:04:35 -04:00
|
|
|
const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid })
|
2018-06-15 10:52:15 -04:00
|
|
|
|
|
|
|
for (const video of [ videoFromList, videoFromGet ]) {
|
|
|
|
expect(video.name).to.equal('video 1')
|
|
|
|
expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
|
|
|
|
expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
|
|
|
|
expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
|
|
|
|
}
|
2018-06-14 12:06:56 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should wait some seconds and have the video in public privacy', async function () {
|
2019-07-29 05:59:29 -04:00
|
|
|
this.timeout(50000)
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2018-06-15 10:52:15 -04:00
|
|
|
await wait(15000)
|
2018-06-14 12:06:56 -04:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total, data } = await server.videos.list()
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data[0].name).to.equal('video 1')
|
2018-06-14 12:06:56 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload a video without scheduling an update', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
const attributes = {
|
2018-06-14 12:06:56 -04:00
|
|
|
name: 'video 2',
|
|
|
|
privacy: VideoPrivacy.PRIVATE
|
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const { uuid } = await servers[0].videos.upload({ attributes })
|
2021-07-15 04:02:54 -04:00
|
|
|
video2UUID = uuid
|
2018-06-14 12:06:56 -04:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should update a video by scheduling an update', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
const attributes = {
|
2018-06-14 12:06:56 -04:00
|
|
|
name: 'video 2 updated',
|
|
|
|
scheduleUpdate: {
|
|
|
|
updateAt: in10Seconds().toISOString(),
|
2021-07-15 04:02:54 -04:00
|
|
|
privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
|
2018-06-14 12:06:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].videos.update({ id: video2UUID, attributes })
|
2018-06-14 12:06:56 -04:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not display the updated video', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await server.videos.list()
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(1)
|
2018-06-14 12:06:56 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have my scheduled updated video in my account videos', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total, data } = await servers[0].videos.listMyVideos()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(2)
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
const video = data.find(v => v.uuid === video2UUID)
|
2018-06-14 12:06:56 -04:00
|
|
|
expect(video).not.to.be.undefined
|
|
|
|
|
|
|
|
expect(video.name).to.equal('video 2 updated')
|
|
|
|
expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE)
|
|
|
|
|
|
|
|
expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date())
|
|
|
|
expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should wait some seconds and have the updated video in public privacy', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2018-06-15 10:52:15 -04:00
|
|
|
await wait(15000)
|
2018-06-14 12:06:56 -04:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total, data } = await server.videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(2)
|
2018-06-14 12:06:56 -04:00
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
const video = data.find(v => v.uuid === video2UUID)
|
2018-06-14 12:06:56 -04:00
|
|
|
expect(video).not.to.be.undefined
|
|
|
|
expect(video.name).to.equal('video 2 updated')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-06-14 12:06:56 -04:00
|
|
|
})
|
|
|
|
})
|