diff options
Diffstat (limited to 'server/tests/api/activitypub/fetch.ts')
-rw-r--r-- | server/tests/api/activitypub/fetch.ts | 51 |
1 files changed, 15 insertions, 36 deletions
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 35fd94eed..422a75d6e 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts | |||
@@ -1,61 +1,44 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | |||
5 | import { | ||
6 | cleanupTests, | ||
7 | closeAllSequelize, | ||
8 | createUser, | ||
9 | doubleFollow, | ||
10 | flushAndRunMultipleServers, | ||
11 | getVideosListSort, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers, | ||
14 | setActorField, | ||
15 | setVideoField, | ||
16 | uploadVideo, | ||
17 | userLogin, | ||
18 | waitJobs | ||
19 | } from '../../../../shared/extra-utils' | ||
20 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
21 | import { Video } from '../../../../shared/models/videos' | 5 | import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' |
22 | 6 | ||
23 | const expect = chai.expect | 7 | const expect = chai.expect |
24 | 8 | ||
25 | describe('Test ActivityPub fetcher', function () { | 9 | describe('Test ActivityPub fetcher', function () { |
26 | let servers: ServerInfo[] | 10 | let servers: PeerTubeServer[] |
27 | 11 | ||
28 | // --------------------------------------------------------------- | 12 | // --------------------------------------------------------------- |
29 | 13 | ||
30 | before(async function () { | 14 | before(async function () { |
31 | this.timeout(60000) | 15 | this.timeout(60000) |
32 | 16 | ||
33 | servers = await flushAndRunMultipleServers(3) | 17 | servers = await createMultipleServers(3) |
34 | 18 | ||
35 | // Get the access tokens | 19 | // Get the access tokens |
36 | await setAccessTokensToServers(servers) | 20 | await setAccessTokensToServers(servers) |
37 | 21 | ||
38 | const user = { username: 'user1', password: 'password' } | 22 | const user = { username: 'user1', password: 'password' } |
39 | for (const server of servers) { | 23 | for (const server of servers) { |
40 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | 24 | await server.users.create({ username: user.username, password: user.password }) |
41 | } | 25 | } |
42 | 26 | ||
43 | const userAccessToken = await userLogin(servers[0], user) | 27 | const userAccessToken = await servers[0].login.getAccessToken(user) |
44 | 28 | ||
45 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) | 29 | await servers[0].videos.upload({ attributes: { name: 'video root' } }) |
46 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) | 30 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'bad video root' } }) |
47 | const badVideoUUID = res.body.video.uuid | 31 | await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'video user' } }) |
48 | await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' }) | ||
49 | 32 | ||
50 | { | 33 | { |
51 | const to = 'http://localhost:' + servers[0].port + '/accounts/user1' | 34 | const to = 'http://localhost:' + servers[0].port + '/accounts/user1' |
52 | const value = 'http://localhost:' + servers[1].port + '/accounts/user1' | 35 | const value = 'http://localhost:' + servers[1].port + '/accounts/user1' |
53 | await setActorField(servers[0].internalServerNumber, to, 'url', value) | 36 | await servers[0].sql.setActorField(to, 'url', value) |
54 | } | 37 | } |
55 | 38 | ||
56 | { | 39 | { |
57 | const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID | 40 | const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid |
58 | await setVideoField(servers[0].internalServerNumber, badVideoUUID, 'url', value) | 41 | await servers[0].sql.setVideoField(uuid, 'url', value) |
59 | } | 42 | } |
60 | }) | 43 | }) |
61 | 44 | ||
@@ -66,20 +49,18 @@ describe('Test ActivityPub fetcher', function () { | |||
66 | await waitJobs(servers) | 49 | await waitJobs(servers) |
67 | 50 | ||
68 | { | 51 | { |
69 | const res = await getVideosListSort(servers[0].url, 'createdAt') | 52 | const { total, data } = await servers[0].videos.list({ sort: 'createdAt' }) |
70 | expect(res.body.total).to.equal(3) | ||
71 | 53 | ||
72 | const data: Video[] = res.body.data | 54 | expect(total).to.equal(3) |
73 | expect(data[0].name).to.equal('video root') | 55 | expect(data[0].name).to.equal('video root') |
74 | expect(data[1].name).to.equal('bad video root') | 56 | expect(data[1].name).to.equal('bad video root') |
75 | expect(data[2].name).to.equal('video user') | 57 | expect(data[2].name).to.equal('video user') |
76 | } | 58 | } |
77 | 59 | ||
78 | { | 60 | { |
79 | const res = await getVideosListSort(servers[1].url, 'createdAt') | 61 | const { total, data } = await servers[1].videos.list({ sort: 'createdAt' }) |
80 | expect(res.body.total).to.equal(1) | ||
81 | 62 | ||
82 | const data: Video[] = res.body.data | 63 | expect(total).to.equal(1) |
83 | expect(data[0].name).to.equal('video root') | 64 | expect(data[0].name).to.equal('video root') |
84 | } | 65 | } |
85 | }) | 66 | }) |
@@ -88,7 +69,5 @@ describe('Test ActivityPub fetcher', function () { | |||
88 | this.timeout(20000) | 69 | this.timeout(20000) |
89 | 70 | ||
90 | await cleanupTests(servers) | 71 | await cleanupTests(servers) |
91 | |||
92 | await closeAllSequelize(servers) | ||
93 | }) | 72 | }) |
94 | }) | 73 | }) |