From d57d6f2605f4ac4a81f9a8594433bb7b65f108b9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 21 Aug 2016 10:08:40 +0200 Subject: Server: fix makefriends validation and tests --- server/tests/api/check-params.js | 109 +++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 50 deletions(-) (limited to 'server/tests/api/check-params.js') diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js index ec666417c..4f7b26561 100644 --- a/server/tests/api/check-params.js +++ b/server/tests/api/check-params.js @@ -44,50 +44,7 @@ describe('Test parameters validator', function () { describe('Of the pods API', function () { const path = '/api/v1/pods/' - describe('When adding a pod', function () { - it('Should fail with nothing', function (done) { - const data = {} - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail without public key', function (done) { - const data = { - url: 'http://coucou.com' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail without an url', function (done) { - const data = { - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - - it('Should fail with an incorrect url', function (done) { - const data = { - url: 'coucou.com', - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { - data.url = 'http://coucou' - requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { - data.url = 'coucou' - requestsUtils.makePostBodyRequest(server.url, path, null, data, done) - }) - }) - }) - - it('Should succeed with the correct parameters', function (done) { - const data = { - url: 'http://coucou.com', - publicKey: 'mysuperpublickey' - } - requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) - }) - }) - - describe('For the friends API', function () { + describe('When making friends', function () { let userAccessToken = null before(function (done) { @@ -115,27 +72,36 @@ describe('Test parameters validator', function () { it('Should fail without urls', function (done) { request(server.url) .post(path + '/makefriends') - .set('Authorization', 'Bearer faketoken') + .set('Authorization', 'Bearer ' + server.accessToken) .set('Accept', 'application/json') - .expect(401, done) + .expect(400, done) }) it('Should fail with urls is not an array', function (done) { request(server.url) .post(path + '/makefriends') .send({ urls: 'http://localhost:9002' }) - .set('Authorization', 'Bearer faketoken') + .set('Authorization', 'Bearer ' + server.accessToken) .set('Accept', 'application/json') - .expect(401, done) + .expect(400, done) }) it('Should fail if the array is not composed by urls', function (done) { request(server.url) .post(path + '/makefriends') .send({ urls: [ 'http://localhost:9002', 'localhost:coucou' ] }) - .set('Authorization', 'Bearer faketoken') + .set('Authorization', 'Bearer ' + server.accessToken) .set('Accept', 'application/json') - .expect(401, done) + .expect(400, done) + }) + + it('Should fail if urls are not unique', function (done) { + request(server.url) + .post(path + '/makefriends') + .send({ urls: [ 'http://localhost:9002', 'http://localhost:9002' ] }) + .set('Authorization', 'Bearer ' + server.accessToken) + .set('Accept', 'application/json') + .expect(400, done) }) it('Should fail with a invalid token', function (done) { @@ -177,6 +143,49 @@ describe('Test parameters validator', function () { }) }) }) + + describe('When adding a pod', function () { + it('Should fail with nothing', function (done) { + const data = {} + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without public key', function (done) { + const data = { + url: 'http://coucou.com' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail without an url', function (done) { + const data = { + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + + it('Should fail with an incorrect url', function (done) { + const data = { + url: 'coucou.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { + data.url = 'http://coucou' + requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { + data.url = 'coucou' + requestsUtils.makePostBodyRequest(server.url, path, null, data, done) + }) + }) + }) + + it('Should succeed with the correct parameters', function (done) { + const data = { + url: 'http://coucou.com', + publicKey: 'mysuperpublickey' + } + requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) + }) + }) }) describe('Of the videos API', function () { -- cgit v1.2.3