aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/accounts.ts51
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/fixtures/avatar2-resized.pngbin0 -> 2350 bytes
-rw-r--r--server/tests/api/fixtures/avatar2.pngbin0 -> 4850 bytes
-rw-r--r--server/tests/api/index-slow.ts1
-rw-r--r--server/tests/api/users/users-multiple-servers.ts85
-rw-r--r--server/tests/utils/users/accounts.ts29
7 files changed, 167 insertions, 0 deletions
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts
new file mode 100644
index 000000000..351228754
--- /dev/null
+++ b/server/tests/api/check-params/accounts.ts
@@ -0,0 +1,51 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import { flushTests, killallServers, runServer, ServerInfo } from '../../utils'
6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
7import { getAccount } from '../../utils/users/accounts'
8
9describe('Test users API validators', function () {
10 const path = '/api/v1/accounts/'
11 let server: ServerInfo
12
13 // ---------------------------------------------------------------
14
15 before(async function () {
16 this.timeout(20000)
17
18 await flushTests()
19
20 server = await runServer(1)
21 })
22
23 describe('When listing accounts', function () {
24 it('Should fail with a bad start pagination', async function () {
25 await checkBadStartPagination(server.url, path, server.accessToken)
26 })
27
28 it('Should fail with a bad count pagination', async function () {
29 await checkBadCountPagination(server.url, path, server.accessToken)
30 })
31
32 it('Should fail with an incorrect sort', async function () {
33 await checkBadSortPagination(server.url, path, server.accessToken)
34 })
35 })
36
37 describe('When getting an account', function () {
38 it('Should return 404 with a non existing id', async function () {
39 await getAccount(server.url, 4545454, 404)
40 })
41 })
42
43 after(async function () {
44 killallServers([ server ])
45
46 // Keep the logs if the test failed
47 if (this['ok']) {
48 await flushTests()
49 }
50 })
51})
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index ab0aa1580..4c3b372f5 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -1,4 +1,5 @@
1// Order of the tests we want to execute 1// Order of the tests we want to execute
2import './accounts'
2import './follows' 3import './follows'
3import './jobs' 4import './jobs'
4import './services' 5import './services'
diff --git a/server/tests/api/fixtures/avatar2-resized.png b/server/tests/api/fixtures/avatar2-resized.png
new file mode 100644
index 000000000..a2e2613bf
--- /dev/null
+++ b/server/tests/api/fixtures/avatar2-resized.png
Binary files differ
diff --git a/server/tests/api/fixtures/avatar2.png b/server/tests/api/fixtures/avatar2.png
new file mode 100644
index 000000000..dae702190
--- /dev/null
+++ b/server/tests/api/fixtures/avatar2.png
Binary files differ
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts
index 23b6526c7..fe86fc018 100644
--- a/server/tests/api/index-slow.ts
+++ b/server/tests/api/index-slow.ts
@@ -5,3 +5,4 @@ import './videos/multiple-servers'
5import './server/follows' 5import './server/follows'
6import './server/jobs' 6import './server/jobs'
7import './videos/video-comments' 7import './videos/video-comments'
8import './users/users-multiple-servers'
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
new file mode 100644
index 000000000..1c7f011a8
--- /dev/null
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -0,0 +1,85 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { Account } from '../../../../shared/models/actors'
6import { doubleFollow, flushAndRunMultipleServers, wait } from '../../utils'
7import {
8 flushTests, getMyUserInformation, killallServers, ServerInfo, testVideoImage, updateMyAvatar,
9 uploadVideo
10} from '../../utils/index'
11import { getAccount, getAccountsList } from '../../utils/users/accounts'
12import { setAccessTokensToServers } from '../../utils/users/login'
13
14const expect = chai.expect
15
16describe('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})
diff --git a/server/tests/utils/users/accounts.ts b/server/tests/utils/users/accounts.ts
new file mode 100644
index 000000000..71712100e
--- /dev/null
+++ b/server/tests/utils/users/accounts.ts
@@ -0,0 +1,29 @@
1import { makeGetRequest } from '../requests/requests'
2
3function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
4 const path = '/api/v1/accounts'
5
6 return makeGetRequest({
7 url,
8 query: { sort },
9 path,
10 statusCodeExpected
11 })
12}
13
14function getAccount (url: string, accountId: number | string, statusCodeExpected = 200) {
15 const path = '/api/v1/accounts/' + accountId
16
17 return makeGetRequest({
18 url,
19 path,
20 statusCodeExpected
21 })
22}
23
24// ---------------------------------------------------------------------------
25
26export {
27 getAccount,
28 getAccountsList
29}