Support video quota on client
[oweals/peertube.git] / server / tests / api / users / users-multiple-servers.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { Account } from '../../../../shared/models/actors'
6 import { doubleFollow, flushAndRunMultipleServers, wait } from '../../utils'
7 import {
8   flushTests, getMyUserInformation, killallServers, ServerInfo, testVideoImage, updateMyAvatar,
9   uploadVideo
10 } from '../../utils/index'
11 import { getAccount, getAccountsList } from '../../utils/users/accounts'
12 import { setAccessTokensToServers } from '../../utils/users/login'
13
14 const expect = chai.expect
15
16 describe('Test users with multiple servers', function () {
17   let servers: ServerInfo[] = []
18
19   before(async function () {
20     this.timeout(120000)
21
22     servers = await flushAndRunMultipleServers(3)
23
24     // Get the access tokens
25     await setAccessTokensToServers(servers)
26
27     // Server 1 and server 2 follow each other
28     await doubleFollow(servers[0], servers[1])
29     // Server 1 and server 3 follow each other
30     await doubleFollow(servers[0], servers[2])
31     // Server 2 and server 3 follow each other
32     await doubleFollow(servers[1], servers[2])
33
34     // The root user of server 1 is propagated to servers 2 and 3
35     await uploadVideo(servers[0].url, servers[0].accessToken, {})
36
37     await wait(5000)
38   })
39
40   it('Should be able to update my avatar', async function () {
41     this.timeout(10000)
42
43     const fixture = 'avatar2.png'
44
45     await updateMyAvatar({
46       url: servers[0].url,
47       accessToken: servers[0].accessToken,
48       fixture
49     })
50
51     const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
52     const user = res.body
53
54     const test = await testVideoImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png')
55     expect(test).to.equal(true)
56
57     await wait(5000)
58   })
59
60   it('Should have updated my avatar on other servers too', async function () {
61     for (const server of servers) {
62       const resAccounts = await getAccountsList(server.url, '-createdAt')
63
64       const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:9001') as Account
65       expect(rootServer1List).not.to.be.undefined
66
67       const resAccount = await getAccount(server.url, rootServer1List.id)
68       const rootServer1Get = resAccount.body as Account
69       expect(rootServer1Get.name).to.equal('root')
70       expect(rootServer1Get.host).to.equal('localhost:9001')
71
72       const test = await testVideoImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
73       expect(test).to.equal(true)
74     }
75   })
76
77   after(async function () {
78     killallServers(servers)
79
80     // Keep the logs if the test failed
81     if (this[ 'ok' ]) {
82       await flushTests()
83     }
84   })
85 })