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