]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/video-channels.ts
Video channel API routes refractor
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-channels.ts
index acb6bdd57ead1bd48dfbeae9f0c3abb20ab2c7db..25b2dc9b950c29db840ab4cb16e97f947c62e222 100644 (file)
@@ -7,7 +7,7 @@ import {
   createUser,
   deleteVideoChannel,
   flushTests,
-  getAccountVideoChannelsList,
+  getAccountVideoChannelsList, getMyUserInformation,
   getVideoChannelsList,
   immutableAssign,
   killallServers,
@@ -21,6 +21,7 @@ import {
 } from '../../utils'
 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
 import { getAccountsList } from '../../utils/users/accounts'
+import { User } from '../../../../shared/models/users'
 
 const expect = chai.expect
 
@@ -29,6 +30,8 @@ describe('Test videos API validator', function () {
   const accountPath = '/api/v1/accounts/'
   let server: ServerInfo
   let accessTokenUser: string
+  let accountUUID: string
+  let videoChannelUUID: string
 
   // ---------------------------------------------------------------
 
@@ -45,8 +48,18 @@ describe('Test videos API validator', function () {
       username: 'fake',
       password: 'fake_password'
     }
-    await createUser(server.url, server.accessToken, user.username, user.password)
-    accessTokenUser = await userLogin(server, user)
+
+    {
+      await createUser(server.url, server.accessToken, user.username, user.password)
+      accessTokenUser = await userLogin(server, user)
+    }
+
+    {
+      const res = await getMyUserInformation(server.url, server.accessToken)
+      const user: User = res.body
+      accountUUID = user.account.uuid
+      videoChannelUUID = user.videoChannels[0].uuid
+    }
   })
 
   describe('When listing a video channels', function () {
@@ -74,18 +87,15 @@ describe('Test videos API validator', function () {
   })
 
   describe('When adding a video channel', function () {
-    let path: string
-
     const baseCorrectParams = {
       name: 'hello',
       description: 'super description',
       support: 'super support text'
     }
+    let path: string
 
     before(async function () {
-      const res = await getAccountsList(server.url)
-      const accountId = res.body.data[0].id
-      path = accountPath + accountId + '/video-channels'
+      path = accountPath + accountUUID + '/video-channels'
     })
 
     it('Should fail with a non authenticated user', async function () {
@@ -129,21 +139,14 @@ describe('Test videos API validator', function () {
   })
 
   describe('When updating a video channel', function () {
-    let path: string
-
     const baseCorrectParams = {
       name: 'hello',
       description: 'super description'
     }
+    let path: string
 
     before(async function () {
-      const res1 = await getVideoChannelsList(server.url, 0, 1)
-      const videoChannelId = res1.body.data[0].id
-
-      const res2 = await getAccountsList(server.url)
-      const accountId = res2.body.data[0].id
-
-      path = accountPath + accountId + '/video-channels/' + videoChannelId
+      path = accountPath + accountUUID + '/video-channels/' + videoChannelUUID
     })
 
     it('Should fail with a non authenticated user', async function () {
@@ -194,16 +197,9 @@ describe('Test videos API validator', function () {
 
   describe('When getting a video channel', function () {
     let basePath: string
-    let videoChannelId: number
 
     before(async function () {
-      const res1 = await getVideoChannelsList(server.url, 0, 1)
-      videoChannelId = res1.body.data[0].id
-
-      const res2 = await getAccountsList(server.url)
-      const accountId = res2.body.data[0].id
-
-      basePath = accountPath + accountId + '/video-channels'
+      basePath = accountPath + accountUUID + '/video-channels'
     })
 
     it('Should return the list of the video channels with nothing', async function () {
@@ -235,49 +231,38 @@ describe('Test videos API validator', function () {
     it('Should succeed with the correct parameters', async function () {
       await makeGetRequest({
         url: server.url,
-        path: basePath + '/' + videoChannelId,
+        path: basePath + '/' + videoChannelUUID,
         statusCodeExpected: 200
       })
     })
   })
 
   describe('When deleting a video channel', function () {
-    let videoChannelId: number
-    let accountId: number
-
-    before(async function () {
-      const res1 = await getVideoChannelsList(server.url, 0, 1)
-      videoChannelId = res1.body.data[0].id
-
-      const res2 = await getAccountsList(server.url)
-      accountId = res2.body.data[0].id
-    })
-
     it('Should fail with a non authenticated user', async function () {
-      await deleteVideoChannel(server.url, 'coucou', accountId, videoChannelId, 401)
+      await deleteVideoChannel(server.url, 'coucou', accountUUID, videoChannelUUID, 401)
     })
 
     it('Should fail with another authenticated user', async function () {
-      await deleteVideoChannel(server.url, accessTokenUser, accountId, videoChannelId, 403)
+      await deleteVideoChannel(server.url, accessTokenUser, accountUUID, videoChannelUUID, 403)
     })
 
     it('Should fail with an unknown account id', async function () {
-      await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelId, 404)
+      await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelUUID, 404)
     })
 
     it('Should fail with an unknown video channel id', async function () {
-      await deleteVideoChannel(server.url, server.accessToken, accountId,454554, 404)
+      await deleteVideoChannel(server.url, server.accessToken, accountUUID,454554, 404)
     })
 
     it('Should succeed with the correct parameters', async function () {
-      await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId)
+      await deleteVideoChannel(server.url, server.accessToken, accountUUID, videoChannelUUID)
     })
 
     it('Should fail to delete the last user video channel', async function () {
       const res = await getVideoChannelsList(server.url, 0, 1)
-      videoChannelId = res.body.data[0].id
+      const lastVideoChannelUUID = res.body.data[0].uuid
 
-      await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId, 409)
+      await deleteVideoChannel(server.url, server.accessToken, accountUUID, lastVideoChannelUUID, 409)
     })
   })