diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/activitypub/fetch.ts | 86 | ||||
-rw-r--r-- | server/tests/api/activitypub/index.ts | 1 |
2 files changed, 87 insertions, 0 deletions
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts new file mode 100644 index 000000000..a42c606c6 --- /dev/null +++ b/server/tests/api/activitypub/fetch.ts | |||
@@ -0,0 +1,86 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { | ||
6 | createUser, | ||
7 | doubleFollow, | ||
8 | flushAndRunMultipleServers, | ||
9 | flushTests, | ||
10 | getVideosListSort, | ||
11 | killallServers, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers, | ||
14 | uploadVideo, | ||
15 | userLogin | ||
16 | } from '../../utils' | ||
17 | import * as chai from 'chai' | ||
18 | import { setActorField, setVideoField } from '../../utils/miscs/sql' | ||
19 | import { waitJobs } from '../../utils/server/jobs' | ||
20 | import { Video } from '../../../../shared/models/videos' | ||
21 | |||
22 | const expect = chai.expect | ||
23 | |||
24 | describe('Test ActivityPub fetcher', function () { | ||
25 | let servers: ServerInfo[] | ||
26 | |||
27 | // --------------------------------------------------------------- | ||
28 | |||
29 | before(async function () { | ||
30 | this.timeout(60000) | ||
31 | |||
32 | servers = await flushAndRunMultipleServers(3) | ||
33 | |||
34 | // Get the access tokens | ||
35 | await setAccessTokensToServers(servers) | ||
36 | |||
37 | const user = { username: 'user1', password: 'password' } | ||
38 | for (const server of servers) { | ||
39 | await createUser(server.url, server.accessToken, user.username, user.password) | ||
40 | } | ||
41 | |||
42 | const userAccessToken = await userLogin(servers[0], user) | ||
43 | |||
44 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) | ||
45 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) | ||
46 | const badVideoUUID = res.body.video.uuid | ||
47 | await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' }) | ||
48 | |||
49 | await setActorField(1, 'http://localhost:9001/accounts/user1', 'url', 'http://localhost:9002/accounts/user1') | ||
50 | await setVideoField(1, badVideoUUID, 'url', 'http://localhost:9003/videos/watch/' + badVideoUUID) | ||
51 | }) | ||
52 | |||
53 | it('Should add only the video with a valid actor URL', async function () { | ||
54 | this.timeout(60000) | ||
55 | |||
56 | await doubleFollow(servers[0], servers[1]) | ||
57 | await waitJobs(servers) | ||
58 | |||
59 | { | ||
60 | const res = await getVideosListSort(servers[0].url, 'createdAt') | ||
61 | expect(res.body.total).to.equal(3) | ||
62 | |||
63 | const data: Video[] = res.body.data | ||
64 | expect(data[0].name).to.equal('video root') | ||
65 | expect(data[1].name).to.equal('bad video root') | ||
66 | expect(data[2].name).to.equal('video user') | ||
67 | } | ||
68 | |||
69 | { | ||
70 | const res = await getVideosListSort(servers[1].url, 'createdAt') | ||
71 | expect(res.body.total).to.equal(1) | ||
72 | |||
73 | const data: Video[] = res.body.data | ||
74 | expect(data[0].name).to.equal('video root') | ||
75 | } | ||
76 | }) | ||
77 | |||
78 | after(async function () { | ||
79 | killallServers(servers) | ||
80 | |||
81 | // Keep the logs if the test failed | ||
82 | if (this['ok']) { | ||
83 | await flushTests() | ||
84 | } | ||
85 | }) | ||
86 | }) | ||
diff --git a/server/tests/api/activitypub/index.ts b/server/tests/api/activitypub/index.ts index de8a59978..e748f32e9 100644 --- a/server/tests/api/activitypub/index.ts +++ b/server/tests/api/activitypub/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import './client' | 1 | import './client' |
2 | import './fetch' | ||
2 | import './helpers' | 3 | import './helpers' |
3 | import './security' | 4 | import './security' |