video-channels.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import { omit } from 'lodash'
  4. import 'mocha'
  5. import {
  6. cleanupTests,
  7. createUser,
  8. deleteVideoChannel,
  9. flushAndRunServer,
  10. getAccountVideoChannelsList,
  11. immutableAssign,
  12. makeGetRequest,
  13. makePostBodyRequest,
  14. makePutBodyRequest,
  15. makeUploadRequest,
  16. ServerInfo,
  17. setAccessTokensToServers,
  18. userLogin
  19. } from '../../../../shared/extra-utils'
  20. import {
  21. checkBadCountPagination,
  22. checkBadSortPagination,
  23. checkBadStartPagination
  24. } from '../../../../shared/extra-utils/requests/check-api-params'
  25. import { join } from 'path'
  26. import { VideoChannelUpdate } from '../../../../shared/models/videos'
  27. const expect = chai.expect
  28. describe('Test video channels API validator', function () {
  29. const videoChannelPath = '/api/v1/video-channels'
  30. let server: ServerInfo
  31. let accessTokenUser: string
  32. // ---------------------------------------------------------------
  33. before(async function () {
  34. this.timeout(30000)
  35. server = await flushAndRunServer(1)
  36. await setAccessTokensToServers([ server ])
  37. const user = {
  38. username: 'fake',
  39. password: 'fake_password'
  40. }
  41. {
  42. await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
  43. accessTokenUser = await userLogin(server, user)
  44. }
  45. })
  46. describe('When listing a video channels', function () {
  47. it('Should fail with a bad start pagination', async function () {
  48. await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
  49. })
  50. it('Should fail with a bad count pagination', async function () {
  51. await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
  52. })
  53. it('Should fail with an incorrect sort', async function () {
  54. await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
  55. })
  56. })
  57. describe('When listing account video channels', function () {
  58. const accountChannelPath = '/api/v1/accounts/fake/video-channels'
  59. it('Should fail with a bad start pagination', async function () {
  60. await checkBadStartPagination(server.url, accountChannelPath, server.accessToken)
  61. })
  62. it('Should fail with a bad count pagination', async function () {
  63. await checkBadCountPagination(server.url, accountChannelPath, server.accessToken)
  64. })
  65. it('Should fail with an incorrect sort', async function () {
  66. await checkBadSortPagination(server.url, accountChannelPath, server.accessToken)
  67. })
  68. it('Should fail with a unknown account', async function () {
  69. await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: 404 })
  70. })
  71. it('Should succeed with the correct parameters', async function () {
  72. await makeGetRequest({
  73. url: server.url,
  74. path: accountChannelPath,
  75. statusCodeExpected: 200
  76. })
  77. })
  78. })
  79. describe('When adding a video channel', function () {
  80. const baseCorrectParams = {
  81. name: 'super_channel',
  82. displayName: 'hello',
  83. description: 'super description',
  84. support: 'super support text'
  85. }
  86. it('Should fail with a non authenticated user', async function () {
  87. await makePostBodyRequest({
  88. url: server.url,
  89. path: videoChannelPath,
  90. token: 'none',
  91. fields: baseCorrectParams,
  92. statusCodeExpected: 401
  93. })
  94. })
  95. it('Should fail with nothing', async function () {
  96. const fields = {}
  97. await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
  98. })
  99. it('Should fail without a name', async function () {
  100. const fields = omit(baseCorrectParams, 'name')
  101. await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
  102. })
  103. it('Should fail with a bad name', async function () {
  104. const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
  105. await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
  106. })
  107. it('Should fail without a name', async function () {
  108. const fields = omit(baseCorrectParams, 'displayName')
  109. await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
  110. })
  111. it('Should fail with a long name', async function () {
  112. const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
  113. await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
  114. })
  115. it('Should fail with a long description', async function () {
  116. const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
  117. await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
  118. })
  119. it('Should fail with a long support text', async function () {
  120. const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
  121. await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
  122. })
  123. it('Should succeed with the correct parameters', async function () {
  124. await makePostBodyRequest({
  125. url: server.url,
  126. path: videoChannelPath,
  127. token: server.accessToken,
  128. fields: baseCorrectParams,
  129. statusCodeExpected: 200
  130. })
  131. })
  132. it('Should fail when adding a channel with the same username', async function () {
  133. await makePostBodyRequest({
  134. url: server.url,
  135. path: videoChannelPath,
  136. token: server.accessToken,
  137. fields: baseCorrectParams,
  138. statusCodeExpected: 409
  139. })
  140. })
  141. })
  142. describe('When updating a video channel', function () {
  143. const baseCorrectParams: VideoChannelUpdate = {
  144. displayName: 'hello',
  145. description: 'super description',
  146. support: 'toto',
  147. bulkVideosSupportUpdate: false
  148. }
  149. let path: string
  150. before(async function () {
  151. path = videoChannelPath + '/super_channel'
  152. })
  153. it('Should fail with a non authenticated user', async function () {
  154. await makePutBodyRequest({
  155. url: server.url,
  156. path,
  157. token: 'hi',
  158. fields: baseCorrectParams,
  159. statusCodeExpected: 401
  160. })
  161. })
  162. it('Should fail with another authenticated user', async function () {
  163. await makePutBodyRequest({
  164. url: server.url,
  165. path,
  166. token: accessTokenUser,
  167. fields: baseCorrectParams,
  168. statusCodeExpected: 403
  169. })
  170. })
  171. it('Should fail with a long name', async function () {
  172. const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
  173. await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  174. })
  175. it('Should fail with a long description', async function () {
  176. const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
  177. await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  178. })
  179. it('Should fail with a long support text', async function () {
  180. const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
  181. await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  182. })
  183. it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
  184. const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' })
  185. await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  186. })
  187. it('Should succeed with the correct parameters', async function () {
  188. await makePutBodyRequest({
  189. url: server.url,
  190. path,
  191. token: server.accessToken,
  192. fields: baseCorrectParams,
  193. statusCodeExpected: 204
  194. })
  195. })
  196. })
  197. describe('When updating video channel avatar', function () {
  198. let path: string
  199. before(async function () {
  200. path = videoChannelPath + '/super_channel'
  201. })
  202. it('Should fail with an incorrect input file', async function () {
  203. const fields = {}
  204. const attaches = {
  205. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
  206. }
  207. await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
  208. })
  209. it('Should fail with a big file', async function () {
  210. const fields = {}
  211. const attaches = {
  212. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
  213. }
  214. await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
  215. })
  216. it('Should fail with an unauthenticated user', async function () {
  217. const fields = {}
  218. const attaches = {
  219. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
  220. }
  221. await makeUploadRequest({
  222. url: server.url,
  223. path: path + '/avatar/pick',
  224. fields,
  225. attaches,
  226. statusCodeExpected: 401
  227. })
  228. })
  229. it('Should succeed with the correct params', async function () {
  230. const fields = {}
  231. const attaches = {
  232. 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
  233. }
  234. await makeUploadRequest({
  235. url: server.url,
  236. path: path + '/avatar/pick',
  237. token: server.accessToken,
  238. fields,
  239. attaches,
  240. statusCodeExpected: 200
  241. })
  242. })
  243. })
  244. describe('When getting a video channel', function () {
  245. it('Should return the list of the video channels with nothing', async function () {
  246. const res = await makeGetRequest({
  247. url: server.url,
  248. path: videoChannelPath,
  249. statusCodeExpected: 200
  250. })
  251. expect(res.body.data).to.be.an('array')
  252. })
  253. it('Should return 404 with an incorrect video channel', async function () {
  254. await makeGetRequest({
  255. url: server.url,
  256. path: videoChannelPath + '/super_channel2',
  257. statusCodeExpected: 404
  258. })
  259. })
  260. it('Should succeed with the correct parameters', async function () {
  261. await makeGetRequest({
  262. url: server.url,
  263. path: videoChannelPath + '/super_channel',
  264. statusCodeExpected: 200
  265. })
  266. })
  267. })
  268. describe('When deleting a video channel', function () {
  269. it('Should fail with a non authenticated user', async function () {
  270. await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401)
  271. })
  272. it('Should fail with another authenticated user', async function () {
  273. await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403)
  274. })
  275. it('Should fail with an unknown video channel id', async function () {
  276. await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404)
  277. })
  278. it('Should succeed with the correct parameters', async function () {
  279. await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
  280. })
  281. it('Should fail to delete the last user video channel', async function () {
  282. await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409)
  283. })
  284. })
  285. after(async function () {
  286. await cleanupTests([ server ])
  287. })
  288. })