videos.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import { omit } from 'lodash'
  4. import 'mocha'
  5. import { join } from 'path'
  6. import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
  7. import {
  8. cleanupTests,
  9. createUser,
  10. flushAndRunServer,
  11. getMyUserInformation,
  12. getVideo,
  13. getVideosList,
  14. immutableAssign,
  15. makeDeleteRequest,
  16. makeGetRequest,
  17. makePutBodyRequest,
  18. makeUploadRequest,
  19. removeVideo,
  20. ServerInfo,
  21. setAccessTokensToServers,
  22. userLogin,
  23. root
  24. } from '../../../../shared/extra-utils'
  25. import {
  26. checkBadCountPagination,
  27. checkBadSortPagination,
  28. checkBadStartPagination
  29. } from '../../../../shared/extra-utils/requests/check-api-params'
  30. const expect = chai.expect
  31. describe('Test videos API validator', function () {
  32. const path = '/api/v1/videos/'
  33. let server: ServerInfo
  34. let userAccessToken = ''
  35. let accountName: string
  36. let channelId: number
  37. let channelName: string
  38. let videoId
  39. // ---------------------------------------------------------------
  40. before(async function () {
  41. this.timeout(30000)
  42. server = await flushAndRunServer(1)
  43. await setAccessTokensToServers([ server ])
  44. const username = 'user1'
  45. const password = 'my super password'
  46. await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
  47. userAccessToken = await userLogin(server, { username, password })
  48. {
  49. const res = await getMyUserInformation(server.url, server.accessToken)
  50. channelId = res.body.videoChannels[ 0 ].id
  51. channelName = res.body.videoChannels[ 0 ].name
  52. accountName = res.body.account.name + '@' + res.body.account.host
  53. }
  54. })
  55. describe('When listing videos', function () {
  56. it('Should fail with a bad start pagination', async function () {
  57. await checkBadStartPagination(server.url, path)
  58. })
  59. it('Should fail with a bad count pagination', async function () {
  60. await checkBadCountPagination(server.url, path)
  61. })
  62. it('Should fail with an incorrect sort', async function () {
  63. await checkBadSortPagination(server.url, path)
  64. })
  65. it('Should success with the correct parameters', async function () {
  66. await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
  67. })
  68. })
  69. describe('When searching a video', function () {
  70. it('Should fail with nothing', async function () {
  71. await makeGetRequest({
  72. url: server.url,
  73. path: join(path, 'search'),
  74. statusCodeExpected: 400
  75. })
  76. })
  77. it('Should fail with a bad start pagination', async function () {
  78. await checkBadStartPagination(server.url, join(path, 'search', 'test'))
  79. })
  80. it('Should fail with a bad count pagination', async function () {
  81. await checkBadCountPagination(server.url, join(path, 'search', 'test'))
  82. })
  83. it('Should fail with an incorrect sort', async function () {
  84. await checkBadSortPagination(server.url, join(path, 'search', 'test'))
  85. })
  86. it('Should success with the correct parameters', async function () {
  87. await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
  88. })
  89. })
  90. describe('When listing my videos', function () {
  91. const path = '/api/v1/users/me/videos'
  92. it('Should fail with a bad start pagination', async function () {
  93. await checkBadStartPagination(server.url, path, server.accessToken)
  94. })
  95. it('Should fail with a bad count pagination', async function () {
  96. await checkBadCountPagination(server.url, path, server.accessToken)
  97. })
  98. it('Should fail with an incorrect sort', async function () {
  99. await checkBadSortPagination(server.url, path, server.accessToken)
  100. })
  101. it('Should success with the correct parameters', async function () {
  102. await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
  103. })
  104. })
  105. describe('When listing account videos', function () {
  106. let path: string
  107. before(async function () {
  108. path = '/api/v1/accounts/' + accountName + '/videos'
  109. })
  110. it('Should fail with a bad start pagination', async function () {
  111. await checkBadStartPagination(server.url, path, server.accessToken)
  112. })
  113. it('Should fail with a bad count pagination', async function () {
  114. await checkBadCountPagination(server.url, path, server.accessToken)
  115. })
  116. it('Should fail with an incorrect sort', async function () {
  117. await checkBadSortPagination(server.url, path, server.accessToken)
  118. })
  119. it('Should success with the correct parameters', async function () {
  120. await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
  121. })
  122. })
  123. describe('When listing video channel videos', function () {
  124. let path: string
  125. before(async function () {
  126. path = '/api/v1/video-channels/' + channelName + '/videos'
  127. })
  128. it('Should fail with a bad start pagination', async function () {
  129. await checkBadStartPagination(server.url, path, server.accessToken)
  130. })
  131. it('Should fail with a bad count pagination', async function () {
  132. await checkBadCountPagination(server.url, path, server.accessToken)
  133. })
  134. it('Should fail with an incorrect sort', async function () {
  135. await checkBadSortPagination(server.url, path, server.accessToken)
  136. })
  137. it('Should success with the correct parameters', async function () {
  138. await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
  139. })
  140. })
  141. describe('When adding a video', function () {
  142. let baseCorrectParams
  143. const baseCorrectAttaches = {
  144. 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
  145. }
  146. before(function () {
  147. // Put in before to have channelId
  148. baseCorrectParams = {
  149. name: 'my super name',
  150. category: 5,
  151. licence: 1,
  152. language: 'pt',
  153. nsfw: false,
  154. commentsEnabled: true,
  155. downloadEnabled: true,
  156. waitTranscoding: true,
  157. description: 'my super description',
  158. support: 'my super support text',
  159. tags: [ 'tag1', 'tag2' ],
  160. privacy: VideoPrivacy.PUBLIC,
  161. channelId: channelId,
  162. originallyPublishedAt: new Date().toISOString()
  163. }
  164. })
  165. it('Should fail with nothing', async function () {
  166. const fields = {}
  167. const attaches = {}
  168. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  169. })
  170. it('Should fail without name', async function () {
  171. const fields = omit(baseCorrectParams, 'name')
  172. const attaches = baseCorrectAttaches
  173. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  174. })
  175. it('Should fail with a long name', async function () {
  176. const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
  177. const attaches = baseCorrectAttaches
  178. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  179. })
  180. it('Should fail with a bad category', async function () {
  181. const fields = immutableAssign(baseCorrectParams, { category: 125 })
  182. const attaches = baseCorrectAttaches
  183. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  184. })
  185. it('Should fail with a bad licence', async function () {
  186. const fields = immutableAssign(baseCorrectParams, { licence: 125 })
  187. const attaches = baseCorrectAttaches
  188. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  189. })
  190. it('Should fail with a bad language', async function () {
  191. const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
  192. const attaches = baseCorrectAttaches
  193. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  194. })
  195. it('Should fail with a long description', async function () {
  196. const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
  197. const attaches = baseCorrectAttaches
  198. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  199. })
  200. it('Should fail with a long support text', async function () {
  201. const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
  202. const attaches = baseCorrectAttaches
  203. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  204. })
  205. it('Should fail without a channel', async function () {
  206. const fields = omit(baseCorrectParams, 'channelId')
  207. const attaches = baseCorrectAttaches
  208. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  209. })
  210. it('Should fail with a bad channel', async function () {
  211. const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
  212. const attaches = baseCorrectAttaches
  213. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  214. })
  215. it('Should fail with another user channel', async function () {
  216. const user = {
  217. username: 'fake',
  218. password: 'fake_password'
  219. }
  220. await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
  221. const accessTokenUser = await userLogin(server, user)
  222. const res = await getMyUserInformation(server.url, accessTokenUser)
  223. const customChannelId = res.body.videoChannels[0].id
  224. const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
  225. const attaches = baseCorrectAttaches
  226. await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
  227. })
  228. it('Should fail with too many tags', async function () {
  229. const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
  230. const attaches = baseCorrectAttaches
  231. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  232. })
  233. it('Should fail with a tag length too low', async function () {
  234. const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
  235. const attaches = baseCorrectAttaches
  236. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  237. })
  238. it('Should fail with a tag length too big', async function () {
  239. const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
  240. const attaches = baseCorrectAttaches
  241. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  242. })
  243. it('Should fail with a bad schedule update (miss updateAt)', async function () {
  244. const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
  245. const attaches = baseCorrectAttaches
  246. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  247. })
  248. it('Should fail with a bad schedule update (wrong updateAt)', async function () {
  249. const fields = immutableAssign(baseCorrectParams, {
  250. 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
  251. 'scheduleUpdate[updateAt]': 'toto'
  252. })
  253. const attaches = baseCorrectAttaches
  254. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  255. })
  256. it('Should fail with a bad originally published at attribute', async function () {
  257. const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
  258. const attaches = baseCorrectAttaches
  259. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  260. })
  261. it('Should fail without an input file', async function () {
  262. const fields = baseCorrectParams
  263. const attaches = {}
  264. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  265. })
  266. it('Should fail with an incorrect input file', async function () {
  267. const fields = baseCorrectParams
  268. let attaches = {
  269. 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm')
  270. }
  271. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  272. attaches = {
  273. 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
  274. }
  275. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  276. })
  277. it('Should fail with an incorrect thumbnail file', async function () {
  278. const fields = baseCorrectParams
  279. const attaches = {
  280. 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
  281. 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
  282. }
  283. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  284. })
  285. it('Should fail with a big thumbnail file', async function () {
  286. const fields = baseCorrectParams
  287. const attaches = {
  288. 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
  289. 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
  290. }
  291. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  292. })
  293. it('Should fail with an incorrect preview file', async function () {
  294. const fields = baseCorrectParams
  295. const attaches = {
  296. 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
  297. 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
  298. }
  299. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  300. })
  301. it('Should fail with a big preview file', async function () {
  302. const fields = baseCorrectParams
  303. const attaches = {
  304. 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
  305. 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
  306. }
  307. await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
  308. })
  309. it('Should succeed with the correct parameters', async function () {
  310. this.timeout(10000)
  311. const fields = baseCorrectParams
  312. {
  313. const attaches = baseCorrectAttaches
  314. await makeUploadRequest({
  315. url: server.url,
  316. path: path + '/upload',
  317. token: server.accessToken,
  318. fields,
  319. attaches,
  320. statusCodeExpected: 200
  321. })
  322. }
  323. {
  324. const attaches = immutableAssign(baseCorrectAttaches, {
  325. videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
  326. })
  327. await makeUploadRequest({
  328. url: server.url,
  329. path: path + '/upload',
  330. token: server.accessToken,
  331. fields,
  332. attaches,
  333. statusCodeExpected: 200
  334. })
  335. }
  336. {
  337. const attaches = immutableAssign(baseCorrectAttaches, {
  338. videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
  339. })
  340. await makeUploadRequest({
  341. url: server.url,
  342. path: path + '/upload',
  343. token: server.accessToken,
  344. fields,
  345. attaches,
  346. statusCodeExpected: 200
  347. })
  348. }
  349. })
  350. })
  351. describe('When updating a video', function () {
  352. const baseCorrectParams = {
  353. name: 'my super name',
  354. category: 5,
  355. licence: 2,
  356. language: 'pt',
  357. nsfw: false,
  358. commentsEnabled: false,
  359. downloadEnabled: false,
  360. description: 'my super description',
  361. privacy: VideoPrivacy.PUBLIC,
  362. tags: [ 'tag1', 'tag2' ]
  363. }
  364. before(async function () {
  365. const res = await getVideosList(server.url)
  366. videoId = res.body.data[0].uuid
  367. })
  368. it('Should fail with nothing', async function () {
  369. const fields = {}
  370. await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  371. })
  372. it('Should fail without a valid uuid', async function () {
  373. const fields = baseCorrectParams
  374. await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
  375. })
  376. it('Should fail with an unknown id', async function () {
  377. const fields = baseCorrectParams
  378. await makePutBodyRequest({
  379. url: server.url,
  380. path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
  381. token: server.accessToken,
  382. fields,
  383. statusCodeExpected: 404
  384. })
  385. })
  386. it('Should fail with a long name', async function () {
  387. const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
  388. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  389. })
  390. it('Should fail with a bad category', async function () {
  391. const fields = immutableAssign(baseCorrectParams, { category: 125 })
  392. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  393. })
  394. it('Should fail with a bad licence', async function () {
  395. const fields = immutableAssign(baseCorrectParams, { licence: 125 })
  396. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  397. })
  398. it('Should fail with a bad language', async function () {
  399. const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
  400. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  401. })
  402. it('Should fail with a long description', async function () {
  403. const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
  404. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  405. })
  406. it('Should fail with a long support text', async function () {
  407. const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
  408. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  409. })
  410. it('Should fail with a bad channel', async function () {
  411. const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
  412. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  413. })
  414. it('Should fail with too many tags', async function () {
  415. const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
  416. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  417. })
  418. it('Should fail with a tag length too low', async function () {
  419. const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
  420. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  421. })
  422. it('Should fail with a tag length too big', async function () {
  423. const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
  424. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  425. })
  426. it('Should fail with a bad schedule update (miss updateAt)', async function () {
  427. const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
  428. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  429. })
  430. it('Should fail with a bad schedule update (wrong updateAt)', async function () {
  431. const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
  432. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  433. })
  434. it('Should fail with a bad originally published at param', async function () {
  435. const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
  436. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
  437. })
  438. it('Should fail with an incorrect thumbnail file', async function () {
  439. const fields = baseCorrectParams
  440. const attaches = {
  441. 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
  442. }
  443. await makeUploadRequest({
  444. url: server.url,
  445. method: 'PUT',
  446. path: path + videoId,
  447. token: server.accessToken,
  448. fields,
  449. attaches
  450. })
  451. })
  452. it('Should fail with a big thumbnail file', async function () {
  453. const fields = baseCorrectParams
  454. const attaches = {
  455. 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
  456. }
  457. await makeUploadRequest({
  458. url: server.url,
  459. method: 'PUT',
  460. path: path + videoId,
  461. token: server.accessToken,
  462. fields,
  463. attaches
  464. })
  465. })
  466. it('Should fail with an incorrect preview file', async function () {
  467. const fields = baseCorrectParams
  468. const attaches = {
  469. 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
  470. }
  471. await makeUploadRequest({
  472. url: server.url,
  473. method: 'PUT',
  474. path: path + videoId,
  475. token: server.accessToken,
  476. fields,
  477. attaches
  478. })
  479. })
  480. it('Should fail with a big preview file', async function () {
  481. const fields = baseCorrectParams
  482. const attaches = {
  483. 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
  484. }
  485. await makeUploadRequest({
  486. url: server.url,
  487. method: 'PUT',
  488. path: path + videoId,
  489. token: server.accessToken,
  490. fields,
  491. attaches
  492. })
  493. })
  494. it('Should fail with a video of another user without the appropriate right', async function () {
  495. const fields = baseCorrectParams
  496. await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
  497. })
  498. it('Should fail with a video of another server')
  499. it('Should succeed with the correct parameters', async function () {
  500. const fields = baseCorrectParams
  501. await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
  502. })
  503. })
  504. describe('When getting a video', function () {
  505. it('Should return the list of the videos with nothing', async function () {
  506. const res = await makeGetRequest({
  507. url: server.url,
  508. path,
  509. statusCodeExpected: 200
  510. })
  511. expect(res.body.data).to.be.an('array')
  512. expect(res.body.data.length).to.equal(3)
  513. })
  514. it('Should fail without a correct uuid', async function () {
  515. await getVideo(server.url, 'coucou', 400)
  516. })
  517. it('Should return 404 with an incorrect video', async function () {
  518. await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
  519. })
  520. it('Should succeed with the correct parameters', async function () {
  521. await getVideo(server.url, videoId)
  522. })
  523. })
  524. describe('When rating a video', function () {
  525. let videoId
  526. before(async function () {
  527. const res = await getVideosList(server.url)
  528. videoId = res.body.data[0].id
  529. })
  530. it('Should fail without a valid uuid', async function () {
  531. const fields = {
  532. rating: 'like'
  533. }
  534. await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
  535. })
  536. it('Should fail with an unknown id', async function () {
  537. const fields = {
  538. rating: 'like'
  539. }
  540. await makePutBodyRequest({
  541. url: server.url,
  542. path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
  543. token: server.accessToken,
  544. fields,
  545. statusCodeExpected: 404
  546. })
  547. })
  548. it('Should fail with a wrong rating', async function () {
  549. const fields = {
  550. rating: 'likes'
  551. }
  552. await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
  553. })
  554. it('Should succeed with the correct parameters', async function () {
  555. const fields = {
  556. rating: 'like'
  557. }
  558. await makePutBodyRequest({
  559. url: server.url,
  560. path: path + videoId + '/rate',
  561. token: server.accessToken,
  562. fields,
  563. statusCodeExpected: 204
  564. })
  565. })
  566. })
  567. describe('When removing a video', function () {
  568. it('Should have 404 with nothing', async function () {
  569. await makeDeleteRequest({
  570. url: server.url,
  571. path,
  572. statusCodeExpected: 400
  573. })
  574. })
  575. it('Should fail without a correct uuid', async function () {
  576. await removeVideo(server.url, server.accessToken, 'hello', 400)
  577. })
  578. it('Should fail with a video which does not exist', async function () {
  579. await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
  580. })
  581. it('Should fail with a video of another user without the appropriate right', async function () {
  582. await removeVideo(server.url, userAccessToken, videoId, 403)
  583. })
  584. it('Should fail with a video of another server')
  585. it('Should succeed with the correct parameters', async function () {
  586. await removeVideo(server.url, server.accessToken, videoId)
  587. })
  588. })
  589. after(async function () {
  590. await cleanupTests([ server ])
  591. })
  592. })