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