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 following', function () {
148 const path = '/api/v1/server/following'
150 it('Should fail with an invalid token', async function () {
151 await makeDeleteRequest({
153 path: path + '/localhost:9002',
155 statusCodeExpected: 401
159 it('Should fail if the user is not an administrator', async function () {
160 await makeDeleteRequest({
162 path: path + '/localhost:9002',
163 token: userAccessToken,
164 statusCodeExpected: 403
168 it('Should fail if we do not follow this server', async function () {
169 await makeDeleteRequest({
171 path: path + '/example.com',
172 token: server.accessToken,
173 statusCodeExpected: 404
179 after(async function () {
180 killallServers([ server ])
182 // Keep the logs if the test failed