1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoChannel } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 setDefaultChannelAvatar
15 } from '@shared/server-commands'
17 const expect = chai.expect
19 describe('Test channels search', function () {
20 let server: PeerTubeServer
21 let remoteServer: PeerTubeServer
22 let command: SearchCommand
24 before(async function () {
27 const servers = await Promise.all([
28 createSingleServer(1),
29 createSingleServer(2, { transcoding: { enabled: false } })
32 remoteServer = servers[1]
34 await setAccessTokensToServers([ server, remoteServer ])
35 await setDefaultChannelAvatar(server)
36 await setDefaultAccountAvatar(server)
39 await server.users.create({ username: 'user1' })
41 name: 'squall_channel',
42 displayName: 'Squall channel'
44 await server.channels.create({ attributes: channel })
48 await remoteServer.users.create({ username: 'user1' })
51 displayName: 'Zell channel'
53 const { id } = await remoteServer.channels.create({ attributes: channel })
55 await remoteServer.videos.upload({ attributes: { channelId: id } })
58 await doubleFollow(server, remoteServer)
60 command = server.search
63 it('Should make a simple search and not have results', async function () {
64 const body = await command.searchChannels({ search: 'abc' })
66 expect(body.total).to.equal(0)
67 expect(body.data).to.have.lengthOf(0)
70 it('Should make a search and have results', async function () {
77 const body = await command.advancedChannelSearch({ search })
78 expect(body.total).to.equal(1)
79 expect(body.data).to.have.lengthOf(1)
81 const channel: VideoChannel = body.data[0]
82 expect(channel.name).to.equal('squall_channel')
83 expect(channel.displayName).to.equal('Squall channel')
93 const body = await command.advancedChannelSearch({ search })
94 expect(body.total).to.equal(1)
95 expect(body.data).to.have.lengthOf(0)
99 it('Should filter by host', async function () {
101 const search = { search: 'channel', host: remoteServer.host }
103 const body = await command.advancedChannelSearch({ search })
104 expect(body.total).to.equal(1)
105 expect(body.data).to.have.lengthOf(1)
106 expect(body.data[0].displayName).to.equal('Zell channel')
110 const search = { search: 'Sq', host: server.host }
112 const body = await command.advancedChannelSearch({ search })
113 expect(body.total).to.equal(1)
114 expect(body.data).to.have.lengthOf(1)
115 expect(body.data[0].displayName).to.equal('Squall channel')
119 const search = { search: 'Squall', host: 'example.com' }
121 const body = await command.advancedChannelSearch({ search })
122 expect(body.total).to.equal(0)
123 expect(body.data).to.have.lengthOf(0)
127 it('Should filter by names', async function () {
129 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel' ] } })
130 expect(body.total).to.equal(1)
131 expect(body.data).to.have.lengthOf(1)
132 expect(body.data[0].displayName).to.equal('Squall channel')
136 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel@' + server.host ] } })
137 expect(body.total).to.equal(1)
138 expect(body.data).to.have.lengthOf(1)
139 expect(body.data[0].displayName).to.equal('Squall channel')
143 const body = await command.advancedChannelSearch({ search: { handles: [ 'chocobozzz_channel' ] } })
144 expect(body.total).to.equal(0)
145 expect(body.data).to.have.lengthOf(0)
149 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel@' + remoteServer.host ] } })
150 expect(body.total).to.equal(2)
151 expect(body.data).to.have.lengthOf(2)
152 expect(body.data[0].displayName).to.equal('Squall channel')
153 expect(body.data[1].displayName).to.equal('Zell channel')
157 after(async function () {
158 await cleanupTests([ server, remoteServer ])