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