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