1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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 with an incorrect actor type', async function () {
146 await makeGetRequest({
155 it('Should fail succeed with the correct params', async function () {
156 await makeGetRequest({
159 statusCodeExpected: 200,
162 actorType: 'Application'
168 describe('When listing followers', function () {
169 const path = '/api/v1/server/followers'
171 it('Should fail with a bad start pagination', async function () {
172 await checkBadStartPagination(server.url, path)
175 it('Should fail with a bad count pagination', async function () {
176 await checkBadCountPagination(server.url, path)
179 it('Should fail with an incorrect sort', async function () {
180 await checkBadSortPagination(server.url, path)
183 it('Should fail with an incorrect actor type', async function () {
184 await makeGetRequest({
193 it('Should fail with an incorrect state', async function () {
194 await makeGetRequest({
199 actorType: 'Application'
204 it('Should fail succeed with the correct params', async function () {
205 await makeGetRequest({
208 statusCodeExpected: 200,
216 describe('When removing a follower', function () {
217 const path = '/api/v1/server/followers'
219 it('Should fail with an invalid token', async function () {
220 await makeDeleteRequest({
222 path: path + '/toto@localhost:9002',
224 statusCodeExpected: 401
228 it('Should fail if the user is not an administrator', async function () {
229 await makeDeleteRequest({
231 path: path + '/toto@localhost:9002',
232 token: userAccessToken,
233 statusCodeExpected: 403
237 it('Should fail with an invalid follower', async function () {
238 await makeDeleteRequest({
240 path: path + '/toto',
241 token: server.accessToken,
242 statusCodeExpected: 400
246 it('Should fail with an unknown follower', async function () {
247 await makeDeleteRequest({
249 path: path + '/toto@localhost:9003',
250 token: server.accessToken,
251 statusCodeExpected: 404
256 describe('When accepting a follower', function () {
257 const path = '/api/v1/server/followers'
259 it('Should fail with an invalid token', async function () {
260 await makePostBodyRequest({
262 path: path + '/toto@localhost:9002/accept',
264 statusCodeExpected: 401
268 it('Should fail if the user is not an administrator', async function () {
269 await makePostBodyRequest({
271 path: path + '/toto@localhost:9002/accept',
272 token: userAccessToken,
273 statusCodeExpected: 403
277 it('Should fail with an invalid follower', async function () {
278 await makePostBodyRequest({
280 path: path + '/toto/accept',
281 token: server.accessToken,
282 statusCodeExpected: 400
286 it('Should fail with an unknown follower', async function () {
287 await makePostBodyRequest({
289 path: path + '/toto@localhost:9003/accept',
290 token: server.accessToken,
291 statusCodeExpected: 404
296 describe('When rejecting a follower', function () {
297 const path = '/api/v1/server/followers'
299 it('Should fail with an invalid token', async function () {
300 await makePostBodyRequest({
302 path: path + '/toto@localhost:9002/reject',
304 statusCodeExpected: 401
308 it('Should fail if the user is not an administrator', async function () {
309 await makePostBodyRequest({
311 path: path + '/toto@localhost:9002/reject',
312 token: userAccessToken,
313 statusCodeExpected: 403
317 it('Should fail with an invalid follower', async function () {
318 await makePostBodyRequest({
320 path: path + '/toto/reject',
321 token: server.accessToken,
322 statusCodeExpected: 400
326 it('Should fail with an unknown follower', async function () {
327 await makePostBodyRequest({
329 path: path + '/toto@localhost:9003/reject',
330 token: server.accessToken,
331 statusCodeExpected: 404
336 describe('When removing following', function () {
337 const path = '/api/v1/server/following'
339 it('Should fail with an invalid token', async function () {
340 await makeDeleteRequest({
342 path: path + '/localhost:9002',
344 statusCodeExpected: 401
348 it('Should fail if the user is not an administrator', async function () {
349 await makeDeleteRequest({
351 path: path + '/localhost:9002',
352 token: userAccessToken,
353 statusCodeExpected: 403
357 it('Should fail if we do not follow this server', async function () {
358 await makeDeleteRequest({
360 path: path + '/example.com',
361 token: server.accessToken,
362 statusCodeExpected: 404
368 after(async function () {
369 await cleanupTests([ server ])