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