]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/pods.js
1 /* eslint-disable no-unused-expressions */
5 const request
= require('supertest')
6 const series
= require('async/series')
8 const loginUtils
= require('../../utils/login')
9 const requestsUtils
= require('../../utils/requests')
10 const serversUtils
= require('../../utils/servers')
11 const usersUtils
= require('../../utils/users')
13 describe('Test pods API validators', function () {
14 const path
= '/api/v1/pods/'
17 // ---------------------------------------------------------------
19 before(function (done
) {
24 serversUtils
.flushTests(next
)
27 serversUtils
.runServer(1, function (server1
) {
34 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
36 server
.accessToken
= token
44 describe('When managing friends', function () {
45 let userAccessToken
= null
47 before(function (done
) {
48 usersUtils
.createUser(server
.url
, server
.accessToken
, 'user1', 'password', function () {
54 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
57 userAccessToken
= accessToken
64 describe('When making friends', function () {
66 hosts: [ 'localhost:9002' ]
69 it('Should fail without hosts', function (done
) {
71 .post(path
+ '/makefriends')
72 .set('Authorization', 'Bearer ' + server
.accessToken
)
73 .set('Accept', 'application/json')
77 it('Should fail if hosts is not an array', function (done
) {
79 .post(path
+ '/makefriends')
80 .send({ hosts: 'localhost:9002' })
81 .set('Authorization', 'Bearer ' + server
.accessToken
)
82 .set('Accept', 'application/json')
86 it('Should fail if the array is not composed by hosts', function (done
) {
88 .post(path
+ '/makefriends')
89 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
90 .set('Authorization', 'Bearer ' + server
.accessToken
)
91 .set('Accept', 'application/json')
95 it('Should fail if the array is composed with http schemes', function (done
) {
97 .post(path
+ '/makefriends')
98 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
99 .set('Authorization', 'Bearer ' + server
.accessToken
)
100 .set('Accept', 'application/json')
104 it('Should fail if hosts are not unique', function (done
) {
106 .post(path
+ '/makefriends')
107 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
108 .set('Authorization', 'Bearer ' + server
.accessToken
)
109 .set('Accept', 'application/json')
113 it('Should fail with an invalid token', function (done
) {
115 .post(path
+ '/makefriends')
117 .set('Authorization', 'Bearer faketoken')
118 .set('Accept', 'application/json')
122 it('Should fail if the user is not an administrator', function (done
) {
124 .post(path
+ '/makefriends')
126 .set('Authorization', 'Bearer ' + userAccessToken
)
127 .set('Accept', 'application/json')
132 describe('When quitting friends', function () {
133 it('Should fail with an invalid token', function (done
) {
135 .get(path
+ '/quitfriends')
136 .query({ start: 'hello' })
137 .set('Authorization', 'Bearer faketoken')
138 .set('Accept', 'application/json')
142 it('Should fail if the user is not an administrator', function (done
) {
144 .get(path
+ '/quitfriends')
145 .query({ start: 'hello' })
146 .set('Authorization', 'Bearer ' + userAccessToken
)
147 .set('Accept', 'application/json')
152 describe('When removing one friend', function () {
153 it('Should fail with an invalid token', function (done
) {
156 .set('Authorization', 'Bearer faketoken')
157 .set('Accept', 'application/json')
161 it('Should fail if the user is not an administrator', function (done
) {
164 .set('Authorization', 'Bearer ' + userAccessToken
)
165 .set('Accept', 'application/json')
169 it('Should fail with an undefined id', function (done
) {
171 .delete(path
+ '/' + undefined)
172 .set('Authorization', 'Bearer ' + server
.accessToken
)
173 .set('Accept', 'application/json')
177 it('Should fail with an invalid id', function (done
) {
179 .delete(path
+ '/foobar')
180 .set('Authorization', 'Bearer ' + server
.accessToken
)
181 .set('Accept', 'application/json')
185 it('Should fail if the pod is not a friend', function (done
) {
187 .delete(path
+ '/-1')
188 .set('Authorization', 'Bearer ' + server
.accessToken
)
189 .set('Accept', 'application/json')
193 it('Should succeed with the correct parameters')
197 describe('When adding a pod', function () {
198 it('Should fail with nothing', function (done
) {
200 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
)
203 it('Should fail without public key', function (done
) {
205 email: 'testexample.com',
208 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
)
211 it('Should fail without an email', function (done
) {
214 publicKey: 'mysuperpublickey'
216 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
)
219 it('Should fail without an invalid email', function (done
) {
222 email: 'testexample.com',
223 publicKey: 'mysuperpublickey'
225 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
)
228 it('Should fail without a host', function (done
) {
230 email: 'testexample.com',
231 publicKey: 'mysuperpublickey'
233 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
)
236 it('Should fail with an incorrect host', function (done
) {
238 host: 'http://coucou.com',
239 email: 'testexample.com',
240 publicKey: 'mysuperpublickey'
242 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, function () {
243 data
.host
= 'http://coucou'
244 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, function () {
246 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
)
251 it('Should succeed with the correct parameters', function (done
) {
254 email: 'test@example.com',
255 publicKey: 'mysuperpublickey'
257 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
, 200)
260 it('Should fail with a host that already exists', function (done
) {
263 email: 'test@example.com',
264 publicKey: 'mysuperpublickey'
266 requestsUtils
.makePostBodyRequest(server
.url
, path
, null, data
, done
, 409)
270 after(function (done
) {
271 process
.kill(-server
.app
.pid
)
273 // Keep the logs if the test failed
275 serversUtils
.flushTests(done
)