1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { VideoChannel } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar
14 } from '@shared/server-commands'
16 describe('Test channels search', function () {
17 let server: PeerTubeServer
18 let remoteServer: PeerTubeServer
19 let command: SearchCommand
21 before(async function () {
24 const servers = await Promise.all([
25 createSingleServer(1),
29 remoteServer = servers[1]
31 await setAccessTokensToServers([ server, remoteServer ])
32 await setDefaultChannelAvatar(server)
33 await setDefaultAccountAvatar(server)
35 await servers[1].config.disableTranscoding()
38 await server.users.create({ username: 'user1' })
40 name: 'squall_channel',
41 displayName: 'Squall channel'
43 await server.channels.create({ attributes: channel })
47 await remoteServer.users.create({ username: 'user1' })
50 displayName: 'Zell channel'
52 const { id } = await remoteServer.channels.create({ attributes: channel })
54 await remoteServer.videos.upload({ attributes: { channelId: id } })
57 await doubleFollow(server, remoteServer)
59 command = server.search
62 it('Should make a simple search and not have results', async function () {
63 const body = await command.searchChannels({ search: 'abc' })
65 expect(body.total).to.equal(0)
66 expect(body.data).to.have.lengthOf(0)
69 it('Should make a search and have results', async function () {
76 const body = await command.advancedChannelSearch({ search })
77 expect(body.total).to.equal(1)
78 expect(body.data).to.have.lengthOf(1)
80 const channel: VideoChannel = body.data[0]
81 expect(channel.name).to.equal('squall_channel')
82 expect(channel.displayName).to.equal('Squall channel')
92 const body = await command.advancedChannelSearch({ search })
93 expect(body.total).to.equal(1)
94 expect(body.data).to.have.lengthOf(0)
98 it('Should filter by host', async function () {
100 const search = { search: 'channel', host: remoteServer.host }
102 const body = await command.advancedChannelSearch({ search })
103 expect(body.total).to.equal(1)
104 expect(body.data).to.have.lengthOf(1)
105 expect(body.data[0].displayName).to.equal('Zell channel')
109 const search = { search: 'Sq', host: server.host }
111 const body = await command.advancedChannelSearch({ search })
112 expect(body.total).to.equal(1)
113 expect(body.data).to.have.lengthOf(1)
114 expect(body.data[0].displayName).to.equal('Squall channel')
118 const search = { search: 'Squall', host: 'example.com' }
120 const body = await command.advancedChannelSearch({ search })
121 expect(body.total).to.equal(0)
122 expect(body.data).to.have.lengthOf(0)
126 it('Should filter by names', async function () {
128 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel' ] } })
129 expect(body.total).to.equal(1)
130 expect(body.data).to.have.lengthOf(1)
131 expect(body.data[0].displayName).to.equal('Squall channel')
135 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel@' + server.host ] } })
136 expect(body.total).to.equal(1)
137 expect(body.data).to.have.lengthOf(1)
138 expect(body.data[0].displayName).to.equal('Squall channel')
142 const body = await command.advancedChannelSearch({ search: { handles: [ 'chocobozzz_channel' ] } })
143 expect(body.total).to.equal(0)
144 expect(body.data).to.have.lengthOf(0)
148 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel@' + remoteServer.host ] } })
149 expect(body.total).to.equal(2)
150 expect(body.data).to.have.lengthOf(2)
151 expect(body.data[0].displayName).to.equal('Squall channel')
152 expect(body.data[1].displayName).to.equal('Zell channel')
156 after(async function () {
157 await cleanupTests([ server, remoteServer ])