1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
7 flushAndRunMultipleServers,
10 setAccessTokensToServers,
13 } from '@shared/extra-utils'
14 import { VideoChannel } from '@shared/models'
16 const expect = chai.expect
18 describe('Test ActivityPub video channels search', function () {
19 let servers: ServerInfo[]
20 let userServer2Token: string
21 let videoServer2UUID: string
22 let channelIdServer2: number
23 let command: SearchCommand
25 before(async function () {
28 servers = await flushAndRunMultipleServers(2)
30 await setAccessTokensToServers(servers)
33 await servers[0].usersCommand.create({ username: 'user1_server1', password: 'password' })
35 name: 'channel1_server1',
36 displayName: 'Channel 1 server 1'
38 await servers[0].channelsCommand.create({ attributes: channel })
42 const user = { username: 'user1_server2', password: 'password' }
43 await servers[1].usersCommand.create({ username: user.username, password: user.password })
44 userServer2Token = await servers[1].loginCommand.getAccessToken(user)
47 name: 'channel1_server2',
48 displayName: 'Channel 1 server 2'
50 const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
51 channelIdServer2 = created.id
53 const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 }
54 const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes })
55 videoServer2UUID = uuid
58 await waitJobs(servers)
60 command = servers[0].searchCommand
63 it('Should not find a remote video channel', async function () {
67 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
68 const body = await command.searchChannels({ search, token: servers[0].accessToken })
70 expect(body.total).to.equal(0)
71 expect(body.data).to.be.an('array')
72 expect(body.data).to.have.lengthOf(0)
77 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
78 const body = await command.searchChannels({ search })
80 expect(body.total).to.equal(0)
81 expect(body.data).to.be.an('array')
82 expect(body.data).to.have.lengthOf(0)
86 it('Should search a local video channel', async function () {
88 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
89 'channel1_server1@localhost:' + servers[0].port
92 for (const search of searches) {
93 const body = await command.searchChannels({ search })
95 expect(body.total).to.equal(1)
96 expect(body.data).to.be.an('array')
97 expect(body.data).to.have.lengthOf(1)
98 expect(body.data[0].name).to.equal('channel1_server1')
99 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
103 it('Should search a local video channel with an alternative URL', async function () {
104 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
106 for (const token of [ undefined, servers[0].accessToken ]) {
107 const body = await command.searchChannels({ search, token })
109 expect(body.total).to.equal(1)
110 expect(body.data).to.be.an('array')
111 expect(body.data).to.have.lengthOf(1)
112 expect(body.data[0].name).to.equal('channel1_server1')
113 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
117 it('Should search a remote video channel with URL or handle', async function () {
119 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2',
120 'http://localhost:' + servers[1].port + '/c/channel1_server2',
121 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos',
122 'channel1_server2@localhost:' + servers[1].port
125 for (const search of searches) {
126 const body = await command.searchChannels({ search, token: servers[0].accessToken })
128 expect(body.total).to.equal(1)
129 expect(body.data).to.be.an('array')
130 expect(body.data).to.have.lengthOf(1)
131 expect(body.data[0].name).to.equal('channel1_server2')
132 expect(body.data[0].displayName).to.equal('Channel 1 server 2')
136 it('Should not list this remote video channel', async function () {
137 const body = await servers[0].channelsCommand.list()
138 expect(body.total).to.equal(3)
139 expect(body.data).to.have.lengthOf(3)
140 expect(body.data[0].name).to.equal('channel1_server1')
141 expect(body.data[1].name).to.equal('user1_server1_channel')
142 expect(body.data[2].name).to.equal('root_channel')
145 it('Should list video channel videos of server 2 without token', async function () {
148 await waitJobs(servers)
150 const { total, data } = await servers[0].videosCommand.listByChannel({
152 videoChannelName: 'channel1_server2@localhost:' + servers[1].port
154 expect(total).to.equal(0)
155 expect(data).to.have.lengthOf(0)
158 it('Should list video channel videos of server 2 with token', async function () {
159 const { total, data } = await servers[0].videosCommand.listByChannel({
160 videoChannelName: 'channel1_server2@localhost:' + servers[1].port
163 expect(total).to.equal(1)
164 expect(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 servers[1].usersCommand.updateMe({ token: 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 servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } })
197 await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { 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 { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' })
212 expect(total).to.equal(2)
213 expect(data[0].name).to.equal('video 2 server 2')
214 expect(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)