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 const servers = await Promise.all([
26 createSingleServer(1),
27 createSingleServer(2, { transcoding: { enabled: false } })
30 remoteServer = servers[1]
32 await setAccessTokensToServers([ server, remoteServer ])
35 await server.users.create({ username: 'user1' })
37 name: 'squall_channel',
38 displayName: 'Squall channel'
40 await server.channels.create({ attributes: channel })
44 await remoteServer.users.create({ username: 'user1' })
47 displayName: 'Zell channel'
49 const { id } = await remoteServer.channels.create({ attributes: channel })
51 await remoteServer.videos.upload({ attributes: { channelId: id } })
54 await doubleFollow(server, remoteServer)
56 command = server.search
59 it('Should make a simple search and not have results', async function () {
60 const body = await command.searchChannels({ search: 'abc' })
62 expect(body.total).to.equal(0)
63 expect(body.data).to.have.lengthOf(0)
66 it('Should make a search and have results', async function () {
73 const body = await command.advancedChannelSearch({ search })
74 expect(body.total).to.equal(1)
75 expect(body.data).to.have.lengthOf(1)
77 const channel: VideoChannel = body.data[0]
78 expect(channel.name).to.equal('squall_channel')
79 expect(channel.displayName).to.equal('Squall channel')
89 const body = await command.advancedChannelSearch({ search })
90 expect(body.total).to.equal(1)
91 expect(body.data).to.have.lengthOf(0)
95 it('Should filter by host', async function () {
97 const search = { search: 'channel', host: remoteServer.host }
99 const body = await command.advancedChannelSearch({ search })
100 expect(body.total).to.equal(1)
101 expect(body.data).to.have.lengthOf(1)
102 expect(body.data[0].displayName).to.equal('Zell channel')
106 const search = { search: 'Sq', host: server.host }
108 const body = await command.advancedChannelSearch({ search })
109 expect(body.total).to.equal(1)
110 expect(body.data).to.have.lengthOf(1)
111 expect(body.data[0].displayName).to.equal('Squall channel')
115 const search = { search: 'Squall', host: 'example.com' }
117 const body = await command.advancedChannelSearch({ search })
118 expect(body.total).to.equal(0)
119 expect(body.data).to.have.lengthOf(0)
123 it('Should filter by names', async function () {
125 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel' ] } })
126 expect(body.total).to.equal(1)
127 expect(body.data).to.have.lengthOf(1)
128 expect(body.data[0].displayName).to.equal('Squall channel')
132 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel@' + server.host ] } })
133 expect(body.total).to.equal(1)
134 expect(body.data).to.have.lengthOf(1)
135 expect(body.data[0].displayName).to.equal('Squall channel')
139 const body = await command.advancedChannelSearch({ search: { handles: [ 'chocobozzz_channel' ] } })
140 expect(body.total).to.equal(0)
141 expect(body.data).to.have.lengthOf(0)
145 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel@' + remoteServer.host ] } })
146 expect(body.total).to.equal(2)
147 expect(body.data).to.have.lengthOf(2)
148 expect(body.data[0].displayName).to.equal('Squall channel')
149 expect(body.data[1].displayName).to.equal('Zell channel')
153 after(async function () {
154 await cleanupTests([ server, remoteServer ])