]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params.js
First version with PostgreSQL
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params.js
index 57b5ca024d797685ab333f21a602343030b9f3c5..d9e51770cc82200e743fdf06baef8a816b2d0a94 100644 (file)
@@ -67,10 +67,10 @@ describe('Test parameters validator', function () {
 
       describe('When making friends', function () {
         const body = {
-          urls: [ 'http://localhost:9002' ]
+          hosts: [ 'localhost:9002' ]
         }
 
-        it('Should fail without urls', function (done) {
+        it('Should fail without hosts', function (done) {
           request(server.url)
             .post(path + '/makefriends')
             .set('Authorization', 'Bearer ' + server.accessToken)
@@ -78,28 +78,37 @@ describe('Test parameters validator', function () {
             .expect(400, done)
         })
 
-        it('Should fail with urls is not an array', function (done) {
+        it('Should fail if hosts is not an array', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: 'http://localhost:9002' })
+            .send({ hosts: 'localhost:9002' })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
         })
 
-        it('Should fail if the array is not composed by urls', function (done) {
+        it('Should fail if the array is not composed by hosts', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: [ 'http://localhost:9002', 'localhost:coucou' ] })
+            .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
         })
 
-        it('Should fail if urls are not unique', function (done) {
+        it('Should fail if the array is composed with http schemes', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: [ 'http://localhost:9002', 'http://localhost:9002' ] })
+            .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
+            .set('Authorization', 'Bearer ' + server.accessToken)
+            .set('Accept', 'application/json')
+            .expect(400, done)
+        })
+
+        it('Should fail if hosts are not unique', function (done) {
+          request(server.url)
+            .post(path + '/makefriends')
+            .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
@@ -153,27 +162,27 @@ describe('Test parameters validator', function () {
 
       it('Should fail without public key', function (done) {
         const data = {
-          url: 'http://coucou.com'
+          host: 'coucou.com'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
       })
 
-      it('Should fail without an url', function (done) {
+      it('Should fail without an host', function (done) {
         const data = {
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
       })
 
-      it('Should fail with an incorrect url', function (done) {
+      it('Should fail with an incorrect host', function (done) {
         const data = {
-          url: 'coucou.com',
+          host: 'http://coucou.com',
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
-          data.url = 'http://coucou'
+          data.host = 'http://coucou'
           requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
-            data.url = 'coucou'
+            data.host = 'coucou'
             requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
           })
         })
@@ -181,7 +190,7 @@ describe('Test parameters validator', function () {
 
       it('Should succeed with the correct parameters', function (done) {
         const data = {
-          url: 'http://coucou.com',
+          host: 'coucou.com',
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200)
@@ -456,7 +465,7 @@ describe('Test parameters validator', function () {
 
       it('Should return 404 with an incorrect video', function (done) {
         request(server.url)
-          .get(path + '123456789012345678901234')
+          .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
           .set('Accept', 'application/json')
           .expect(404, done)
       })
@@ -481,7 +490,7 @@ describe('Test parameters validator', function () {
 
       it('Should fail with a video which does not exist', function (done) {
         request(server.url)
-          .delete(path + '123456789012345678901234')
+          .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
           .set('Authorization', 'Bearer ' + server.accessToken)
           .expect(404, done)
       })
@@ -497,6 +506,7 @@ describe('Test parameters validator', function () {
   describe('Of the users API', function () {
     const path = '/api/v1/users/'
     let userId = null
+    let rootId = null
 
     describe('When listing users', function () {
       it('Should fail with a bad start pagination', function (done) {
@@ -626,6 +636,7 @@ describe('Test parameters validator', function () {
           if (err) throw err
 
           userId = res.body.data[1].id
+          rootId = res.body.data[2].id
           done()
         })
       })
@@ -691,9 +702,16 @@ describe('Test parameters validator', function () {
           .expect(400, done)
       })
 
+      it('Should fail with the root user', function (done) {
+        request(server.url)
+          .delete(path + rootId)
+          .set('Authorization', 'Bearer ' + server.accessToken)
+          .expect(400, done)
+      })
+
       it('Should return 404 with a non existing id', function (done) {
         request(server.url)
-          .delete(path + '579f982228c99c221d8092b8')
+          .delete(path + '45')
           .set('Authorization', 'Bearer ' + server.accessToken)
           .expect(404, done)
       })