aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params.js')
-rw-r--r--server/tests/api/check-params.js39
1 files changed, 24 insertions, 15 deletions
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js
index 07f41daab..444c2fc55 100644
--- a/server/tests/api/check-params.js
+++ b/server/tests/api/check-params.js
@@ -67,10 +67,10 @@ describe('Test parameters validator', function () {
67 67
68 describe('When making friends', function () { 68 describe('When making friends', function () {
69 const body = { 69 const body = {
70 urls: [ 'http://localhost:9002' ] 70 hosts: [ 'localhost:9002' ]
71 } 71 }
72 72
73 it('Should fail without urls', function (done) { 73 it('Should fail without hosts', function (done) {
74 request(server.url) 74 request(server.url)
75 .post(path + '/makefriends') 75 .post(path + '/makefriends')
76 .set('Authorization', 'Bearer ' + server.accessToken) 76 .set('Authorization', 'Bearer ' + server.accessToken)
@@ -78,28 +78,37 @@ describe('Test parameters validator', function () {
78 .expect(400, done) 78 .expect(400, done)
79 }) 79 })
80 80
81 it('Should fail with urls is not an array', function (done) { 81 it('Should fail if hosts is not an array', function (done) {
82 request(server.url) 82 request(server.url)
83 .post(path + '/makefriends') 83 .post(path + '/makefriends')
84 .send({ urls: 'http://localhost:9002' }) 84 .send({ hosts: 'localhost:9002' })
85 .set('Authorization', 'Bearer ' + server.accessToken) 85 .set('Authorization', 'Bearer ' + server.accessToken)
86 .set('Accept', 'application/json') 86 .set('Accept', 'application/json')
87 .expect(400, done) 87 .expect(400, done)
88 }) 88 })
89 89
90 it('Should fail if the array is not composed by urls', function (done) { 90 it('Should fail if the array is not composed by hosts', function (done) {
91 request(server.url) 91 request(server.url)
92 .post(path + '/makefriends') 92 .post(path + '/makefriends')
93 .send({ urls: [ 'http://localhost:9002', 'localhost:coucou' ] }) 93 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
94 .set('Authorization', 'Bearer ' + server.accessToken) 94 .set('Authorization', 'Bearer ' + server.accessToken)
95 .set('Accept', 'application/json') 95 .set('Accept', 'application/json')
96 .expect(400, done) 96 .expect(400, done)
97 }) 97 })
98 98
99 it('Should fail if urls are not unique', function (done) { 99 it('Should fail if the array is composed with http schemes', function (done) {
100 request(server.url) 100 request(server.url)
101 .post(path + '/makefriends') 101 .post(path + '/makefriends')
102 .send({ urls: [ 'http://localhost:9002', 'http://localhost:9002' ] }) 102 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
103 .set('Authorization', 'Bearer ' + server.accessToken)
104 .set('Accept', 'application/json')
105 .expect(400, done)
106 })
107
108 it('Should fail if hosts are not unique', function (done) {
109 request(server.url)
110 .post(path + '/makefriends')
111 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
103 .set('Authorization', 'Bearer ' + server.accessToken) 112 .set('Authorization', 'Bearer ' + server.accessToken)
104 .set('Accept', 'application/json') 113 .set('Accept', 'application/json')
105 .expect(400, done) 114 .expect(400, done)
@@ -153,27 +162,27 @@ describe('Test parameters validator', function () {
153 162
154 it('Should fail without public key', function (done) { 163 it('Should fail without public key', function (done) {
155 const data = { 164 const data = {
156 url: 'http://coucou.com' 165 host: 'coucou.com'
157 } 166 }
158 requestsUtils.makePostBodyRequest(server.url, path, null, data, done) 167 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
159 }) 168 })
160 169
161 it('Should fail without an url', function (done) { 170 it('Should fail without an host', function (done) {
162 const data = { 171 const data = {
163 publicKey: 'mysuperpublickey' 172 publicKey: 'mysuperpublickey'
164 } 173 }
165 requestsUtils.makePostBodyRequest(server.url, path, null, data, done) 174 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
166 }) 175 })
167 176
168 it('Should fail with an incorrect url', function (done) { 177 it('Should fail with an incorrect host', function (done) {
169 const data = { 178 const data = {
170 url: 'coucou.com', 179 host: 'http://coucou.com',
171 publicKey: 'mysuperpublickey' 180 publicKey: 'mysuperpublickey'
172 } 181 }
173 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { 182 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
174 data.url = 'http://coucou' 183 data.host = 'http://coucou'
175 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { 184 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
176 data.url = 'coucou' 185 data.host = 'coucou'
177 requestsUtils.makePostBodyRequest(server.url, path, null, data, done) 186 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
178 }) 187 })
179 }) 188 })
@@ -181,7 +190,7 @@ describe('Test parameters validator', function () {
181 190
182 it('Should succeed with the correct parameters', function (done) { 191 it('Should succeed with the correct parameters', function (done) {
183 const data = { 192 const data = {
184 url: 'http://coucou.com', 193 host: 'coucou.com',
185 publicKey: 'mysuperpublickey' 194 publicKey: 'mysuperpublickey'
186 } 195 }
187 requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) 196 requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200)