]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-activitypub-video-channels.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-activitypub-video-channels.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
f5b0af50 2
f5b0af50 3import 'mocha'
af971e06 4import * as chai from 'chai'
f5b0af50 5import {
7243f84d 6 cleanupTests,
254d3579 7 createMultipleServers,
254d3579 8 PeerTubeServer,
4c7e60bc 9 SearchCommand,
f5b0af50 10 setAccessTokensToServers,
af971e06
C
11 wait,
12 waitJobs
13} from '@shared/extra-utils'
14import { VideoChannel } from '@shared/models'
f5b0af50
C
15
16const expect = chai.expect
17
da3a3ab6 18describe('Test ActivityPub video channels search', function () {
254d3579 19 let servers: PeerTubeServer[]
f5b0af50 20 let userServer2Token: string
687d638c
C
21 let videoServer2UUID: string
22 let channelIdServer2: number
af971e06 23 let command: SearchCommand
f5b0af50
C
24
25 before(async function () {
26 this.timeout(120000)
27
254d3579 28 servers = await createMultipleServers(2)
f5b0af50
C
29
30 await setAccessTokensToServers(servers)
31
32 {
89d241a7 33 await servers[0].users.create({ username: 'user1_server1', password: 'password' })
f5b0af50
C
34 const channel = {
35 name: 'channel1_server1',
36 displayName: 'Channel 1 server 1'
37 }
89d241a7 38 await servers[0].channels.create({ attributes: channel })
f5b0af50
C
39 }
40
41 {
42 const user = { username: 'user1_server2', password: 'password' }
89d241a7
C
43 await servers[1].users.create({ username: user.username, password: user.password })
44 userServer2Token = await servers[1].login.getAccessToken(user)
f5b0af50
C
45
46 const channel = {
47 name: 'channel1_server2',
48 displayName: 'Channel 1 server 2'
49 }
89d241a7 50 const created = await servers[1].channels.create({ token: userServer2Token, attributes: channel })
a5461888 51 channelIdServer2 = created.id
f5b0af50 52
d23dd9fb 53 const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 }
89d241a7 54 const { uuid } = await servers[1].videos.upload({ token: userServer2Token, attributes })
d23dd9fb 55 videoServer2UUID = uuid
f5b0af50
C
56 }
57
58 await waitJobs(servers)
af971e06 59
89d241a7 60 command = servers[0].search
f5b0af50
C
61 })
62
63 it('Should not find a remote video channel', async function () {
8d2be0ed
C
64 this.timeout(15000)
65
f5b0af50 66 {
a1587156 67 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
af971e06 68 const body = await command.searchChannels({ search, token: servers[0].accessToken })
f5b0af50 69
af971e06
C
70 expect(body.total).to.equal(0)
71 expect(body.data).to.be.an('array')
72 expect(body.data).to.have.lengthOf(0)
f5b0af50
C
73 }
74
75 {
76 // Without token
a1587156 77 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
af971e06 78 const body = await command.searchChannels({ search })
f5b0af50 79
af971e06
C
80 expect(body.total).to.equal(0)
81 expect(body.data).to.be.an('array')
82 expect(body.data).to.have.lengthOf(0)
f5b0af50
C
83 }
84 })
85
86 it('Should search a local video channel', async function () {
87 const searches = [
a1587156
C
88 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
89 'channel1_server1@localhost:' + servers[0].port
f5b0af50
C
90 ]
91
92 for (const search of searches) {
af971e06 93 const body = await command.searchChannels({ search })
f5b0af50 94
af971e06
C
95 expect(body.total).to.equal(1)
96 expect(body.data).to.be.an('array')
97 expect(body.data).to.have.lengthOf(1)
98 expect(body.data[0].name).to.equal('channel1_server1')
99 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
f5b0af50
C
100 }
101 })
102
37a44fc9
C
103 it('Should search a local video channel with an alternative URL', async function () {
104 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
105
106 for (const token of [ undefined, servers[0].accessToken ]) {
af971e06 107 const body = await command.searchChannels({ search, token })
37a44fc9 108
af971e06
C
109 expect(body.total).to.equal(1)
110 expect(body.data).to.be.an('array')
111 expect(body.data).to.have.lengthOf(1)
112 expect(body.data[0].name).to.equal('channel1_server1')
113 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
37a44fc9
C
114 }
115 })
116
f5b0af50
C
117 it('Should search a remote video channel with URL or handle', async function () {
118 const searches = [
a1587156 119 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2',
37a44fc9
C
120 'http://localhost:' + servers[1].port + '/c/channel1_server2',
121 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos',
a1587156 122 'channel1_server2@localhost:' + servers[1].port
f5b0af50
C
123 ]
124
125 for (const search of searches) {
af971e06 126 const body = await command.searchChannels({ search, token: servers[0].accessToken })
f5b0af50 127
af971e06
C
128 expect(body.total).to.equal(1)
129 expect(body.data).to.be.an('array')
130 expect(body.data).to.have.lengthOf(1)
131 expect(body.data[0].name).to.equal('channel1_server2')
132 expect(body.data[0].displayName).to.equal('Channel 1 server 2')
f5b0af50
C
133 }
134 })
135
136 it('Should not list this remote video channel', async function () {
89d241a7 137 const body = await servers[0].channels.list()
a5461888
C
138 expect(body.total).to.equal(3)
139 expect(body.data).to.have.lengthOf(3)
140 expect(body.data[0].name).to.equal('channel1_server1')
141 expect(body.data[1].name).to.equal('user1_server1_channel')
142 expect(body.data[2].name).to.equal('root_channel')
f5b0af50
C
143 })
144
687d638c
C
145 it('Should list video channel videos of server 2 without token', async function () {
146 this.timeout(30000)
147
148 await waitJobs(servers)
149
89d241a7 150 const { total, data } = await servers[0].videos.listByChannel({
d23dd9fb 151 token: null,
c0e8b12e 152 handle: 'channel1_server2@localhost:' + servers[1].port
d23dd9fb
C
153 })
154 expect(total).to.equal(0)
155 expect(data).to.have.lengthOf(0)
687d638c
C
156 })
157
158 it('Should list video channel videos of server 2 with token', async function () {
89d241a7 159 const { total, data } = await servers[0].videos.listByChannel({
c0e8b12e 160 handle: 'channel1_server2@localhost:' + servers[1].port
d23dd9fb 161 })
687d638c 162
d23dd9fb
C
163 expect(total).to.equal(1)
164 expect(data[0].name).to.equal('video 1 server 2')
687d638c
C
165 })
166
f5b0af50
C
167 it('Should update video channel of server 2, and refresh it on server 1', async function () {
168 this.timeout(60000)
169
89d241a7 170 await servers[1].channels.update({
a5461888
C
171 token: userServer2Token,
172 channelName: 'channel1_server2',
173 attributes: { displayName: 'channel updated' }
174 })
89d241a7 175 await servers[1].users.updateMe({ token: userServer2Token, displayName: 'user updated' })
f5b0af50
C
176
177 await waitJobs(servers)
178 // Expire video channel
179 await wait(10000)
180
a1587156 181 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
af971e06
C
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)
f5b0af50 185
af971e06 186 const videoChannel: VideoChannel = body.data[0]
f5b0af50
C
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
687d638c
C
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
89d241a7
C
196 await servers[1].videos.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } })
197 await servers[1].videos.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } })
687d638c
C
198
199 await waitJobs(servers)
200
201 // Expire video channel
202 await wait(10000)
203
a1587156 204 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
af971e06 205 await command.searchChannels({ search, token: servers[0].accessToken })
687d638c
C
206
207 await waitJobs(servers)
208
c0e8b12e
C
209 const handle = 'channel1_server2@localhost:' + servers[1].port
210 const { total, data } = await servers[0].videos.listByChannel({ handle, sort: '-createdAt' })
687d638c 211
d23dd9fb
C
212 expect(total).to.equal(2)
213 expect(data[0].name).to.equal('video 2 server 2')
214 expect(data[1].name).to.equal('video 1 updated')
687d638c
C
215 })
216
f5b0af50
C
217 it('Should delete video channel of server 2, and delete it on server 1', async function () {
218 this.timeout(60000)
219
89d241a7 220 await servers[1].channels.delete({ token: userServer2Token, channelName: 'channel1_server2' })
f5b0af50
C
221
222 await waitJobs(servers)
223 // Expire video
224 await wait(10000)
225
a1587156 226 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
af971e06
C
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)
f5b0af50
C
230 })
231
7c3b7976
C
232 after(async function () {
233 await cleanupTests(servers)
f5b0af50
C
234 })
235})