1 /* tslint:disable:no-unused-expression */
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)
136 describe('When listing followers', function () {
137 const path = '/api/v1/server/followers'
139 it('Should fail with a bad start pagination', async function () {
140 await checkBadStartPagination(server.url, path)
143 it('Should fail with a bad count pagination', async function () {
144 await checkBadCountPagination(server.url, path)
147 it('Should fail with an incorrect sort', async function () {
148 await checkBadSortPagination(server.url, path)
152 describe('When removing a follower', function () {
153 const path = '/api/v1/server/followers'
155 it('Should fail with an invalid token', async function () {
156 await makeDeleteRequest({
158 path: path + '/toto@localhost:9002',
160 statusCodeExpected: 401
164 it('Should fail if the user is not an administrator', async function () {
165 await makeDeleteRequest({
167 path: path + '/toto@localhost:9002',
168 token: userAccessToken,
169 statusCodeExpected: 403
173 it('Should fail with an invalid follower', async function () {
174 await makeDeleteRequest({
176 path: path + '/toto',
177 token: server.accessToken,
178 statusCodeExpected: 400
182 it('Should fail with an unknown follower', async function () {
183 await makeDeleteRequest({
185 path: path + '/toto@localhost:9003',
186 token: server.accessToken,
187 statusCodeExpected: 404
192 describe('When accepting a follower', function () {
193 const path = '/api/v1/server/followers'
195 it('Should fail with an invalid token', async function () {
196 await makePostBodyRequest({
198 path: path + '/toto@localhost:9002/accept',
200 statusCodeExpected: 401
204 it('Should fail if the user is not an administrator', async function () {
205 await makePostBodyRequest({
207 path: path + '/toto@localhost:9002/accept',
208 token: userAccessToken,
209 statusCodeExpected: 403
213 it('Should fail with an invalid follower', async function () {
214 await makePostBodyRequest({
216 path: path + '/toto/accept',
217 token: server.accessToken,
218 statusCodeExpected: 400
222 it('Should fail with an unknown follower', async function () {
223 await makePostBodyRequest({
225 path: path + '/toto@localhost:9003/accept',
226 token: server.accessToken,
227 statusCodeExpected: 404
232 describe('When rejecting a follower', function () {
233 const path = '/api/v1/server/followers'
235 it('Should fail with an invalid token', async function () {
236 await makePostBodyRequest({
238 path: path + '/toto@localhost:9002/reject',
240 statusCodeExpected: 401
244 it('Should fail if the user is not an administrator', async function () {
245 await makePostBodyRequest({
247 path: path + '/toto@localhost:9002/reject',
248 token: userAccessToken,
249 statusCodeExpected: 403
253 it('Should fail with an invalid follower', async function () {
254 await makePostBodyRequest({
256 path: path + '/toto/reject',
257 token: server.accessToken,
258 statusCodeExpected: 400
262 it('Should fail with an unknown follower', async function () {
263 await makePostBodyRequest({
265 path: path + '/toto@localhost:9003/reject',
266 token: server.accessToken,
267 statusCodeExpected: 404
272 describe('When removing following', function () {
273 const path = '/api/v1/server/following'
275 it('Should fail with an invalid token', async function () {
276 await makeDeleteRequest({
278 path: path + '/localhost:9002',
280 statusCodeExpected: 401
284 it('Should fail if the user is not an administrator', async function () {
285 await makeDeleteRequest({
287 path: path + '/localhost:9002',
288 token: userAccessToken,
289 statusCodeExpected: 403
293 it('Should fail if we do not follow this server', async function () {
294 await makeDeleteRequest({
296 path: path + '/example.com',
297 token: server.accessToken,
298 statusCodeExpected: 404
304 after(async function () {
305 await cleanupTests([ server ])