diff options
Diffstat (limited to 'server/tests/api/videos/single-server.ts')
-rw-r--r-- | server/tests/api/videos/single-server.ts | 286 |
1 files changed, 124 insertions, 162 deletions
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 1058a1e9c..c0535be09 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts | |||
@@ -2,43 +2,26 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { keyBy } from 'lodash' | ||
6 | |||
7 | import { | 5 | import { |
8 | checkVideoFilesWereRemoved, | 6 | checkVideoFilesWereRemoved, |
9 | cleanupTests, | 7 | cleanupTests, |
10 | completeVideoCheck, | 8 | completeVideoCheck, |
11 | flushAndRunServer, | 9 | createSingleServer, |
12 | getVideo, | 10 | PeerTubeServer, |
13 | getVideoCategories, | ||
14 | getVideoLanguages, | ||
15 | getVideoLicences, | ||
16 | getVideoPrivacies, | ||
17 | getVideosList, | ||
18 | getVideosListPagination, | ||
19 | getVideosListSort, | ||
20 | getVideosWithFilters, | ||
21 | rateVideo, | ||
22 | removeVideo, | ||
23 | ServerInfo, | ||
24 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
25 | testImage, | 12 | testImage, |
26 | updateVideo, | ||
27 | uploadVideo, | ||
28 | viewVideo, | ||
29 | wait | 13 | wait |
30 | } from '../../../../shared/extra-utils' | 14 | } from '@shared/extra-utils' |
31 | import { VideoPrivacy } from '../../../../shared/models/videos' | 15 | import { Video, VideoPrivacy } from '@shared/models' |
32 | import { HttpStatusCode } from '@shared/core-utils' | ||
33 | 16 | ||
34 | const expect = chai.expect | 17 | const expect = chai.expect |
35 | 18 | ||
36 | describe('Test a single server', function () { | 19 | describe('Test a single server', function () { |
37 | 20 | ||
38 | function runSuite (mode: 'legacy' | 'resumable') { | 21 | function runSuite (mode: 'legacy' | 'resumable') { |
39 | let server: ServerInfo = null | 22 | let server: PeerTubeServer = null |
40 | let videoId = -1 | 23 | let videoId: number | string |
41 | let videoId2 = -1 | 24 | let videoId2: string |
42 | let videoUUID = '' | 25 | let videoUUID = '' |
43 | let videosListBase: any[] = null | 26 | let videosListBase: any[] = null |
44 | 27 | ||
@@ -111,134 +94,122 @@ describe('Test a single server', function () { | |||
111 | before(async function () { | 94 | before(async function () { |
112 | this.timeout(30000) | 95 | this.timeout(30000) |
113 | 96 | ||
114 | server = await flushAndRunServer(1) | 97 | server = await createSingleServer(1) |
115 | 98 | ||
116 | await setAccessTokensToServers([ server ]) | 99 | await setAccessTokensToServers([ server ]) |
117 | }) | 100 | }) |
118 | 101 | ||
119 | it('Should list video categories', async function () { | 102 | it('Should list video categories', async function () { |
120 | const res = await getVideoCategories(server.url) | 103 | const categories = await server.videos.getCategories() |
121 | |||
122 | const categories = res.body | ||
123 | expect(Object.keys(categories)).to.have.length.above(10) | 104 | expect(Object.keys(categories)).to.have.length.above(10) |
124 | 105 | ||
125 | expect(categories[11]).to.equal('News & Politics') | 106 | expect(categories[11]).to.equal('News & Politics') |
126 | }) | 107 | }) |
127 | 108 | ||
128 | it('Should list video licences', async function () { | 109 | it('Should list video licences', async function () { |
129 | const res = await getVideoLicences(server.url) | 110 | const licences = await server.videos.getLicences() |
130 | |||
131 | const licences = res.body | ||
132 | expect(Object.keys(licences)).to.have.length.above(5) | 111 | expect(Object.keys(licences)).to.have.length.above(5) |
133 | 112 | ||
134 | expect(licences[3]).to.equal('Attribution - No Derivatives') | 113 | expect(licences[3]).to.equal('Attribution - No Derivatives') |
135 | }) | 114 | }) |
136 | 115 | ||
137 | it('Should list video languages', async function () { | 116 | it('Should list video languages', async function () { |
138 | const res = await getVideoLanguages(server.url) | 117 | const languages = await server.videos.getLanguages() |
139 | |||
140 | const languages = res.body | ||
141 | expect(Object.keys(languages)).to.have.length.above(5) | 118 | expect(Object.keys(languages)).to.have.length.above(5) |
142 | 119 | ||
143 | expect(languages['ru']).to.equal('Russian') | 120 | expect(languages['ru']).to.equal('Russian') |
144 | }) | 121 | }) |
145 | 122 | ||
146 | it('Should list video privacies', async function () { | 123 | it('Should list video privacies', async function () { |
147 | const res = await getVideoPrivacies(server.url) | 124 | const privacies = await server.videos.getPrivacies() |
148 | |||
149 | const privacies = res.body | ||
150 | expect(Object.keys(privacies)).to.have.length.at.least(3) | 125 | expect(Object.keys(privacies)).to.have.length.at.least(3) |
151 | 126 | ||
152 | expect(privacies[3]).to.equal('Private') | 127 | expect(privacies[3]).to.equal('Private') |
153 | }) | 128 | }) |
154 | 129 | ||
155 | it('Should not have videos', async function () { | 130 | it('Should not have videos', async function () { |
156 | const res = await getVideosList(server.url) | 131 | const { data, total } = await server.videos.list() |
157 | 132 | ||
158 | expect(res.body.total).to.equal(0) | 133 | expect(total).to.equal(0) |
159 | expect(res.body.data).to.be.an('array') | 134 | expect(data).to.be.an('array') |
160 | expect(res.body.data.length).to.equal(0) | 135 | expect(data.length).to.equal(0) |
161 | }) | 136 | }) |
162 | 137 | ||
163 | it('Should upload the video', async function () { | 138 | it('Should upload the video', async function () { |
164 | this.timeout(10000) | 139 | this.timeout(10000) |
165 | 140 | ||
166 | const videoAttributes = { | 141 | const attributes = { |
167 | name: 'my super name', | 142 | name: 'my super name', |
168 | category: 2, | 143 | category: 2, |
169 | nsfw: true, | 144 | nsfw: true, |
170 | licence: 6, | 145 | licence: 6, |
171 | tags: [ 'tag1', 'tag2', 'tag3' ] | 146 | tags: [ 'tag1', 'tag2', 'tag3' ] |
172 | } | 147 | } |
173 | const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) | 148 | const video = await server.videos.upload({ attributes, mode }) |
174 | expect(res.body.video).to.not.be.undefined | 149 | expect(video).to.not.be.undefined |
175 | expect(res.body.video.id).to.equal(1) | 150 | expect(video.id).to.equal(1) |
176 | expect(res.body.video.uuid).to.have.length.above(5) | 151 | expect(video.uuid).to.have.length.above(5) |
177 | 152 | ||
178 | videoId = res.body.video.id | 153 | videoId = video.id |
179 | videoUUID = res.body.video.uuid | 154 | videoUUID = video.uuid |
180 | }) | 155 | }) |
181 | 156 | ||
182 | it('Should get and seed the uploaded video', async function () { | 157 | it('Should get and seed the uploaded video', async function () { |
183 | this.timeout(5000) | 158 | this.timeout(5000) |
184 | 159 | ||
185 | const res = await getVideosList(server.url) | 160 | const { data, total } = await server.videos.list() |
186 | 161 | ||
187 | expect(res.body.total).to.equal(1) | 162 | expect(total).to.equal(1) |
188 | expect(res.body.data).to.be.an('array') | 163 | expect(data).to.be.an('array') |
189 | expect(res.body.data.length).to.equal(1) | 164 | expect(data.length).to.equal(1) |
190 | 165 | ||
191 | const video = res.body.data[0] | 166 | const video = data[0] |
192 | await completeVideoCheck(server.url, video, getCheckAttributes()) | 167 | await completeVideoCheck(server, video, getCheckAttributes()) |
193 | }) | 168 | }) |
194 | 169 | ||
195 | it('Should get the video by UUID', async function () { | 170 | it('Should get the video by UUID', async function () { |
196 | this.timeout(5000) | 171 | this.timeout(5000) |
197 | 172 | ||
198 | const res = await getVideo(server.url, videoUUID) | 173 | const video = await server.videos.get({ id: videoUUID }) |
199 | 174 | await completeVideoCheck(server, video, getCheckAttributes()) | |
200 | const video = res.body | ||
201 | await completeVideoCheck(server.url, video, getCheckAttributes()) | ||
202 | }) | 175 | }) |
203 | 176 | ||
204 | it('Should have the views updated', async function () { | 177 | it('Should have the views updated', async function () { |
205 | this.timeout(20000) | 178 | this.timeout(20000) |
206 | 179 | ||
207 | await viewVideo(server.url, videoId) | 180 | await server.videos.view({ id: videoId }) |
208 | await viewVideo(server.url, videoId) | 181 | await server.videos.view({ id: videoId }) |
209 | await viewVideo(server.url, videoId) | 182 | await server.videos.view({ id: videoId }) |
210 | 183 | ||
211 | await wait(1500) | 184 | await wait(1500) |
212 | 185 | ||
213 | await viewVideo(server.url, videoId) | 186 | await server.videos.view({ id: videoId }) |
214 | await viewVideo(server.url, videoId) | 187 | await server.videos.view({ id: videoId }) |
215 | 188 | ||
216 | await wait(1500) | 189 | await wait(1500) |
217 | 190 | ||
218 | await viewVideo(server.url, videoId) | 191 | await server.videos.view({ id: videoId }) |
219 | await viewVideo(server.url, videoId) | 192 | await server.videos.view({ id: videoId }) |
220 | 193 | ||
221 | // Wait the repeatable job | 194 | // Wait the repeatable job |
222 | await wait(8000) | 195 | await wait(8000) |
223 | 196 | ||
224 | const res = await getVideo(server.url, videoId) | 197 | const video = await server.videos.get({ id: videoId }) |
225 | |||
226 | const video = res.body | ||
227 | expect(video.views).to.equal(3) | 198 | expect(video.views).to.equal(3) |
228 | }) | 199 | }) |
229 | 200 | ||
230 | it('Should remove the video', async function () { | 201 | it('Should remove the video', async function () { |
231 | await removeVideo(server.url, server.accessToken, videoId) | 202 | await server.videos.remove({ id: videoId }) |
232 | 203 | ||
233 | await checkVideoFilesWereRemoved(videoUUID, 1) | 204 | await checkVideoFilesWereRemoved(videoUUID, server) |
234 | }) | 205 | }) |
235 | 206 | ||
236 | it('Should not have videos', async function () { | 207 | it('Should not have videos', async function () { |
237 | const res = await getVideosList(server.url) | 208 | const { total, data } = await server.videos.list() |
238 | 209 | ||
239 | expect(res.body.total).to.equal(0) | 210 | expect(total).to.equal(0) |
240 | expect(res.body.data).to.be.an('array') | 211 | expect(data).to.be.an('array') |
241 | expect(res.body.data).to.have.lengthOf(0) | 212 | expect(data).to.have.lengthOf(0) |
242 | }) | 213 | }) |
243 | 214 | ||
244 | it('Should upload 6 videos', async function () { | 215 | it('Should upload 6 videos', async function () { |
@@ -250,7 +221,7 @@ describe('Test a single server', function () { | |||
250 | ]) | 221 | ]) |
251 | 222 | ||
252 | for (const video of videos) { | 223 | for (const video of videos) { |
253 | const videoAttributes = { | 224 | const attributes = { |
254 | name: video + ' name', | 225 | name: video + ' name', |
255 | description: video + ' description', | 226 | description: video + ' description', |
256 | category: 2, | 227 | category: 2, |
@@ -261,19 +232,20 @@ describe('Test a single server', function () { | |||
261 | fixture: video | 232 | fixture: video |
262 | } | 233 | } |
263 | 234 | ||
264 | await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) | 235 | await server.videos.upload({ attributes, mode }) |
265 | } | 236 | } |
266 | }) | 237 | }) |
267 | 238 | ||
268 | it('Should have the correct durations', async function () { | 239 | it('Should have the correct durations', async function () { |
269 | const res = await getVideosList(server.url) | 240 | const { total, data } = await server.videos.list() |
241 | |||
242 | expect(total).to.equal(6) | ||
243 | expect(data).to.be.an('array') | ||
244 | expect(data).to.have.lengthOf(6) | ||
270 | 245 | ||
271 | expect(res.body.total).to.equal(6) | 246 | const videosByName: { [ name: string ]: Video } = {} |
272 | const videos = res.body.data | 247 | data.forEach(v => { videosByName[v.name] = v }) |
273 | expect(videos).to.be.an('array') | ||
274 | expect(videos).to.have.lengthOf(6) | ||
275 | 248 | ||
276 | const videosByName = keyBy<{ duration: number }>(videos, 'name') | ||
277 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | 249 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) |
278 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | 250 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) |
279 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | 251 | expect(videosByName['video_short.webm name'].duration).to.equal(5) |
@@ -283,96 +255,87 @@ describe('Test a single server', function () { | |||
283 | }) | 255 | }) |
284 | 256 | ||
285 | it('Should have the correct thumbnails', async function () { | 257 | it('Should have the correct thumbnails', async function () { |
286 | const res = await getVideosList(server.url) | 258 | const { data } = await server.videos.list() |
287 | 259 | ||
288 | const videos = res.body.data | ||
289 | // For the next test | 260 | // For the next test |
290 | videosListBase = videos | 261 | videosListBase = data |
291 | 262 | ||
292 | for (const video of videos) { | 263 | for (const video of data) { |
293 | const videoName = video.name.replace(' name', '') | 264 | const videoName = video.name.replace(' name', '') |
294 | await testImage(server.url, videoName, video.thumbnailPath) | 265 | await testImage(server.url, videoName, video.thumbnailPath) |
295 | } | 266 | } |
296 | }) | 267 | }) |
297 | 268 | ||
298 | it('Should list only the two first videos', async function () { | 269 | it('Should list only the two first videos', async function () { |
299 | const res = await getVideosListPagination(server.url, 0, 2, 'name') | 270 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' }) |
300 | 271 | ||
301 | const videos = res.body.data | 272 | expect(total).to.equal(6) |
302 | expect(res.body.total).to.equal(6) | 273 | expect(data.length).to.equal(2) |
303 | expect(videos.length).to.equal(2) | 274 | expect(data[0].name).to.equal(videosListBase[0].name) |
304 | expect(videos[0].name).to.equal(videosListBase[0].name) | 275 | expect(data[1].name).to.equal(videosListBase[1].name) |
305 | expect(videos[1].name).to.equal(videosListBase[1].name) | ||
306 | }) | 276 | }) |
307 | 277 | ||
308 | it('Should list only the next three videos', async function () { | 278 | it('Should list only the next three videos', async function () { |
309 | const res = await getVideosListPagination(server.url, 2, 3, 'name') | 279 | const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' }) |
310 | 280 | ||
311 | const videos = res.body.data | 281 | expect(total).to.equal(6) |
312 | expect(res.body.total).to.equal(6) | 282 | expect(data.length).to.equal(3) |
313 | expect(videos.length).to.equal(3) | 283 | expect(data[0].name).to.equal(videosListBase[2].name) |
314 | expect(videos[0].name).to.equal(videosListBase[2].name) | 284 | expect(data[1].name).to.equal(videosListBase[3].name) |
315 | expect(videos[1].name).to.equal(videosListBase[3].name) | 285 | expect(data[2].name).to.equal(videosListBase[4].name) |
316 | expect(videos[2].name).to.equal(videosListBase[4].name) | ||
317 | }) | 286 | }) |
318 | 287 | ||
319 | it('Should list the last video', async function () { | 288 | it('Should list the last video', async function () { |
320 | const res = await getVideosListPagination(server.url, 5, 6, 'name') | 289 | const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' }) |
321 | 290 | ||
322 | const videos = res.body.data | 291 | expect(total).to.equal(6) |
323 | expect(res.body.total).to.equal(6) | 292 | expect(data.length).to.equal(1) |
324 | expect(videos.length).to.equal(1) | 293 | expect(data[0].name).to.equal(videosListBase[5].name) |
325 | expect(videos[0].name).to.equal(videosListBase[5].name) | ||
326 | }) | 294 | }) |
327 | 295 | ||
328 | it('Should not have the total field', async function () { | 296 | it('Should not have the total field', async function () { |
329 | const res = await getVideosListPagination(server.url, 5, 6, 'name', true) | 297 | const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true }) |
330 | 298 | ||
331 | const videos = res.body.data | 299 | expect(total).to.not.exist |
332 | expect(res.body.total).to.not.exist | 300 | expect(data.length).to.equal(1) |
333 | expect(videos.length).to.equal(1) | 301 | expect(data[0].name).to.equal(videosListBase[5].name) |
334 | expect(videos[0].name).to.equal(videosListBase[5].name) | ||
335 | }) | 302 | }) |
336 | 303 | ||
337 | it('Should list and sort by name in descending order', async function () { | 304 | it('Should list and sort by name in descending order', async function () { |
338 | const res = await getVideosListSort(server.url, '-name') | 305 | const { total, data } = await server.videos.list({ sort: '-name' }) |
339 | 306 | ||
340 | const videos = res.body.data | 307 | expect(total).to.equal(6) |
341 | expect(res.body.total).to.equal(6) | 308 | expect(data.length).to.equal(6) |
342 | expect(videos.length).to.equal(6) | 309 | expect(data[0].name).to.equal('video_short.webm name') |
343 | expect(videos[0].name).to.equal('video_short.webm name') | 310 | expect(data[1].name).to.equal('video_short.ogv name') |
344 | expect(videos[1].name).to.equal('video_short.ogv name') | 311 | expect(data[2].name).to.equal('video_short.mp4 name') |
345 | expect(videos[2].name).to.equal('video_short.mp4 name') | 312 | expect(data[3].name).to.equal('video_short3.webm name') |
346 | expect(videos[3].name).to.equal('video_short3.webm name') | 313 | expect(data[4].name).to.equal('video_short2.webm name') |
347 | expect(videos[4].name).to.equal('video_short2.webm name') | 314 | expect(data[5].name).to.equal('video_short1.webm name') |
348 | expect(videos[5].name).to.equal('video_short1.webm name') | ||
349 | 315 | ||
350 | videoId = videos[3].uuid | 316 | videoId = data[3].uuid |
351 | videoId2 = videos[5].uuid | 317 | videoId2 = data[5].uuid |
352 | }) | 318 | }) |
353 | 319 | ||
354 | it('Should list and sort by trending in descending order', async function () { | 320 | it('Should list and sort by trending in descending order', async function () { |
355 | const res = await getVideosListPagination(server.url, 0, 2, '-trending') | 321 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' }) |
356 | 322 | ||
357 | const videos = res.body.data | 323 | expect(total).to.equal(6) |
358 | expect(res.body.total).to.equal(6) | 324 | expect(data.length).to.equal(2) |
359 | expect(videos.length).to.equal(2) | ||
360 | }) | 325 | }) |
361 | 326 | ||
362 | it('Should list and sort by hotness in descending order', async function () { | 327 | it('Should list and sort by hotness in descending order', async function () { |
363 | const res = await getVideosListPagination(server.url, 0, 2, '-hot') | 328 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' }) |
364 | 329 | ||
365 | const videos = res.body.data | 330 | expect(total).to.equal(6) |
366 | expect(res.body.total).to.equal(6) | 331 | expect(data.length).to.equal(2) |
367 | expect(videos.length).to.equal(2) | ||
368 | }) | 332 | }) |
369 | 333 | ||
370 | it('Should list and sort by best in descending order', async function () { | 334 | it('Should list and sort by best in descending order', async function () { |
371 | const res = await getVideosListPagination(server.url, 0, 2, '-best') | 335 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' }) |
372 | 336 | ||
373 | const videos = res.body.data | 337 | expect(total).to.equal(6) |
374 | expect(res.body.total).to.equal(6) | 338 | expect(data.length).to.equal(2) |
375 | expect(videos.length).to.equal(2) | ||
376 | }) | 339 | }) |
377 | 340 | ||
378 | it('Should update a video', async function () { | 341 | it('Should update a video', async function () { |
@@ -387,67 +350,66 @@ describe('Test a single server', function () { | |||
387 | downloadEnabled: false, | 350 | downloadEnabled: false, |
388 | tags: [ 'tagup1', 'tagup2' ] | 351 | tags: [ 'tagup1', 'tagup2' ] |
389 | } | 352 | } |
390 | await updateVideo(server.url, server.accessToken, videoId, attributes) | 353 | await server.videos.update({ id: videoId, attributes }) |
391 | }) | 354 | }) |
392 | 355 | ||
393 | it('Should filter by tags and category', async function () { | 356 | it('Should filter by tags and category', async function () { |
394 | const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) | 357 | { |
395 | expect(res1.body.total).to.equal(1) | 358 | const { data, total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) |
396 | expect(res1.body.data[0].name).to.equal('my super video updated') | 359 | expect(total).to.equal(1) |
360 | expect(data[0].name).to.equal('my super video updated') | ||
361 | } | ||
397 | 362 | ||
398 | const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) | 363 | { |
399 | expect(res2.body.total).to.equal(0) | 364 | const { total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) |
365 | expect(total).to.equal(0) | ||
366 | } | ||
400 | }) | 367 | }) |
401 | 368 | ||
402 | it('Should have the video updated', async function () { | 369 | it('Should have the video updated', async function () { |
403 | this.timeout(60000) | 370 | this.timeout(60000) |
404 | 371 | ||
405 | const res = await getVideo(server.url, videoId) | 372 | const video = await server.videos.get({ id: videoId }) |
406 | const video = res.body | ||
407 | 373 | ||
408 | await completeVideoCheck(server.url, video, updateCheckAttributes()) | 374 | await completeVideoCheck(server, video, updateCheckAttributes()) |
409 | }) | 375 | }) |
410 | 376 | ||
411 | it('Should update only the tags of a video', async function () { | 377 | it('Should update only the tags of a video', async function () { |
412 | const attributes = { | 378 | const attributes = { |
413 | tags: [ 'supertag', 'tag1', 'tag2' ] | 379 | tags: [ 'supertag', 'tag1', 'tag2' ] |
414 | } | 380 | } |
415 | await updateVideo(server.url, server.accessToken, videoId, attributes) | 381 | await server.videos.update({ id: videoId, attributes }) |
416 | 382 | ||
417 | const res = await getVideo(server.url, videoId) | 383 | const video = await server.videos.get({ id: videoId }) |
418 | const video = res.body | ||
419 | 384 | ||
420 | await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) | 385 | await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes)) |
421 | }) | 386 | }) |
422 | 387 | ||
423 | it('Should update only the description of a video', async function () { | 388 | it('Should update only the description of a video', async function () { |
424 | const attributes = { | 389 | const attributes = { |
425 | description: 'hello everybody' | 390 | description: 'hello everybody' |
426 | } | 391 | } |
427 | await updateVideo(server.url, server.accessToken, videoId, attributes) | 392 | await server.videos.update({ id: videoId, attributes }) |
428 | 393 | ||
429 | const res = await getVideo(server.url, videoId) | 394 | const video = await server.videos.get({ id: videoId }) |
430 | const video = res.body | ||
431 | 395 | ||
432 | const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) | 396 | const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) |
433 | await completeVideoCheck(server.url, video, expectedAttributes) | 397 | await completeVideoCheck(server, video, expectedAttributes) |
434 | }) | 398 | }) |
435 | 399 | ||
436 | it('Should like a video', async function () { | 400 | it('Should like a video', async function () { |
437 | await rateVideo(server.url, server.accessToken, videoId, 'like') | 401 | await server.videos.rate({ id: videoId, rating: 'like' }) |
438 | 402 | ||
439 | const res = await getVideo(server.url, videoId) | 403 | const video = await server.videos.get({ id: videoId }) |
440 | const video = res.body | ||
441 | 404 | ||
442 | expect(video.likes).to.equal(1) | 405 | expect(video.likes).to.equal(1) |
443 | expect(video.dislikes).to.equal(0) | 406 | expect(video.dislikes).to.equal(0) |
444 | }) | 407 | }) |
445 | 408 | ||
446 | it('Should dislike the same video', async function () { | 409 | it('Should dislike the same video', async function () { |
447 | await rateVideo(server.url, server.accessToken, videoId, 'dislike') | 410 | await server.videos.rate({ id: videoId, rating: 'dislike' }) |
448 | 411 | ||
449 | const res = await getVideo(server.url, videoId) | 412 | const video = await server.videos.get({ id: videoId }) |
450 | const video = res.body | ||
451 | 413 | ||
452 | expect(video.likes).to.equal(0) | 414 | expect(video.likes).to.equal(0) |
453 | expect(video.dislikes).to.equal(1) | 415 | expect(video.dislikes).to.equal(1) |
@@ -457,10 +419,10 @@ describe('Test a single server', function () { | |||
457 | { | 419 | { |
458 | const now = new Date() | 420 | const now = new Date() |
459 | const attributes = { originallyPublishedAt: now.toISOString() } | 421 | const attributes = { originallyPublishedAt: now.toISOString() } |
460 | await updateVideo(server.url, server.accessToken, videoId, attributes) | 422 | await server.videos.update({ id: videoId, attributes }) |
461 | 423 | ||
462 | const res = await getVideosListSort(server.url, '-originallyPublishedAt') | 424 | const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) |
463 | const names = res.body.data.map(v => v.name) | 425 | const names = data.map(v => v.name) |
464 | 426 | ||
465 | expect(names[0]).to.equal('my super video updated') | 427 | expect(names[0]).to.equal('my super video updated') |
466 | expect(names[1]).to.equal('video_short2.webm name') | 428 | expect(names[1]).to.equal('video_short2.webm name') |
@@ -473,10 +435,10 @@ describe('Test a single server', function () { | |||
473 | { | 435 | { |
474 | const now = new Date() | 436 | const now = new Date() |
475 | const attributes = { originallyPublishedAt: now.toISOString() } | 437 | const attributes = { originallyPublishedAt: now.toISOString() } |
476 | await updateVideo(server.url, server.accessToken, videoId2, attributes) | 438 | await server.videos.update({ id: videoId2, attributes }) |
477 | 439 | ||
478 | const res = await getVideosListSort(server.url, '-originallyPublishedAt') | 440 | const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) |
479 | const names = res.body.data.map(v => v.name) | 441 | const names = data.map(v => v.name) |
480 | 442 | ||
481 | expect(names[0]).to.equal('video_short1.webm name') | 443 | expect(names[0]).to.equal('video_short1.webm name') |
482 | expect(names[1]).to.equal('my super video updated') | 444 | expect(names[1]).to.equal('my super video updated') |