X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fpods.js;h=35ea590931f5552be5c4537aa4fd2ff2e21f7686;hb=d5f5a670fcf6258d0facf9a2fd3aabd550fbc78f;hp=2f85af644022b00326a69b08697264a0a056f994;hpb=efe923bcdaf15b47593ad8583df09a92c715ac6c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/pods.js b/server/tests/api/check-params/pods.js index 2f85af644..35ea59093 100644 --- a/server/tests/api/check-params/pods.js +++ b/server/tests/api/check-params/pods.js @@ -1,3 +1,5 @@ +/* eslint-disable no-unused-expressions */ + 'use strict' const request = require('supertest') @@ -15,7 +17,7 @@ describe('Test pods API validators', function () { // --------------------------------------------------------------- before(function (done) { - this.timeout(20000) + this.timeout(45000) series([ function (next) { @@ -39,7 +41,7 @@ describe('Test pods API validators', function () { ], done) }) - describe('When making friends', function () { + describe('When managing friends', function () { let userAccessToken = null before(function (done) { @@ -108,7 +110,7 @@ describe('Test pods API validators', function () { .expect(400, done) }) - it('Should fail with a invalid token', function (done) { + it('Should fail with an invalid token', function (done) { request(server.url) .post(path + '/makefriends') .send(body) @@ -128,7 +130,7 @@ describe('Test pods API validators', function () { }) describe('When quitting friends', function () { - it('Should fail with a invalid token', function (done) { + it('Should fail with an invalid token', function (done) { request(server.url) .get(path + '/quitfriends') .query({ start: 'hello' }) @@ -146,6 +148,50 @@ describe('Test pods API validators', function () { .expect(403, done) }) }) + + describe('When removing one friend', function () { + it('Should fail with an invalid token', function (done) { + request(server.url) + .delete(path + '/1') + .set('Authorization', 'Bearer faketoken') + .set('Accept', 'application/json') + .expect(401, done) + }) + + it('Should fail if the user is not an administrator', function (done) { + request(server.url) + .delete(path + '/1') + .set('Authorization', 'Bearer ' + userAccessToken) + .set('Accept', 'application/json') + .expect(403, done) + }) + + it('Should fail with an undefined id', function (done) { + request(server.url) + .delete(path + '/' + undefined) + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail with an invalid id', function (done) { + request(server.url) + .delete(path + '/foobar') + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) + }) + + it('Should fail if the pod is not a friend', function (done) { + request(server.url) + .delete(path + '/-1') + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(404, done) + }) + + it('Should succeed with the correct parameters') + }) }) describe('When adding a pod', function () { @@ -156,13 +202,32 @@ describe('Test pods API validators', function () { it('Should fail without public key', function (done) { const data = { + email: 'testexample.com', host: 'coucou.com' } requestsUtils.makePostBodyRequest(server.url, path, null, data, done) }) - it('Should fail without an host', function (done) { + it('Should fail without an email', function (done) { + const data = { + host: 'coucou.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without an invalid email', function (done) { + const data = { + host: 'coucou.com', + email: 'testexample.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without a host', function (done) { const data = { + email: 'testexample.com', publicKey: 'mysuperpublickey' } requestsUtils.makePostBodyRequest(server.url, path, null, data, done) @@ -171,6 +236,7 @@ describe('Test pods API validators', function () { it('Should fail with an incorrect host', function (done) { const data = { host: 'http://coucou.com', + email: 'testexample.com', publicKey: 'mysuperpublickey' } requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { @@ -185,10 +251,20 @@ describe('Test pods API validators', function () { it('Should succeed with the correct parameters', function (done) { const data = { host: 'coucou.com', + email: 'test@example.com', publicKey: 'mysuperpublickey' } requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) }) + + it('Should fail with a host that already exists', function (done) { + const data = { + host: 'coucou.com', + email: 'test@example.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 409) + }) }) after(function (done) {