1 /* tslint:disable:no-unused-expression */
8 flushAndRunMultipleServers,
13 setAccessTokensToServers,
15 } from '../../../../shared/utils'
17 describe('Test server redundancy API validators', function () {
18 let servers: ServerInfo[]
19 let userAccessToken = null
21 // ---------------------------------------------------------------
23 before(async function () {
27 servers = await flushAndRunMultipleServers(2)
29 await setAccessTokensToServers(servers)
30 await doubleFollow(servers[0], servers[1])
37 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
38 userAccessToken = await userLogin(servers[0], user)
41 describe('When updating redundancy', function () {
42 const path = '/api/v1/server/redundancy'
44 it('Should fail with an invalid token', async function () {
45 await makePutBodyRequest({
47 path: path + '/localhost:9002',
48 fields: { redundancyAllowed: true },
50 statusCodeExpected: 401
54 it('Should fail if the user is not an administrator', async function () {
55 await makePutBodyRequest({
57 path: path + '/localhost:9002',
58 fields: { redundancyAllowed: true },
59 token: userAccessToken,
60 statusCodeExpected: 403
64 it('Should fail if we do not follow this server', async function () {
65 await makePutBodyRequest({
67 path: path + '/example.com',
68 fields: { redundancyAllowed: true },
69 token: servers[0].accessToken,
70 statusCodeExpected: 404
74 it('Should fail without de redundancyAllowed param', async function () {
75 await makePutBodyRequest({
77 path: path + '/localhost:9002',
78 fields: { blabla: true },
79 token: servers[0].accessToken,
80 statusCodeExpected: 400
84 it('Should succeed with the correct parameters', async function () {
85 await makePutBodyRequest({
87 path: path + '/localhost:9002',
88 fields: { redundancyAllowed: true },
89 token: servers[0].accessToken,
90 statusCodeExpected: 204
95 after(async function () {
96 killallServers(servers)
98 // Keep the logs if the test failed