diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-03 16:38:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-03 16:38:50 +0100 |
commit | 265ba139ebf56bbdc1c65f6ea4f367774c691fc0 (patch) | |
tree | c7c52d1ae48a35b8f9aa06a9fa2335a6ba502fd1 /server/tests | |
parent | 9bce811268cd74b402176ae9fcd8b77ac887576e (diff) | |
download | PeerTube-265ba139ebf56bbdc1c65f6ea4f367774c691fc0.tar.gz PeerTube-265ba139ebf56bbdc1c65f6ea4f367774c691fc0.tar.zst PeerTube-265ba139ebf56bbdc1c65f6ea4f367774c691fc0.zip |
Send account activitypub update events
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/accounts.ts | 51 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/fixtures/avatar2-resized.png | bin | 0 -> 2350 bytes | |||
-rw-r--r-- | server/tests/api/fixtures/avatar2.png | bin | 0 -> 4850 bytes | |||
-rw-r--r-- | server/tests/api/index-slow.ts | 1 | ||||
-rw-r--r-- | server/tests/api/users/users-multiple-servers.ts | 85 | ||||
-rw-r--r-- | server/tests/utils/users/accounts.ts | 29 |
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 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { flushTests, killallServers, runServer, ServerInfo } from '../../utils' | ||
6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | ||
7 | import { getAccount } from '../../utils/users/accounts' | ||
8 | |||
9 | describe('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 |
2 | import './accounts' | ||
2 | import './follows' | 3 | import './follows' |
3 | import './jobs' | 4 | import './jobs' |
4 | import './services' | 5 | import './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' | |||
5 | import './server/follows' | 5 | import './server/follows' |
6 | import './server/jobs' | 6 | import './server/jobs' |
7 | import './videos/video-comments' | 7 | import './videos/video-comments' |
8 | import './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 | |||
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 | }) | ||
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 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | |||
3 | function 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 | |||
14 | function 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 | |||
26 | export { | ||
27 | getAccount, | ||
28 | getAccountsList | ||
29 | } | ||