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