aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-15 10:02:54 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitd23dd9fbfc4d26026352c10f81d2795ceaf2908a (patch)
treeda82286d423c5e834a1ee2dcd5970076b8263cf1 /server/tests/api/activitypub
parent7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (diff)
downloadPeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.gz
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.zst
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.zip
Introduce videos command
Diffstat (limited to 'server/tests/api/activitypub')
-rw-r--r--server/tests/api/activitypub/cleaner.ts50
-rw-r--r--server/tests/api/activitypub/client.ts11
-rw-r--r--server/tests/api/activitypub/fetch.ts33
-rw-r--r--server/tests/api/activitypub/refresher.ts29
4 files changed, 52 insertions, 71 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts
index 5b08880bf..dcf758711 100644
--- a/server/tests/api/activitypub/cleaner.ts
+++ b/server/tests/api/activitypub/cleaner.ts
@@ -6,11 +6,8 @@ import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getVideo,
10 rateVideo,
11 ServerInfo, 9 ServerInfo,
12 setAccessTokensToServers, 10 setAccessTokensToServers,
13 uploadVideoAndGetId,
14 wait, 11 wait,
15 waitJobs 12 waitJobs
16} from '@shared/extra-utils' 13} from '@shared/extra-utils'
@@ -49,9 +46,9 @@ describe('Test AP cleaner', function () {
49 // Create 1 comment per video 46 // Create 1 comment per video
50 // Update 1 remote URL and 1 local URL on 47 // Update 1 remote URL and 1 local URL on
51 48
52 videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid 49 videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid
53 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid 50 videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
54 videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid 51 videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid
55 52
56 videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] 53 videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ]
57 54
@@ -59,7 +56,7 @@ describe('Test AP cleaner', function () {
59 56
60 for (const server of servers) { 57 for (const server of servers) {
61 for (const uuid of videoUUIDs) { 58 for (const uuid of videoUUIDs) {
62 await rateVideo(server.url, server.accessToken, uuid, 'like') 59 await server.videosCommand.rate({ id: uuid, rating: 'like' })
63 await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) 60 await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' })
64 } 61 }
65 } 62 }
@@ -70,9 +67,10 @@ describe('Test AP cleaner', function () {
70 it('Should have the correct likes', async function () { 67 it('Should have the correct likes', async function () {
71 for (const server of servers) { 68 for (const server of servers) {
72 for (const uuid of videoUUIDs) { 69 for (const uuid of videoUUIDs) {
73 const res = await getVideo(server.url, uuid) 70 const video = await server.videosCommand.get({ id: uuid })
74 expect(res.body.likes).to.equal(3) 71
75 expect(res.body.dislikes).to.equal(0) 72 expect(video.likes).to.equal(3)
73 expect(video.dislikes).to.equal(0)
76 } 74 }
77 } 75 }
78 }) 76 })
@@ -90,16 +88,16 @@ describe('Test AP cleaner', function () {
90 88
91 // Updated rates of my video 89 // Updated rates of my video
92 { 90 {
93 const res = await getVideo(servers[0].url, videoUUID1) 91 const video = await servers[0].videosCommand.get({ id: videoUUID1 })
94 expect(res.body.likes).to.equal(2) 92 expect(video.likes).to.equal(2)
95 expect(res.body.dislikes).to.equal(0) 93 expect(video.dislikes).to.equal(0)
96 } 94 }
97 95
98 // Did not update rates of a remote video 96 // Did not update rates of a remote video
99 { 97 {
100 const res = await getVideo(servers[0].url, videoUUID2) 98 const video = await servers[0].videosCommand.get({ id: videoUUID2 })
101 expect(res.body.likes).to.equal(3) 99 expect(video.likes).to.equal(3)
102 expect(res.body.dislikes).to.equal(0) 100 expect(video.dislikes).to.equal(0)
103 } 101 }
104 }) 102 })
105 103
@@ -108,7 +106,7 @@ describe('Test AP cleaner', function () {
108 106
109 for (const server of servers) { 107 for (const server of servers) {
110 for (const uuid of videoUUIDs) { 108 for (const uuid of videoUUIDs) {
111 await rateVideo(server.url, server.accessToken, uuid, 'dislike') 109 await server.videosCommand.rate({ id: uuid, rating: 'dislike' })
112 } 110 }
113 } 111 }
114 112
@@ -116,9 +114,9 @@ describe('Test AP cleaner', function () {
116 114
117 for (const server of servers) { 115 for (const server of servers) {
118 for (const uuid of videoUUIDs) { 116 for (const uuid of videoUUIDs) {
119 const res = await getVideo(server.url, uuid) 117 const video = await server.videosCommand.get({ id: uuid })
120 expect(res.body.likes).to.equal(0) 118 expect(video.likes).to.equal(0)
121 expect(res.body.dislikes).to.equal(3) 119 expect(video.dislikes).to.equal(3)
122 } 120 }
123 } 121 }
124 }) 122 })
@@ -137,16 +135,16 @@ describe('Test AP cleaner', function () {
137 135
138 // Updated rates of my video 136 // Updated rates of my video
139 { 137 {
140 const res = await getVideo(servers[0].url, videoUUID1) 138 const video = await servers[0].videosCommand.get({ id: videoUUID1 })
141 expect(res.body.likes).to.equal(0) 139 expect(video.likes).to.equal(0)
142 expect(res.body.dislikes).to.equal(2) 140 expect(video.dislikes).to.equal(2)
143 } 141 }
144 142
145 // Did not update rates of a remote video 143 // Did not update rates of a remote video
146 { 144 {
147 const res = await getVideo(servers[0].url, videoUUID2) 145 const video = await servers[0].videosCommand.get({ id: videoUUID2 })
148 expect(res.body.likes).to.equal(0) 146 expect(video.likes).to.equal(0)
149 expect(res.body.dislikes).to.equal(3) 147 expect(video.dislikes).to.equal(3)
150 } 148 }
151 }) 149 })
152 150
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts
index e8536a214..0190df04c 100644
--- a/server/tests/api/activitypub/client.ts
+++ b/server/tests/api/activitypub/client.ts
@@ -2,8 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPlaylistPrivacy } from '@shared/models' 5import { HttpStatusCode } from '@shared/core-utils'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 cleanupTests, 7 cleanupTests,
9 doubleFollow, 8 doubleFollow,
@@ -11,9 +10,9 @@ import {
11 makeActivityPubGetRequest, 10 makeActivityPubGetRequest,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 setDefaultVideoChannel, 13 setDefaultVideoChannel
15 uploadVideoAndGetId 14} from '@shared/extra-utils'
16} from '../../../../shared/extra-utils' 15import { VideoPlaylistPrivacy } from '@shared/models'
17 16
18const expect = chai.expect 17const expect = chai.expect
19 18
@@ -69,7 +68,7 @@ describe('Test activitypub', function () {
69 await setDefaultVideoChannel(servers) 68 await setDefaultVideoChannel(servers)
70 69
71 { 70 {
72 video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' }) 71 video = await await servers[0].videosCommand.quickUpload({ name: 'video' })
73 } 72 }
74 73
75 { 74 {
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index 162f3ec83..5ab4a85d7 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -2,17 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6 cleanupTests,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 getVideosListSort,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo,
13 waitJobs
14} from '../../../../shared/extra-utils'
15import { Video } from '../../../../shared/models/videos'
16 6
17const expect = chai.expect 7const expect = chai.expect
18 8
@@ -36,10 +26,9 @@ describe('Test ActivityPub fetcher', function () {
36 26
37 const userAccessToken = await servers[0].loginCommand.getAccessToken(user) 27 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
38 28
39 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) 29 await servers[0].videosCommand.upload({ attributes: { name: 'video root' } })
40 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) 30 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } })
41 const badVideoUUID = res.body.video.uuid 31 await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } })
42 await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
43 32
44 { 33 {
45 const to = 'http://localhost:' + servers[0].port + '/accounts/user1' 34 const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
@@ -48,8 +37,8 @@ describe('Test ActivityPub fetcher', function () {
48 } 37 }
49 38
50 { 39 {
51 const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID 40 const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid
52 await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) 41 await servers[0].sqlCommand.setVideoField(uuid, 'url', value)
53 } 42 }
54 }) 43 })
55 44
@@ -60,20 +49,18 @@ describe('Test ActivityPub fetcher', function () {
60 await waitJobs(servers) 49 await waitJobs(servers)
61 50
62 { 51 {
63 const res = await getVideosListSort(servers[0].url, 'createdAt') 52 const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' })
64 expect(res.body.total).to.equal(3)
65 53
66 const data: Video[] = res.body.data 54 expect(total).to.equal(3)
67 expect(data[0].name).to.equal('video root') 55 expect(data[0].name).to.equal('video root')
68 expect(data[1].name).to.equal('bad video root') 56 expect(data[1].name).to.equal('bad video root')
69 expect(data[2].name).to.equal('video user') 57 expect(data[2].name).to.equal('video user')
70 } 58 }
71 59
72 { 60 {
73 const res = await getVideosListSort(servers[1].url, 'createdAt') 61 const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' })
74 expect(res.body.total).to.equal(1)
75 62
76 const data: Video[] = res.body.data 63 expect(total).to.equal(1)
77 expect(data[0].name).to.equal('video root') 64 expect(data[0].name).to.equal('video root')
78 } 65 }
79 }) 66 })
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index 5a37dbc40..5af4b1edb 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -6,14 +6,11 @@ import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getVideo,
10 killallServers, 9 killallServers,
11 reRunServer, 10 reRunServer,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 setDefaultVideoChannel, 13 setDefaultVideoChannel,
15 uploadVideo,
16 uploadVideoAndGetId,
17 wait, 14 wait,
18 waitJobs 15 waitJobs
19} from '@shared/extra-utils' 16} from '@shared/extra-utils'
@@ -37,17 +34,17 @@ describe('Test AP refresher', function () {
37 await setDefaultVideoChannel(servers) 34 await setDefaultVideoChannel(servers)
38 35
39 { 36 {
40 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid 37 videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid
41 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid 38 videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid
42 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid 39 videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid
43 } 40 }
44 41
45 { 42 {
46 const a1 = await servers[1].usersCommand.generateUserAndToken('user1') 43 const token1 = await servers[1].usersCommand.generateUserAndToken('user1')
47 await uploadVideo(servers[1].url, a1, { name: 'video4' }) 44 await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } })
48 45
49 const a2 = await servers[1].usersCommand.generateUserAndToken('user2') 46 const token2 = await servers[1].usersCommand.generateUserAndToken('user2')
50 await uploadVideo(servers[1].url, a2, { name: 'video5' }) 47 await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } })
51 } 48 }
52 49
53 { 50 {
@@ -75,13 +72,13 @@ describe('Test AP refresher', function () {
75 // Change UUID so the remote server returns a 404 72 // Change UUID so the remote server returns a 404
76 await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') 73 await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
77 74
78 await getVideo(servers[0].url, videoUUID1) 75 await servers[0].videosCommand.get({ id: videoUUID1 })
79 await getVideo(servers[0].url, videoUUID2) 76 await servers[0].videosCommand.get({ id: videoUUID2 })
80 77
81 await waitJobs(servers) 78 await waitJobs(servers)
82 79
83 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404) 80 await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
84 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200) 81 await servers[0].videosCommand.get({ id: videoUUID2 })
85 }) 82 })
86 83
87 it('Should not update a remote video if the remote instance is down', async function () { 84 it('Should not update a remote video if the remote instance is down', async function () {
@@ -94,13 +91,13 @@ describe('Test AP refresher', function () {
94 // Video will need a refresh 91 // Video will need a refresh
95 await wait(10000) 92 await wait(10000)
96 93
97 await getVideo(servers[0].url, videoUUID3) 94 await servers[0].videosCommand.get({ id: videoUUID3 })
98 // The refresh should fail 95 // The refresh should fail
99 await waitJobs([ servers[0] ]) 96 await waitJobs([ servers[0] ])
100 97
101 await reRunServer(servers[1]) 98 await reRunServer(servers[1])
102 99
103 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200) 100 await servers[0].videosCommand.get({ id: videoUUID3 })
104 }) 101 })
105 }) 102 })
106 103