diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-14 18:06:56 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-14 18:06:56 +0200 |
commit | 2baea0c77cc765f7cbca9c9a2f4272268892a35c (patch) | |
tree | 47b1be5535439409a97eb80c0222c9c821b83dae /server/tests | |
parent | bf079b7bfd7f0fb75ceb28e333bb4b74d8840dd4 (diff) | |
download | PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.tar.gz PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.tar.zst PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.zip |
Add ability for uploaders to schedule video update
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/index-slow.ts | 1 | ||||
-rw-r--r-- | server/tests/api/videos/video-schedule-update.ts | 164 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 13 |
3 files changed, 178 insertions, 0 deletions
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts index cde546856..d987442b3 100644 --- a/server/tests/api/index-slow.ts +++ b/server/tests/api/index-slow.ts | |||
@@ -6,3 +6,4 @@ import './server/jobs' | |||
6 | import './videos/video-comments' | 6 | import './videos/video-comments' |
7 | import './users/users-multiple-servers' | 7 | import './users/users-multiple-servers' |
8 | import './server/handle-down' | 8 | import './server/handle-down' |
9 | import './videos/video-schedule-update' | ||
diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts new file mode 100644 index 000000000..8b87ea855 --- /dev/null +++ b/server/tests/api/videos/video-schedule-update.ts | |||
@@ -0,0 +1,164 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
6 | import { | ||
7 | doubleFollow, | ||
8 | flushAndRunMultipleServers, getMyVideos, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers, updateVideo, | ||
13 | uploadVideo, | ||
14 | wait | ||
15 | } from '../../utils' | ||
16 | import { join } from 'path' | ||
17 | import { waitJobs } from '../../utils/server/jobs' | ||
18 | |||
19 | const expect = chai.expect | ||
20 | |||
21 | function in10Seconds () { | ||
22 | const now = new Date() | ||
23 | now.setSeconds(now.getSeconds() + 10) | ||
24 | |||
25 | return now | ||
26 | } | ||
27 | |||
28 | describe('Test video update scheduler', function () { | ||
29 | let servers: ServerInfo[] = [] | ||
30 | let video2UUID: string | ||
31 | |||
32 | before(async function () { | ||
33 | this.timeout(30000) | ||
34 | |||
35 | // Run servers | ||
36 | servers = await flushAndRunMultipleServers(2) | ||
37 | |||
38 | await setAccessTokensToServers(servers) | ||
39 | |||
40 | await doubleFollow(servers[0], servers[1]) | ||
41 | }) | ||
42 | |||
43 | it('Should upload a video and schedule an update in 10 seconds', async function () { | ||
44 | this.timeout(10000) | ||
45 | |||
46 | const videoAttributes = { | ||
47 | name: 'video 1', | ||
48 | privacy: VideoPrivacy.PRIVATE, | ||
49 | scheduleUpdate: { | ||
50 | updateAt: in10Seconds().toISOString(), | ||
51 | privacy: VideoPrivacy.PUBLIC | ||
52 | } | ||
53 | } | ||
54 | |||
55 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | ||
56 | |||
57 | await waitJobs(servers) | ||
58 | }) | ||
59 | |||
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) | ||
63 | |||
64 | expect(res.body.total).to.equal(0) | ||
65 | } | ||
66 | }) | ||
67 | |||
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) | ||
71 | |||
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) | ||
77 | }) | ||
78 | |||
79 | it('Should wait some seconds and have the video in public privacy', async function () { | ||
80 | this.timeout(20000) | ||
81 | |||
82 | await wait(10000) | ||
83 | await waitJobs(servers) | ||
84 | |||
85 | for (const server of servers) { | ||
86 | const res = await getVideosList(server.url) | ||
87 | |||
88 | expect(res.body.total).to.equal(1) | ||
89 | expect(res.body.data[0].name).to.equal('video 1') | ||
90 | } | ||
91 | }) | ||
92 | |||
93 | it('Should upload a video without scheduling an update', async function () { | ||
94 | this.timeout(10000) | ||
95 | |||
96 | const videoAttributes = { | ||
97 | name: 'video 2', | ||
98 | privacy: VideoPrivacy.PRIVATE | ||
99 | } | ||
100 | |||
101 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | ||
102 | video2UUID = res.body.video.uuid | ||
103 | |||
104 | await waitJobs(servers) | ||
105 | }) | ||
106 | |||
107 | it('Should update a video by scheduling an update', async function () { | ||
108 | this.timeout(10000) | ||
109 | |||
110 | const videoAttributes = { | ||
111 | name: 'video 2 updated', | ||
112 | scheduleUpdate: { | ||
113 | updateAt: in10Seconds().toISOString(), | ||
114 | privacy: VideoPrivacy.PUBLIC | ||
115 | } | ||
116 | } | ||
117 | |||
118 | await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes) | ||
119 | await waitJobs(servers) | ||
120 | }) | ||
121 | |||
122 | it('Should not display the updated video', async function () { | ||
123 | for (const server of servers) { | ||
124 | const res = await getVideosList(server.url) | ||
125 | |||
126 | expect(res.body.total).to.equal(1) | ||
127 | } | ||
128 | }) | ||
129 | |||
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) | ||
133 | |||
134 | const video = res.body.data.find(v => v.uuid === video2UUID) | ||
135 | expect(video).not.to.be.undefined | ||
136 | |||
137 | expect(video.name).to.equal('video 2 updated') | ||
138 | expect(video.privacy.id).to.equal(VideoPrivacy.PRIVATE) | ||
139 | |||
140 | expect(new Date(video.scheduledUpdate.updateAt)).to.be.above(new Date()) | ||
141 | expect(video.scheduledUpdate.privacy).to.equal(VideoPrivacy.PUBLIC) | ||
142 | }) | ||
143 | |||
144 | it('Should wait some seconds and have the updated video in public privacy', async function () { | ||
145 | this.timeout(20000) | ||
146 | |||
147 | await wait(10000) | ||
148 | await waitJobs(servers) | ||
149 | |||
150 | for (const server of servers) { | ||
151 | const res = await getVideosList(server.url) | ||
152 | |||
153 | expect(res.body.total).to.equal(2) | ||
154 | |||
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') | ||
158 | } | ||
159 | }) | ||
160 | |||
161 | after(async function () { | ||
162 | killallServers(servers) | ||
163 | }) | ||
164 | }) | ||
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 2c1d20ef1..4f7ce6d6b 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts | |||
@@ -35,6 +35,10 @@ type VideoAttributes = { | |||
35 | fixture?: string | 35 | fixture?: string |
36 | thumbnailfile?: string | 36 | thumbnailfile?: string |
37 | previewfile?: string | 37 | previewfile?: string |
38 | scheduleUpdate?: { | ||
39 | updateAt: string | ||
40 | privacy?: VideoPrivacy | ||
41 | } | ||
38 | } | 42 | } |
39 | 43 | ||
40 | function getVideoCategories (url: string) { | 44 | function getVideoCategories (url: string) { |
@@ -371,6 +375,14 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
371 | req.attach('previewfile', buildAbsoluteFixturePath(attributes.previewfile)) | 375 | req.attach('previewfile', buildAbsoluteFixturePath(attributes.previewfile)) |
372 | } | 376 | } |
373 | 377 | ||
378 | if (attributes.scheduleUpdate) { | ||
379 | req.field('scheduleUpdate[updateAt]', attributes.scheduleUpdate.updateAt) | ||
380 | |||
381 | if (attributes.scheduleUpdate.privacy) { | ||
382 | req.field('scheduleUpdate[privacy]', attributes.scheduleUpdate.privacy) | ||
383 | } | ||
384 | } | ||
385 | |||
374 | return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) | 386 | return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) |
375 | .expect(specialStatus) | 387 | .expect(specialStatus) |
376 | } | 388 | } |
@@ -389,6 +401,7 @@ function updateVideo (url: string, accessToken: string, id: number | string, att | |||
389 | if (attributes.tags) body['tags'] = attributes.tags | 401 | if (attributes.tags) body['tags'] = attributes.tags |
390 | if (attributes.privacy) body['privacy'] = attributes.privacy | 402 | if (attributes.privacy) body['privacy'] = attributes.privacy |
391 | if (attributes.channelId) body['channelId'] = attributes.channelId | 403 | if (attributes.channelId) body['channelId'] = attributes.channelId |
404 | if (attributes.scheduleUpdate) body['scheduleUpdate'] = attributes.scheduleUpdate | ||
392 | 405 | ||
393 | // Upload request | 406 | // Upload request |
394 | if (attributes.thumbnailfile || attributes.previewfile) { | 407 | if (attributes.thumbnailfile || attributes.previewfile) { |