1 /* tslint:disable:no-unused-expression */
9 makeDeleteRequest, makeGetRequest,
12 setAccessTokensToServers,
14 } from '../../../../shared/extra-utils'
16 checkBadCountPagination,
17 checkBadSortPagination,
18 checkBadStartPagination
19 } from '../../../../shared/extra-utils/requests/check-api-params'
21 describe('Test server follows API validators', function () {
22 let server: ServerInfo
24 // ---------------------------------------------------------------
26 before(async function () {
29 server = await flushAndRunServer(1)
31 await setAccessTokensToServers([ server ])
34 describe('When managing following', function () {
35 let userAccessToken = null
37 before(async function () {
43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
44 userAccessToken = await userLogin(server, user)
47 describe('When adding follows', function () {
48 const path = '/api/v1/server/following'
50 it('Should fail without hosts', async function () {
51 await makePostBodyRequest({
54 token: server.accessToken,
55 statusCodeExpected: 400
59 it('Should fail if hosts is not an array', async function () {
60 await makePostBodyRequest({
63 token: server.accessToken,
64 fields: { hosts: 'localhost:9002' },
65 statusCodeExpected: 400
69 it('Should fail if the array is not composed by hosts', async function () {
70 await makePostBodyRequest({
73 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
74 token: server.accessToken,
75 statusCodeExpected: 400
79 it('Should fail if the array is composed with http schemes', async function () {
80 await makePostBodyRequest({
83 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
84 token: server.accessToken,
85 statusCodeExpected: 400
89 it('Should fail if hosts are not unique', async function () {
90 await makePostBodyRequest({
93 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
94 token: server.accessToken,
95 statusCodeExpected: 400
99 it('Should fail with an invalid token', async function () {
100 await makePostBodyRequest({
103 fields: { hosts: [ 'localhost:9002' ] },
105 statusCodeExpected: 401
109 it('Should fail if the user is not an administrator', async function () {
110 await makePostBodyRequest({
113 fields: { hosts: [ 'localhost:9002' ] },
114 token: userAccessToken,
115 statusCodeExpected: 403
120 describe('When listing followings', function () {
121 const path = '/api/v1/server/following'
123 it('Should fail with a bad start pagination', async function () {
124 await checkBadStartPagination(server.url, path)
127 it('Should fail with a bad count pagination', async function () {
128 await checkBadCountPagination(server.url, path)
131 it('Should fail with an incorrect sort', async function () {
132 await checkBadSortPagination(server.url, path)
135 it('Should fail with an incorrect state', async function () {
136 await makeGetRequest({
145 it('Should fail succeed with the correct params', async function () {
146 await makeGetRequest({
149 statusCodeExpected: 200,
157 describe('When listing followers', function () {
158 const path = '/api/v1/server/followers'
160 it('Should fail with a bad start pagination', async function () {
161 await checkBadStartPagination(server.url, path)
164 it('Should fail with a bad count pagination', async function () {
165 await checkBadCountPagination(server.url, path)
168 it('Should fail with an incorrect sort', async function () {
169 await checkBadSortPagination(server.url, path)
172 it('Should fail with an incorrect state', async function () {
173 await makeGetRequest({
182 it('Should fail succeed with the correct params', async function () {
183 await makeGetRequest({
186 statusCodeExpected: 200,
194 describe('When removing a follower', function () {
195 const path = '/api/v1/server/followers'
197 it('Should fail with an invalid token', async function () {
198 await makeDeleteRequest({
200 path: path + '/toto@localhost:9002',
202 statusCodeExpected: 401
206 it('Should fail if the user is not an administrator', async function () {
207 await makeDeleteRequest({
209 path: path + '/toto@localhost:9002',
210 token: userAccessToken,
211 statusCodeExpected: 403
215 it('Should fail with an invalid follower', async function () {
216 await makeDeleteRequest({
218 path: path + '/toto',
219 token: server.accessToken,
220 statusCodeExpected: 400
224 it('Should fail with an unknown follower', async function () {
225 await makeDeleteRequest({
227 path: path + '/toto@localhost:9003',
228 token: server.accessToken,
229 statusCodeExpected: 404
234 describe('When accepting a follower', function () {
235 const path = '/api/v1/server/followers'
237 it('Should fail with an invalid token', async function () {
238 await makePostBodyRequest({
240 path: path + '/toto@localhost:9002/accept',
242 statusCodeExpected: 401
246 it('Should fail if the user is not an administrator', async function () {
247 await makePostBodyRequest({
249 path: path + '/toto@localhost:9002/accept',
250 token: userAccessToken,
251 statusCodeExpected: 403
255 it('Should fail with an invalid follower', async function () {
256 await makePostBodyRequest({
258 path: path + '/toto/accept',
259 token: server.accessToken,
260 statusCodeExpected: 400
264 it('Should fail with an unknown follower', async function () {
265 await makePostBodyRequest({
267 path: path + '/toto@localhost:9003/accept',
268 token: server.accessToken,
269 statusCodeExpected: 404
274 describe('When rejecting a follower', function () {
275 const path = '/api/v1/server/followers'
277 it('Should fail with an invalid token', async function () {
278 await makePostBodyRequest({
280 path: path + '/toto@localhost:9002/reject',
282 statusCodeExpected: 401
286 it('Should fail if the user is not an administrator', async function () {
287 await makePostBodyRequest({
289 path: path + '/toto@localhost:9002/reject',
290 token: userAccessToken,
291 statusCodeExpected: 403
295 it('Should fail with an invalid follower', async function () {
296 await makePostBodyRequest({
298 path: path + '/toto/reject',
299 token: server.accessToken,
300 statusCodeExpected: 400
304 it('Should fail with an unknown follower', async function () {
305 await makePostBodyRequest({
307 path: path + '/toto@localhost:9003/reject',
308 token: server.accessToken,
309 statusCodeExpected: 404
314 describe('When removing following', function () {
315 const path = '/api/v1/server/following'
317 it('Should fail with an invalid token', async function () {
318 await makeDeleteRequest({
320 path: path + '/localhost:9002',
322 statusCodeExpected: 401
326 it('Should fail if the user is not an administrator', async function () {
327 await makeDeleteRequest({
329 path: path + '/localhost:9002',
330 token: userAccessToken,
331 statusCodeExpected: 403
335 it('Should fail if we do not follow this server', async function () {
336 await makeDeleteRequest({
338 path: path + '/example.com',
339 token: server.accessToken,
340 statusCodeExpected: 404
346 after(async function () {
347 await cleanupTests([ server ])