]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/users.ts
Merge branch 'release/v1.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / users.ts
index 00d0a7e2be7e7fafd1f843cb59238965809ada89..95097817b21dd5134370f353cded7f65f4b005a1 100644 (file)
@@ -6,9 +6,28 @@ import { join } from 'path'
 import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
 
 import {
-  createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
-  makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, flushAndRunServer, ServerInfo, setAccessTokensToServers,
-  updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser
+  addVideoChannel,
+  blockUser,
+  cleanupTests,
+  createUser,
+  deleteMe,
+  flushAndRunServer,
+  getMyUserInformation,
+  getMyUserVideoRating,
+  getUsersList,
+  immutableAssign,
+  makeGetRequest,
+  makePostBodyRequest,
+  makePutBodyRequest,
+  makeUploadRequest,
+  registerUser,
+  removeUser,
+  ServerInfo,
+  setAccessTokensToServers,
+  unblockUser,
+  updateUser,
+  uploadVideo,
+  userLogin
 } from '../../../../shared/extra-utils'
 import {
   checkBadCountPagination,
@@ -620,7 +639,7 @@ describe('Test users API validators', function () {
     })
   })
 
-  describe('When register a new user', function () {
+  describe('When registering a new user', function () {
     const registrationPath = path + '/register'
     const baseCorrectParams = {
       username: 'user3',
@@ -695,7 +714,7 @@ describe('Test users API validators', function () {
     })
 
     it('Should fail if we register a user with the same email', async function () {
-      const fields = immutableAssign(baseCorrectParams, { email: 'admin1@example.com' })
+      const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
 
       await makePostBodyRequest({
         url: server.url,
@@ -706,12 +725,42 @@ describe('Test users API validators', function () {
       })
     })
 
+    it('Should fail with a bad channel name', async function () {
+      const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
+
+      await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
+    })
+
+    it('Should fail with a bad channel display name', async function () {
+      const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
+
+      await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
+    })
+
+    it('Should fail with a channel name that is the same than user username', async function () {
+      const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
+      const fields = immutableAssign(baseCorrectParams, source)
+
+      await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
+    })
+
+    it('Should fail with an existing channel', async function () {
+      const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
+      await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
+
+      const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
+
+      await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
+    })
+
     it('Should succeed with the correct params', async function () {
+      const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
+
       await makePostBodyRequest({
         url: server.url,
         path: registrationPath,
         token: server.accessToken,
-        fields: baseCorrectParams,
+        fields: fields,
         statusCodeExpected: 204
       })
     })
@@ -879,7 +928,7 @@ describe('Test users API validators', function () {
     })
   })
 
-  after(function () {
-    killallServers([ server, serverWithRegistrationDisabled ])
+  after(async function () {
+    await cleanupTests([ server, serverWithRegistrationDisabled ])
   })
 })