]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/redundancy.ts
Cleanup tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / redundancy.ts
CommitLineData
c48e82b5
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 flushTests,
10 killallServers,
11 makePutBodyRequest,
12 ServerInfo,
13 setAccessTokensToServers,
14 userLogin
94565d52 15} from '../../../../shared/extra-utils'
c48e82b5
C
16
17describe('Test server redundancy API validators', function () {
18 let servers: ServerInfo[]
19 let userAccessToken = null
20
21 // ---------------------------------------------------------------
22
23 before(async function () {
24 this.timeout(30000)
25
c48e82b5
C
26 servers = await flushAndRunMultipleServers(2)
27
28 await setAccessTokensToServers(servers)
29 await doubleFollow(servers[0], servers[1])
30
31 const user = {
32 username: 'user1',
33 password: 'password'
34 }
35
1eddc9a7 36 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
c48e82b5
C
37 userAccessToken = await userLogin(servers[0], user)
38 })
39
40 describe('When updating redundancy', function () {
41 const path = '/api/v1/server/redundancy'
42
43 it('Should fail with an invalid token', async function () {
44 await makePutBodyRequest({
45 url: servers[0].url,
46 path: path + '/localhost:9002',
47 fields: { redundancyAllowed: true },
48 token: 'fake_token',
49 statusCodeExpected: 401
50 })
51 })
52
53 it('Should fail if the user is not an administrator', async function () {
54 await makePutBodyRequest({
55 url: servers[0].url,
56 path: path + '/localhost:9002',
57 fields: { redundancyAllowed: true },
58 token: userAccessToken,
59 statusCodeExpected: 403
60 })
61 })
62
63 it('Should fail if we do not follow this server', async function () {
64 await makePutBodyRequest({
65 url: servers[0].url,
66 path: path + '/example.com',
67 fields: { redundancyAllowed: true },
68 token: servers[0].accessToken,
69 statusCodeExpected: 404
70 })
71 })
72
73 it('Should fail without de redundancyAllowed param', async function () {
74 await makePutBodyRequest({
75 url: servers[0].url,
76 path: path + '/localhost:9002',
77 fields: { blabla: true },
78 token: servers[0].accessToken,
79 statusCodeExpected: 400
80 })
81 })
82
83 it('Should succeed with the correct parameters', async function () {
84 await makePutBodyRequest({
85 url: servers[0].url,
86 path: path + '/localhost:9002',
87 fields: { redundancyAllowed: true },
88 token: servers[0].accessToken,
89 statusCodeExpected: 204
90 })
91 })
92 })
93
210feb6c 94 after(function () {
c48e82b5 95 killallServers(servers)
c48e82b5
C
96 })
97})