1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
12 setAccessTokensToServers,
18 } from '@shared/extra-utils'
19 import { VideoChannel } from '@shared/models'
21 const expect = chai.expect
23 describe('Test ActivityPub video channels search', function () {
24 let servers: ServerInfo[]
25 let userServer2Token: string
26 let videoServer2UUID: string
27 let channelIdServer2: number
28 let command: SearchCommand
30 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers)
38 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' })
40 name: 'channel1_server1',
41 displayName: 'Channel 1 server 1'
43 await servers[0].channelsCommand.create({ attributes: channel })
47 const user = { username: 'user1_server2', password: 'password' }
48 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
49 userServer2Token = await servers[1].loginCommand.getAccessToken(user)
52 name: 'channel1_server2',
53 displayName: 'Channel 1 server 2'
55 const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
56 channelIdServer2 = created.id
58 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
59 videoServer2UUID = res.body.video.uuid
62 await waitJobs(servers)
64 command = servers[0].searchCommand
67 it('Should not find a remote video channel', async function () {
71 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
72 const body = await command.searchChannels({ search, token: servers[0].accessToken })
74 expect(body.total).to.equal(0)
75 expect(body.data).to.be.an('array')
76 expect(body.data).to.have.lengthOf(0)
81 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
82 const body = await command.searchChannels({ search })
84 expect(body.total).to.equal(0)
85 expect(body.data).to.be.an('array')
86 expect(body.data).to.have.lengthOf(0)
90 it('Should search a local video channel', async function () {
92 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
93 'channel1_server1@localhost:' + servers[0].port
96 for (const search of searches) {
97 const body = await command.searchChannels({ search })
99 expect(body.total).to.equal(1)
100 expect(body.data).to.be.an('array')
101 expect(body.data).to.have.lengthOf(1)
102 expect(body.data[0].name).to.equal('channel1_server1')
103 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
107 it('Should search a local video channel with an alternative URL', async function () {
108 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
110 for (const token of [ undefined, servers[0].accessToken ]) {
111 const body = await command.searchChannels({ search, token })
113 expect(body.total).to.equal(1)
114 expect(body.data).to.be.an('array')
115 expect(body.data).to.have.lengthOf(1)
116 expect(body.data[0].name).to.equal('channel1_server1')
117 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
121 it('Should search a remote video channel with URL or handle', async function () {
123 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2',
124 'http://localhost:' + servers[1].port + '/c/channel1_server2',
125 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos',
126 'channel1_server2@localhost:' + servers[1].port
129 for (const search of searches) {
130 const body = await command.searchChannels({ search, token: servers[0].accessToken })
132 expect(body.total).to.equal(1)
133 expect(body.data).to.be.an('array')
134 expect(body.data).to.have.lengthOf(1)
135 expect(body.data[0].name).to.equal('channel1_server2')
136 expect(body.data[0].displayName).to.equal('Channel 1 server 2')
140 it('Should not list this remote video channel', async function () {
141 const body = await servers[0].channelsCommand.list()
142 expect(body.total).to.equal(3)
143 expect(body.data).to.have.lengthOf(3)
144 expect(body.data[0].name).to.equal('channel1_server1')
145 expect(body.data[1].name).to.equal('user1_server1_channel')
146 expect(body.data[2].name).to.equal('root_channel')
149 it('Should list video channel videos of server 2 without token', async function () {
152 await waitJobs(servers)
154 const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
155 expect(res.body.total).to.equal(0)
156 expect(res.body.data).to.have.lengthOf(0)
159 it('Should list video channel videos of server 2 with token', async function () {
160 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
162 expect(res.body.total).to.equal(1)
163 expect(res.body.data[0].name).to.equal('video 1 server 2')
166 it('Should update video channel of server 2, and refresh it on server 1', async function () {
169 await servers[1].channelsCommand.update({
170 token: userServer2Token,
171 channelName: 'channel1_server2',
172 attributes: { displayName: 'channel updated' }
174 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
176 await waitJobs(servers)
177 // Expire video channel
180 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
181 const body = await command.searchChannels({ search, token: servers[0].accessToken })
182 expect(body.total).to.equal(1)
183 expect(body.data).to.have.lengthOf(1)
185 const videoChannel: VideoChannel = body.data[0]
186 expect(videoChannel.displayName).to.equal('channel updated')
188 // We don't return the owner account for now
189 // expect(videoChannel.ownerAccount.displayName).to.equal('user updated')
192 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
195 await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' })
196 await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 })
198 await waitJobs(servers)
200 // Expire video channel
203 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
204 await command.searchChannels({ search, token: servers[0].accessToken })
206 await waitJobs(servers)
208 const videoChannelName = 'channel1_server2@localhost:' + servers[1].port
209 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt')
211 expect(res.body.total).to.equal(2)
212 expect(res.body.data[0].name).to.equal('video 2 server 2')
213 expect(res.body.data[1].name).to.equal('video 1 updated')
216 it('Should delete video channel of server 2, and delete it on server 1', async function () {
219 await servers[1].channelsCommand.delete({ token: userServer2Token, channelName: 'channel1_server2' })
221 await waitJobs(servers)
225 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
226 const body = await command.searchChannels({ search, token: servers[0].accessToken })
227 expect(body.total).to.equal(0)
228 expect(body.data).to.have.lengthOf(0)
231 after(async function () {
232 await cleanupTests(servers)