1 /* tslint:disable:no-unused-expression */
6 createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
8 } from '../../../../shared/utils'
10 checkBadCountPagination,
11 checkBadSortPagination,
12 checkBadStartPagination
13 } from '../../../../shared/utils/requests/check-api-params'
15 describe('Test server follows API validators', function () {
16 let server: ServerInfo
18 // ---------------------------------------------------------------
20 before(async function () {
24 server = await runServer(1)
26 await setAccessTokensToServers([ server ])
29 describe('When managing following', function () {
30 let userAccessToken = null
32 before(async function () {
38 await createUser(server.url, server.accessToken, user.username, user.password)
39 userAccessToken = await userLogin(server, user)
42 describe('When adding follows', function () {
43 const path = '/api/v1/server/following'
45 it('Should fail without hosts', async function () {
46 await makePostBodyRequest({
49 token: server.accessToken,
50 statusCodeExpected: 400
54 it('Should fail if hosts is not an array', async function () {
55 await makePostBodyRequest({
58 token: server.accessToken,
59 fields: { hosts: 'localhost:9002' },
60 statusCodeExpected: 400
64 it('Should fail if the array is not composed by hosts', async function () {
65 await makePostBodyRequest({
68 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
69 token: server.accessToken,
70 statusCodeExpected: 400
74 it('Should fail if the array is composed with http schemes', async function () {
75 await makePostBodyRequest({
78 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
79 token: server.accessToken,
80 statusCodeExpected: 400
84 it('Should fail if hosts are not unique', async function () {
85 await makePostBodyRequest({
88 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
89 token: server.accessToken,
90 statusCodeExpected: 400
94 it('Should fail with an invalid token', async function () {
95 await makePostBodyRequest({
98 fields: { hosts: [ 'localhost:9002' ] },
100 statusCodeExpected: 401
104 it('Should fail if the user is not an administrator', async function () {
105 await makePostBodyRequest({
108 fields: { hosts: [ 'localhost:9002' ] },
109 token: userAccessToken,
110 statusCodeExpected: 403
115 describe('When listing followings', function () {
116 const path = '/api/v1/server/following'
118 it('Should fail with a bad start pagination', async function () {
119 await checkBadStartPagination(server.url, path)
122 it('Should fail with a bad count pagination', async function () {
123 await checkBadCountPagination(server.url, path)
126 it('Should fail with an incorrect sort', async function () {
127 await checkBadSortPagination(server.url, path)
131 describe('When listing followers', function () {
132 const path = '/api/v1/server/followers'
134 it('Should fail with a bad start pagination', async function () {
135 await checkBadStartPagination(server.url, path)
138 it('Should fail with a bad count pagination', async function () {
139 await checkBadCountPagination(server.url, path)
142 it('Should fail with an incorrect sort', async function () {
143 await checkBadSortPagination(server.url, path)
147 describe('When removing a follower', function () {
148 const path = '/api/v1/server/followers'
150 it('Should fail with an invalid token', async function () {
151 await makeDeleteRequest({
153 path: path + '/toto@localhost:9002',
155 statusCodeExpected: 401
159 it('Should fail if the user is not an administrator', async function () {
160 await makeDeleteRequest({
162 path: path + '/toto@localhost:9002',
163 token: userAccessToken,
164 statusCodeExpected: 403
168 it('Should fail with an invalid follower', async function () {
169 await makeDeleteRequest({
171 path: path + '/toto',
172 token: server.accessToken,
173 statusCodeExpected: 400
177 it('Should fail with an unknown follower', async function () {
178 await makeDeleteRequest({
180 path: path + '/toto@localhost:9003',
181 token: server.accessToken,
182 statusCodeExpected: 404
187 describe('When accepting a follower', function () {
188 const path = '/api/v1/server/followers'
190 it('Should fail with an invalid token', async function () {
191 await makePostBodyRequest({
193 path: path + '/toto@localhost:9002/accept',
195 statusCodeExpected: 401
199 it('Should fail if the user is not an administrator', async function () {
200 await makePostBodyRequest({
202 path: path + '/toto@localhost:9002/accept',
203 token: userAccessToken,
204 statusCodeExpected: 403
208 it('Should fail with an invalid follower', async function () {
209 await makePostBodyRequest({
211 path: path + '/toto/accept',
212 token: server.accessToken,
213 statusCodeExpected: 400
217 it('Should fail with an unknown follower', async function () {
218 await makePostBodyRequest({
220 path: path + '/toto@localhost:9003/accept',
221 token: server.accessToken,
222 statusCodeExpected: 404
227 describe('When rejecting a follower', function () {
228 const path = '/api/v1/server/followers'
230 it('Should fail with an invalid token', async function () {
231 await makePostBodyRequest({
233 path: path + '/toto@localhost:9002/reject',
235 statusCodeExpected: 401
239 it('Should fail if the user is not an administrator', async function () {
240 await makePostBodyRequest({
242 path: path + '/toto@localhost:9002/reject',
243 token: userAccessToken,
244 statusCodeExpected: 403
248 it('Should fail with an invalid follower', async function () {
249 await makePostBodyRequest({
251 path: path + '/toto/reject',
252 token: server.accessToken,
253 statusCodeExpected: 400
257 it('Should fail with an unknown follower', async function () {
258 await makePostBodyRequest({
260 path: path + '/toto@localhost:9003/reject',
261 token: server.accessToken,
262 statusCodeExpected: 404
267 describe('When removing following', function () {
268 const path = '/api/v1/server/following'
270 it('Should fail with an invalid token', async function () {
271 await makeDeleteRequest({
273 path: path + '/localhost:9002',
275 statusCodeExpected: 401
279 it('Should fail if the user is not an administrator', async function () {
280 await makeDeleteRequest({
282 path: path + '/localhost:9002',
283 token: userAccessToken,
284 statusCodeExpected: 403
288 it('Should fail if we do not follow this server', async function () {
289 await makeDeleteRequest({
291 path: path + '/example.com',
292 token: server.accessToken,
293 statusCodeExpected: 404
299 after(async function () {
300 killallServers([ server ])
302 // Keep the logs if the test failed