1 /* tslint:disable:no-unused-expression */
8 flushAndRunMultipleServers,
13 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
17 describe('Test server redundancy API validators', function () {
18 let servers: ServerInfo[]
19 let userAccessToken = null
21 // ---------------------------------------------------------------
23 before(async function () {
26 servers = await flushAndRunMultipleServers(2)
28 await setAccessTokensToServers(servers)
29 await doubleFollow(servers[0], servers[1])
36 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
37 userAccessToken = await userLogin(servers[0], user)
40 describe('When updating redundancy', function () {
41 const path = '/api/v1/server/redundancy'
43 it('Should fail with an invalid token', async function () {
44 await makePutBodyRequest({
46 path: path + '/localhost:9002',
47 fields: { redundancyAllowed: true },
49 statusCodeExpected: 401
53 it('Should fail if the user is not an administrator', async function () {
54 await makePutBodyRequest({
56 path: path + '/localhost:9002',
57 fields: { redundancyAllowed: true },
58 token: userAccessToken,
59 statusCodeExpected: 403
63 it('Should fail if we do not follow this server', async function () {
64 await makePutBodyRequest({
66 path: path + '/example.com',
67 fields: { redundancyAllowed: true },
68 token: servers[0].accessToken,
69 statusCodeExpected: 404
73 it('Should fail without de redundancyAllowed param', async function () {
74 await makePutBodyRequest({
76 path: path + '/localhost:9002',
77 fields: { blabla: true },
78 token: servers[0].accessToken,
79 statusCodeExpected: 400
83 it('Should succeed with the correct parameters', async function () {
84 await makePutBodyRequest({
86 path: path + '/localhost:9002',
87 fields: { redundancyAllowed: true },
88 token: servers[0].accessToken,
89 statusCodeExpected: 204
95 killallServers(servers)