]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-activitypub-video-channels.ts
Introduce abuse command
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-activitypub-video-channels.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 addVideoChannel,
7 cleanupTests,
8 createUser,
9 deleteVideoChannel,
10 flushAndRunMultipleServers,
11 getVideoChannelsList,
12 getVideoChannelVideos,
13 ServerInfo,
14 setAccessTokensToServers,
15 updateMyUser,
16 updateVideo,
17 updateVideoChannel,
18 uploadVideo,
19 userLogin,
20 wait
21 } from '../../../../shared/extra-utils'
22 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23 import { VideoChannel } from '../../../../shared/models/videos'
24 import { searchVideoChannel } from '../../../../shared/extra-utils/search/video-channels'
25
26 const expect = chai.expect
27
28 describe('Test ActivityPub video channels search', function () {
29 let servers: ServerInfo[]
30 let userServer2Token: string
31 let videoServer2UUID: string
32 let channelIdServer2: number
33
34 before(async function () {
35 this.timeout(120000)
36
37 servers = await flushAndRunMultipleServers(2)
38
39 await setAccessTokensToServers(servers)
40
41 {
42 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' })
43 const channel = {
44 name: 'channel1_server1',
45 displayName: 'Channel 1 server 1'
46 }
47 await addVideoChannel(servers[0].url, servers[0].accessToken, channel)
48 }
49
50 {
51 const user = { username: 'user1_server2', password: 'password' }
52 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
53 userServer2Token = await userLogin(servers[1], user)
54
55 const channel = {
56 name: 'channel1_server2',
57 displayName: 'Channel 1 server 2'
58 }
59 const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel)
60 channelIdServer2 = resChannel.body.videoChannel.id
61
62 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
63 videoServer2UUID = res.body.video.uuid
64 }
65
66 await waitJobs(servers)
67 })
68
69 it('Should not find a remote video channel', async function () {
70 this.timeout(15000)
71
72 {
73 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
74 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
75
76 expect(res.body.total).to.equal(0)
77 expect(res.body.data).to.be.an('array')
78 expect(res.body.data).to.have.lengthOf(0)
79 }
80
81 {
82 // Without token
83 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
84 const res = await searchVideoChannel(servers[0].url, search)
85
86 expect(res.body.total).to.equal(0)
87 expect(res.body.data).to.be.an('array')
88 expect(res.body.data).to.have.lengthOf(0)
89 }
90 })
91
92 it('Should search a local video channel', async function () {
93 const searches = [
94 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
95 'channel1_server1@localhost:' + servers[0].port
96 ]
97
98 for (const search of searches) {
99 const res = await searchVideoChannel(servers[0].url, search)
100
101 expect(res.body.total).to.equal(1)
102 expect(res.body.data).to.be.an('array')
103 expect(res.body.data).to.have.lengthOf(1)
104 expect(res.body.data[0].name).to.equal('channel1_server1')
105 expect(res.body.data[0].displayName).to.equal('Channel 1 server 1')
106 }
107 })
108
109 it('Should search a local video channel with an alternative URL', async function () {
110 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
111
112 for (const token of [ undefined, servers[0].accessToken ]) {
113 const res = await searchVideoChannel(servers[0].url, search, token)
114
115 expect(res.body.total).to.equal(1)
116 expect(res.body.data).to.be.an('array')
117 expect(res.body.data).to.have.lengthOf(1)
118 expect(res.body.data[0].name).to.equal('channel1_server1')
119 expect(res.body.data[0].displayName).to.equal('Channel 1 server 1')
120 }
121 })
122
123 it('Should search a remote video channel with URL or handle', async function () {
124 const searches = [
125 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2',
126 'http://localhost:' + servers[1].port + '/c/channel1_server2',
127 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos',
128 'channel1_server2@localhost:' + servers[1].port
129 ]
130
131 for (const search of searches) {
132 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
133
134 expect(res.body.total).to.equal(1)
135 expect(res.body.data).to.be.an('array')
136 expect(res.body.data).to.have.lengthOf(1)
137 expect(res.body.data[0].name).to.equal('channel1_server2')
138 expect(res.body.data[0].displayName).to.equal('Channel 1 server 2')
139 }
140 })
141
142 it('Should not list this remote video channel', async function () {
143 const res = await getVideoChannelsList(servers[0].url, 0, 5)
144 expect(res.body.total).to.equal(3)
145 expect(res.body.data).to.have.lengthOf(3)
146 expect(res.body.data[0].name).to.equal('channel1_server1')
147 expect(res.body.data[1].name).to.equal('user1_server1_channel')
148 expect(res.body.data[2].name).to.equal('root_channel')
149 })
150
151 it('Should list video channel videos of server 2 without token', async function () {
152 this.timeout(30000)
153
154 await waitJobs(servers)
155
156 const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
157 expect(res.body.total).to.equal(0)
158 expect(res.body.data).to.have.lengthOf(0)
159 })
160
161 it('Should list video channel videos of server 2 with token', async function () {
162 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
163
164 expect(res.body.total).to.equal(1)
165 expect(res.body.data[0].name).to.equal('video 1 server 2')
166 })
167
168 it('Should update video channel of server 2, and refresh it on server 1', async function () {
169 this.timeout(60000)
170
171 await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' })
172 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
173
174 await waitJobs(servers)
175 // Expire video channel
176 await wait(10000)
177
178 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
179 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
180 expect(res.body.total).to.equal(1)
181 expect(res.body.data).to.have.lengthOf(1)
182
183 const videoChannel: VideoChannel = res.body.data[0]
184 expect(videoChannel.displayName).to.equal('channel updated')
185
186 // We don't return the owner account for now
187 // expect(videoChannel.ownerAccount.displayName).to.equal('user updated')
188 })
189
190 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
191 this.timeout(60000)
192
193 await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' })
194 await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 })
195
196 await waitJobs(servers)
197
198 // Expire video channel
199 await wait(10000)
200
201 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
202 await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
203
204 await waitJobs(servers)
205
206 const videoChannelName = 'channel1_server2@localhost:' + servers[1].port
207 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt')
208
209 expect(res.body.total).to.equal(2)
210 expect(res.body.data[0].name).to.equal('video 2 server 2')
211 expect(res.body.data[1].name).to.equal('video 1 updated')
212 })
213
214 it('Should delete video channel of server 2, and delete it on server 1', async function () {
215 this.timeout(60000)
216
217 await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2')
218
219 await waitJobs(servers)
220 // Expire video
221 await wait(10000)
222
223 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
224 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
225 expect(res.body.total).to.equal(0)
226 expect(res.body.data).to.have.lengthOf(0)
227 })
228
229 after(async function () {
230 await cleanupTests(servers)
231 })
232 })