1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
7 flushAndRunMultipleServers,
11 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { VideoChannel } from '@shared/models'
19 const expect = chai.expect
21 describe('Test ActivityPub video channels search', function () {
22 let servers: ServerInfo[]
23 let userServer2Token: string
24 let videoServer2UUID: string
25 let channelIdServer2: number
26 let command: SearchCommand
28 before(async function () {
31 servers = await flushAndRunMultipleServers(2)
33 await setAccessTokensToServers(servers)
36 await servers[0].usersCommand.create({ username: 'user1_server1', password: 'password' })
38 name: 'channel1_server1',
39 displayName: 'Channel 1 server 1'
41 await servers[0].channelsCommand.create({ attributes: channel })
45 const user = { username: 'user1_server2', password: 'password' }
46 await servers[1].usersCommand.create({ username: user.username, password: user.password })
47 userServer2Token = await servers[1].loginCommand.getAccessToken(user)
50 name: 'channel1_server2',
51 displayName: 'Channel 1 server 2'
53 const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
54 channelIdServer2 = created.id
56 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
57 videoServer2UUID = res.body.video.uuid
60 await waitJobs(servers)
62 command = servers[0].searchCommand
65 it('Should not find a remote video channel', async function () {
69 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
70 const body = await command.searchChannels({ search, token: servers[0].accessToken })
72 expect(body.total).to.equal(0)
73 expect(body.data).to.be.an('array')
74 expect(body.data).to.have.lengthOf(0)
79 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
80 const body = await command.searchChannels({ search })
82 expect(body.total).to.equal(0)
83 expect(body.data).to.be.an('array')
84 expect(body.data).to.have.lengthOf(0)
88 it('Should search a local video channel', async function () {
90 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
91 'channel1_server1@localhost:' + servers[0].port
94 for (const search of searches) {
95 const body = await command.searchChannels({ search })
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')
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'
108 for (const token of [ undefined, servers[0].accessToken ]) {
109 const body = await command.searchChannels({ search, token })
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')
119 it('Should search a remote video channel with URL or handle', async function () {
121 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2',
122 'http://localhost:' + servers[1].port + '/c/channel1_server2',
123 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos',
124 'channel1_server2@localhost:' + servers[1].port
127 for (const search of searches) {
128 const body = await command.searchChannels({ search, token: servers[0].accessToken })
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')
138 it('Should not list this remote video channel', async function () {
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')
147 it('Should list video channel videos of server 2 without token', async function () {
150 await waitJobs(servers)
152 const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
153 expect(res.body.total).to.equal(0)
154 expect(res.body.data).to.have.lengthOf(0)
157 it('Should list video channel videos of server 2 with token', async function () {
158 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
160 expect(res.body.total).to.equal(1)
161 expect(res.body.data[0].name).to.equal('video 1 server 2')
164 it('Should update video channel of server 2, and refresh it on server 1', async function () {
167 await servers[1].channelsCommand.update({
168 token: userServer2Token,
169 channelName: 'channel1_server2',
170 attributes: { displayName: 'channel updated' }
172 await servers[1].usersCommand.updateMe({ token: userServer2Token, displayName: 'user updated' })
174 await waitJobs(servers)
175 // Expire video channel
178 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
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)
183 const videoChannel: VideoChannel = body.data[0]
184 expect(videoChannel.displayName).to.equal('channel updated')
186 // We don't return the owner account for now
187 // expect(videoChannel.ownerAccount.displayName).to.equal('user updated')
190 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
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 })
196 await waitJobs(servers)
198 // Expire video channel
201 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
202 await command.searchChannels({ search, token: servers[0].accessToken })
204 await waitJobs(servers)
206 const videoChannelName = 'channel1_server2@localhost:' + servers[1].port
207 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt')
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')
214 it('Should delete video channel of server 2, and delete it on server 1', async function () {
217 await servers[1].channelsCommand.delete({ token: userServer2Token, channelName: 'channel1_server2' })
219 await waitJobs(servers)
223 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
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)
229 after(async function () {
230 await cleanupTests(servers)