1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { VideoChannel } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar
14 } from '@shared/server-commands'
16 const expect = chai.expect
18 describe('Test channels search', function () {
19 let server: PeerTubeServer
20 let remoteServer: PeerTubeServer
21 let command: SearchCommand
23 before(async function () {
26 const servers = await Promise.all([
27 createSingleServer(1),
31 remoteServer = servers[1]
33 await setAccessTokensToServers([ server, remoteServer ])
34 await setDefaultChannelAvatar(server)
35 await setDefaultAccountAvatar(server)
37 await servers[1].config.disableTranscoding()
40 await server.users.create({ username: 'user1' })
42 name: 'squall_channel',
43 displayName: 'Squall channel'
45 await server.channels.create({ attributes: channel })
49 await remoteServer.users.create({ username: 'user1' })
52 displayName: 'Zell channel'
54 const { id } = await remoteServer.channels.create({ attributes: channel })
56 await remoteServer.videos.upload({ attributes: { channelId: id } })
59 await doubleFollow(server, remoteServer)
61 command = server.search
64 it('Should make a simple search and not have results', async function () {
65 const body = await command.searchChannels({ search: 'abc' })
67 expect(body.total).to.equal(0)
68 expect(body.data).to.have.lengthOf(0)
71 it('Should make a search and have results', async function () {
78 const body = await command.advancedChannelSearch({ search })
79 expect(body.total).to.equal(1)
80 expect(body.data).to.have.lengthOf(1)
82 const channel: VideoChannel = body.data[0]
83 expect(channel.name).to.equal('squall_channel')
84 expect(channel.displayName).to.equal('Squall channel')
94 const body = await command.advancedChannelSearch({ search })
95 expect(body.total).to.equal(1)
96 expect(body.data).to.have.lengthOf(0)
100 it('Should filter by host', async function () {
102 const search = { search: 'channel', host: remoteServer.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('Zell channel')
111 const search = { search: 'Sq', host: server.host }
113 const body = await command.advancedChannelSearch({ search })
114 expect(body.total).to.equal(1)
115 expect(body.data).to.have.lengthOf(1)
116 expect(body.data[0].displayName).to.equal('Squall channel')
120 const search = { search: 'Squall', host: 'example.com' }
122 const body = await command.advancedChannelSearch({ search })
123 expect(body.total).to.equal(0)
124 expect(body.data).to.have.lengthOf(0)
128 it('Should filter by names', async function () {
130 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel' ] } })
131 expect(body.total).to.equal(1)
132 expect(body.data).to.have.lengthOf(1)
133 expect(body.data[0].displayName).to.equal('Squall channel')
137 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel@' + server.host ] } })
138 expect(body.total).to.equal(1)
139 expect(body.data).to.have.lengthOf(1)
140 expect(body.data[0].displayName).to.equal('Squall channel')
144 const body = await command.advancedChannelSearch({ search: { handles: [ 'chocobozzz_channel' ] } })
145 expect(body.total).to.equal(0)
146 expect(body.data).to.have.lengthOf(0)
150 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel@' + remoteServer.host ] } })
151 expect(body.total).to.equal(2)
152 expect(body.data).to.have.lengthOf(2)
153 expect(body.data[0].displayName).to.equal('Squall channel')
154 expect(body.data[1].displayName).to.equal('Zell channel')
158 after(async function () {
159 await cleanupTests([ server, remoteServer ])