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),
32 remoteServer = servers[1]
34 await setAccessTokensToServers([ server, remoteServer ])
35 await setDefaultChannelAvatar(server)
36 await setDefaultAccountAvatar(server)
38 await servers[1].config.disableTranscoding()
41 await server.users.create({ username: 'user1' })
43 name: 'squall_channel',
44 displayName: 'Squall channel'
46 await server.channels.create({ attributes: channel })
50 await remoteServer.users.create({ username: 'user1' })
53 displayName: 'Zell channel'
55 const { id } = await remoteServer.channels.create({ attributes: channel })
57 await remoteServer.videos.upload({ attributes: { channelId: id } })
60 await doubleFollow(server, remoteServer)
62 command = server.search
65 it('Should make a simple search and not have results', async function () {
66 const body = await command.searchChannels({ search: 'abc' })
68 expect(body.total).to.equal(0)
69 expect(body.data).to.have.lengthOf(0)
72 it('Should make a search and have results', async function () {
79 const body = await command.advancedChannelSearch({ search })
80 expect(body.total).to.equal(1)
81 expect(body.data).to.have.lengthOf(1)
83 const channel: VideoChannel = body.data[0]
84 expect(channel.name).to.equal('squall_channel')
85 expect(channel.displayName).to.equal('Squall channel')
95 const body = await command.advancedChannelSearch({ search })
96 expect(body.total).to.equal(1)
97 expect(body.data).to.have.lengthOf(0)
101 it('Should filter by host', async function () {
103 const search = { search: 'channel', host: remoteServer.host }
105 const body = await command.advancedChannelSearch({ search })
106 expect(body.total).to.equal(1)
107 expect(body.data).to.have.lengthOf(1)
108 expect(body.data[0].displayName).to.equal('Zell channel')
112 const search = { search: 'Sq', host: server.host }
114 const body = await command.advancedChannelSearch({ search })
115 expect(body.total).to.equal(1)
116 expect(body.data).to.have.lengthOf(1)
117 expect(body.data[0].displayName).to.equal('Squall channel')
121 const search = { search: 'Squall', host: 'example.com' }
123 const body = await command.advancedChannelSearch({ search })
124 expect(body.total).to.equal(0)
125 expect(body.data).to.have.lengthOf(0)
129 it('Should filter by names', async function () {
131 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel' ] } })
132 expect(body.total).to.equal(1)
133 expect(body.data).to.have.lengthOf(1)
134 expect(body.data[0].displayName).to.equal('Squall channel')
138 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel@' + server.host ] } })
139 expect(body.total).to.equal(1)
140 expect(body.data).to.have.lengthOf(1)
141 expect(body.data[0].displayName).to.equal('Squall channel')
145 const body = await command.advancedChannelSearch({ search: { handles: [ 'chocobozzz_channel' ] } })
146 expect(body.total).to.equal(0)
147 expect(body.data).to.have.lengthOf(0)
151 const body = await command.advancedChannelSearch({ search: { handles: [ 'squall_channel', 'zell_channel@' + remoteServer.host ] } })
152 expect(body.total).to.equal(2)
153 expect(body.data).to.have.lengthOf(2)
154 expect(body.data[0].displayName).to.equal('Squall channel')
155 expect(body.data[1].displayName).to.equal('Zell channel')
159 after(async function () {
160 await cleanupTests([ server, remoteServer ])