1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers
12 } from '@shared/extra-utils'
13 import { VideoChannel } from '@shared/models'
15 const expect = chai.expect
17 describe('Test channels search', function () {
18 let server: PeerTubeServer
19 let remoteServer: PeerTubeServer
20 let command: SearchCommand
22 before(async function () {
25 server = await createSingleServer(1)
26 remoteServer = await createSingleServer(2, { transcoding: { enabled: false } })
28 await setAccessTokensToServers([ server, remoteServer ])
31 await server.users.create({ username: 'user1' })
33 name: 'squall_channel',
34 displayName: 'Squall channel'
36 await server.channels.create({ attributes: channel })
40 await remoteServer.users.create({ username: 'user1' })
43 displayName: 'Zell channel'
45 const { id } = await remoteServer.channels.create({ attributes: channel })
47 await remoteServer.videos.upload({ attributes: { channelId: id } })
50 await doubleFollow(server, remoteServer)
52 command = server.search
55 it('Should make a simple search and not have results', async function () {
56 const body = await command.searchChannels({ search: 'abc' })
58 expect(body.total).to.equal(0)
59 expect(body.data).to.have.lengthOf(0)
62 it('Should make a search and have results', async function () {
69 const body = await command.advancedChannelSearch({ search })
70 expect(body.total).to.equal(1)
71 expect(body.data).to.have.lengthOf(1)
73 const channel: VideoChannel = body.data[0]
74 expect(channel.name).to.equal('squall_channel')
75 expect(channel.displayName).to.equal('Squall channel')
85 const body = await command.advancedChannelSearch({ search })
86 expect(body.total).to.equal(1)
87 expect(body.data).to.have.lengthOf(0)
91 it('Should filter by host', async function () {
93 const search = { search: 'channel', host: remoteServer.host }
95 const body = await command.advancedChannelSearch({ search })
96 expect(body.total).to.equal(1)
97 expect(body.data).to.have.lengthOf(1)
98 expect(body.data[0].displayName).to.equal('Zell channel')
102 const search = { search: 'Sq', host: server.host }
104 const body = await command.advancedChannelSearch({ search })
105 expect(body.total).to.equal(1)
106 expect(body.data).to.have.lengthOf(1)
107 expect(body.data[0].displayName).to.equal('Squall channel')
111 const search = { search: 'Squall', host: 'example.com' }
113 const body = await command.advancedChannelSearch({ search })
114 expect(body.total).to.equal(0)
115 expect(body.data).to.have.lengthOf(0)
119 after(async function () {
120 await cleanupTests([ server ])