]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/follows.ts
shared/ typescript types dir server-commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / follows.ts
index dfe3f226d4e075a5708e6835f768ba598599c912..6121d22022c251f35595a08a6726eb402ace63bb 100644 (file)
@@ -12,7 +12,7 @@ import {
   makePostBodyRequest,
   PeerTubeServer,
   setAccessTokensToServers
-} from '@shared/extra-utils'
+} from '@shared/server-commands'
 import { HttpStatusCode } from '@shared/models'
 
 describe('Test server follows API validators', function () {
@@ -32,19 +32,13 @@ describe('Test server follows API validators', function () {
     let userAccessToken = null
 
     before(async function () {
-      const user = {
-        username: 'user1',
-        password: 'password'
-      }
-
-      await server.users.create({ username: user.username, password: user.password })
-      userAccessToken = await server.login.getAccessToken(user)
+      userAccessToken = await server.users.generateUserAndToken('user1')
     })
 
     describe('When adding follows', function () {
       const path = '/api/v1/server/following'
 
-      it('Should fail without hosts', async function () {
+      it('Should fail with nothing', async function () {
         await makePostBodyRequest({
           url: server.url,
           path,
@@ -53,41 +47,51 @@ describe('Test server follows API validators', function () {
         })
       })
 
-      it('Should fail if hosts is not an array', async function () {
+      it('Should fail if hosts is not composed by hosts', async function () {
         await makePostBodyRequest({
           url: server.url,
           path,
+          fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
           token: server.accessToken,
-          fields: { hosts: 'localhost:9002' },
           expectedStatus: HttpStatusCode.BAD_REQUEST_400
         })
       })
 
-      it('Should fail if the array is not composed by hosts', async function () {
+      it('Should fail if hosts is composed with http schemes', async function () {
         await makePostBodyRequest({
           url: server.url,
           path,
-          fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
+          fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
           token: server.accessToken,
           expectedStatus: HttpStatusCode.BAD_REQUEST_400
         })
       })
 
-      it('Should fail if the array is composed with http schemes', async function () {
+      it('Should fail if hosts are not unique', async function () {
         await makePostBodyRequest({
           url: server.url,
           path,
-          fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
+          fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
           token: server.accessToken,
           expectedStatus: HttpStatusCode.BAD_REQUEST_400
         })
       })
 
-      it('Should fail if hosts are not unique', async function () {
+      it('Should fail if handles is not composed by handles', async function () {
         await makePostBodyRequest({
           url: server.url,
           path,
-          fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
+          fields: { handles: [ 'hello@example.com', 'localhost:9001' ] },
+          token: server.accessToken,
+          expectedStatus: HttpStatusCode.BAD_REQUEST_400
+        })
+      })
+
+      it('Should fail if handles are not unique', async function () {
+        await makePostBodyRequest({
+          url: server.url,
+          path,
+          fields: { urls: [ 'hello@example.com', 'hello@example.com' ] },
           token: server.accessToken,
           expectedStatus: HttpStatusCode.BAD_REQUEST_400
         })