1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
12 setAccessTokensToServers,
19 } from '@shared/extra-utils'
20 import { VideoChannel } from '@shared/models'
22 const expect = chai.expect
24 describe('Test ActivityPub video channels search', function () {
25 let servers: ServerInfo[]
26 let userServer2Token: string
27 let videoServer2UUID: string
28 let channelIdServer2: number
29 let command: SearchCommand
31 before(async function () {
34 servers = await flushAndRunMultipleServers(2)
36 await setAccessTokensToServers(servers)
39 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' })
41 name: 'channel1_server1',
42 displayName: 'Channel 1 server 1'
44 await servers[0].channelsCommand.create({ attributes: channel })
48 const user = { username: 'user1_server2', password: 'password' }
49 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
50 userServer2Token = await userLogin(servers[1], user)
53 name: 'channel1_server2',
54 displayName: 'Channel 1 server 2'
56 const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
57 channelIdServer2 = created.id
59 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
60 videoServer2UUID = res.body.video.uuid
63 await waitJobs(servers)
65 command = servers[0].searchCommand
68 it('Should not find a remote video channel', async function () {
72 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
73 const body = await command.searchChannels({ search, token: servers[0].accessToken })
75 expect(body.total).to.equal(0)
76 expect(body.data).to.be.an('array')
77 expect(body.data).to.have.lengthOf(0)
82 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
83 const body = await command.searchChannels({ search })
85 expect(body.total).to.equal(0)
86 expect(body.data).to.be.an('array')
87 expect(body.data).to.have.lengthOf(0)
91 it('Should search a local video channel', async function () {
93 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
94 'channel1_server1@localhost:' + servers[0].port
97 for (const search of searches) {
98 const body = await command.searchChannels({ search })
100 expect(body.total).to.equal(1)
101 expect(body.data).to.be.an('array')
102 expect(body.data).to.have.lengthOf(1)
103 expect(body.data[0].name).to.equal('channel1_server1')
104 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
108 it('Should search a local video channel with an alternative URL', async function () {
109 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
111 for (const token of [ undefined, servers[0].accessToken ]) {
112 const body = await command.searchChannels({ search, token })
114 expect(body.total).to.equal(1)
115 expect(body.data).to.be.an('array')
116 expect(body.data).to.have.lengthOf(1)
117 expect(body.data[0].name).to.equal('channel1_server1')
118 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
122 it('Should search a remote video channel with URL or handle', async function () {
124 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2',
125 'http://localhost:' + servers[1].port + '/c/channel1_server2',
126 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos',
127 'channel1_server2@localhost:' + servers[1].port
130 for (const search of searches) {
131 const body = await command.searchChannels({ search, token: servers[0].accessToken })
133 expect(body.total).to.equal(1)
134 expect(body.data).to.be.an('array')
135 expect(body.data).to.have.lengthOf(1)
136 expect(body.data[0].name).to.equal('channel1_server2')
137 expect(body.data[0].displayName).to.equal('Channel 1 server 2')
141 it('Should not list this remote video channel', async function () {
142 const body = await servers[0].channelsCommand.list()
143 expect(body.total).to.equal(3)
144 expect(body.data).to.have.lengthOf(3)
145 expect(body.data[0].name).to.equal('channel1_server1')
146 expect(body.data[1].name).to.equal('user1_server1_channel')
147 expect(body.data[2].name).to.equal('root_channel')
150 it('Should list video channel videos of server 2 without token', async function () {
153 await waitJobs(servers)
155 const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
156 expect(res.body.total).to.equal(0)
157 expect(res.body.data).to.have.lengthOf(0)
160 it('Should list video channel videos of server 2 with token', async function () {
161 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5)
163 expect(res.body.total).to.equal(1)
164 expect(res.body.data[0].name).to.equal('video 1 server 2')
167 it('Should update video channel of server 2, and refresh it on server 1', async function () {
170 await servers[1].channelsCommand.update({
171 token: userServer2Token,
172 channelName: 'channel1_server2',
173 attributes: { 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 servers[1].channelsCommand.delete({ token: userServer2Token, channelName: '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)