1 /* tslint:disable:no-unused-expression */
6 createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
9 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
11 describe('Test server follows API validators', function () {
12 let server: ServerInfo
14 // ---------------------------------------------------------------
16 before(async function () {
20 server = await runServer(1)
22 await setAccessTokensToServers([ server ])
25 describe('When managing following', function () {
26 let userAccessToken = null
28 before(async function () {
34 await createUser(server.url, server.accessToken, user.username, user.password)
35 userAccessToken = await userLogin(server, user)
38 describe('When adding follows', function () {
39 const path = '/api/v1/server/following'
41 it('Should fail without hosts', async function () {
42 await makePostBodyRequest({
45 token: server.accessToken,
46 statusCodeExpected: 400
50 it('Should fail if hosts is not an array', async function () {
51 await makePostBodyRequest({
54 token: server.accessToken,
55 fields: { hosts: 'localhost:9002' },
56 statusCodeExpected: 400
60 it('Should fail if the array is not composed by hosts', async function () {
61 await makePostBodyRequest({
64 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
65 token: server.accessToken,
66 statusCodeExpected: 400
70 it('Should fail if the array is composed with http schemes', async function () {
71 await makePostBodyRequest({
74 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
75 token: server.accessToken,
76 statusCodeExpected: 400
80 it('Should fail if hosts are not unique', async function () {
81 await makePostBodyRequest({
84 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
85 token: server.accessToken,
86 statusCodeExpected: 400
90 it('Should fail with an invalid token', async function () {
91 await makePostBodyRequest({
94 fields: { hosts: [ 'localhost:9002' ] },
96 statusCodeExpected: 401
100 it('Should fail if the user is not an administrator', async function () {
101 await makePostBodyRequest({
104 fields: { hosts: [ 'localhost:9002' ] },
105 token: userAccessToken,
106 statusCodeExpected: 403
111 describe('When listing followings', function () {
112 const path = '/api/v1/server/following'
114 it('Should fail with a bad start pagination', async function () {
115 await checkBadStartPagination(server.url, path)
118 it('Should fail with a bad count pagination', async function () {
119 await checkBadCountPagination(server.url, path)
122 it('Should fail with an incorrect sort', async function () {
123 await checkBadSortPagination(server.url, path)
127 describe('When listing followers', function () {
128 const path = '/api/v1/server/followers'
130 it('Should fail with a bad start pagination', async function () {
131 await checkBadStartPagination(server.url, path)
134 it('Should fail with a bad count pagination', async function () {
135 await checkBadCountPagination(server.url, path)
138 it('Should fail with an incorrect sort', async function () {
139 await checkBadSortPagination(server.url, path)
143 describe('When removing following', function () {
144 const path = '/api/v1/server/following'
146 it('Should fail with an invalid token', async function () {
147 await makeDeleteRequest({
149 path: path + '/localhost:9002',
151 statusCodeExpected: 401
155 it('Should fail if the user is not an administrator', async function () {
156 await makeDeleteRequest({
158 path: path + '/localhost:9002',
159 token: userAccessToken,
160 statusCodeExpected: 403
164 it('Should fail if we do not follow this server', async function () {
165 await makeDeleteRequest({
167 path: path + '/example.com',
168 token: server.accessToken,
169 statusCodeExpected: 404
175 after(async function () {
176 killallServers([ server ])
178 // Keep the logs if the test failed