1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 flushAndRunMultipleServers,
12 getVideoChannelVideos,
15 setAccessTokensToServers,
23 } from '@shared/extra-utils'
24 import { VideoChannel } from '@shared/models'
26 const expect = chai.expect
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
35 before(async function () {
38 servers = await flushAndRunMultipleServers(2)
40 await setAccessTokensToServers(servers)
43 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' })
45 name: 'channel1_server1',
46 displayName: 'Channel 1 server 1'
48 await addVideoChannel(servers[0].url, servers[0].accessToken, channel)
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)
57 name: 'channel1_server2',
58 displayName: 'Channel 1 server 2'
60 const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel)
61 channelIdServer2 = resChannel.body.videoChannel.id
63 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
64 videoServer2UUID = res.body.video.uuid
67 await waitJobs(servers)
69 command = servers[0].searchCommand
72 it('Should not find a remote video channel', async function () {
76 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
77 const body = await command.searchChannels({ search, token: servers[0].accessToken })
79 expect(body.total).to.equal(0)
80 expect(body.data).to.be.an('array')
81 expect(body.data).to.have.lengthOf(0)
86 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
87 const body = await command.searchChannels({ search })
89 expect(body.total).to.equal(0)
90 expect(body.data).to.be.an('array')
91 expect(body.data).to.have.lengthOf(0)
95 it('Should search a local video channel', async function () {
97 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
98 'channel1_server1@localhost:' + servers[0].port
101 for (const search of searches) {
102 const body = await command.searchChannels({ search })
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')
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'
115 for (const token of [ undefined, servers[0].accessToken ]) {
116 const body = await command.searchChannels({ search, token })
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')
126 it('Should search a remote video channel with URL or handle', async function () {
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
134 for (const search of searches) {
135 const body = await command.searchChannels({ search, token: servers[0].accessToken })
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')
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')
154 it('Should list video channel videos of server 2 without token', async function () {
157 await waitJobs(servers)
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)
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)
167 expect(res.body.total).to.equal(1)
168 expect(res.body.data[0].name).to.equal('video 1 server 2')
171 it('Should update video channel of server 2, and refresh it on server 1', async function () {
174 await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' })
175 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
177 await waitJobs(servers)
178 // Expire video channel
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)
186 const videoChannel: VideoChannel = body.data[0]
187 expect(videoChannel.displayName).to.equal('channel updated')
189 // We don't return the owner account for now
190 // expect(videoChannel.ownerAccount.displayName).to.equal('user updated')
193 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
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 })
199 await waitJobs(servers)
201 // Expire video channel
204 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
205 await command.searchChannels({ search, token: servers[0].accessToken })
207 await waitJobs(servers)
209 const videoChannelName = 'channel1_server2@localhost:' + servers[1].port
210 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt')
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')
217 it('Should delete video channel of server 2, and delete it on server 1', async function () {
220 await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2')
222 await waitJobs(servers)
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)
232 after(async function () {
233 await cleanupTests(servers)