]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-channels.ts
Filter host for channels and playlists search
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-channels.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 cleanupTests,
7 createSingleServer,
8 doubleFollow,
9 PeerTubeServer,
10 SearchCommand,
11 setAccessTokensToServers
12 } from '@shared/extra-utils'
13 import { VideoChannel } from '@shared/models'
14
15 const expect = chai.expect
16
17 describe('Test channels search', function () {
18 let server: PeerTubeServer
19 let remoteServer: PeerTubeServer
20 let command: SearchCommand
21
22 before(async function () {
23 this.timeout(30000)
24
25 server = await createSingleServer(1)
26 remoteServer = await createSingleServer(2, { transcoding: { enabled: false } })
27
28 await setAccessTokensToServers([ server, remoteServer ])
29
30 {
31 await server.users.create({ username: 'user1' })
32 const channel = {
33 name: 'squall_channel',
34 displayName: 'Squall channel'
35 }
36 await server.channels.create({ attributes: channel })
37 }
38
39 {
40 await remoteServer.users.create({ username: 'user1' })
41 const channel = {
42 name: 'zell_channel',
43 displayName: 'Zell channel'
44 }
45 const { id } = await remoteServer.channels.create({ attributes: channel })
46
47 await remoteServer.videos.upload({ attributes: { channelId: id } })
48 }
49
50 await doubleFollow(server, remoteServer)
51
52 command = server.search
53 })
54
55 it('Should make a simple search and not have results', async function () {
56 const body = await command.searchChannels({ search: 'abc' })
57
58 expect(body.total).to.equal(0)
59 expect(body.data).to.have.lengthOf(0)
60 })
61
62 it('Should make a search and have results', async function () {
63 {
64 const search = {
65 search: 'Squall',
66 start: 0,
67 count: 1
68 }
69 const body = await command.advancedChannelSearch({ search })
70 expect(body.total).to.equal(1)
71 expect(body.data).to.have.lengthOf(1)
72
73 const channel: VideoChannel = body.data[0]
74 expect(channel.name).to.equal('squall_channel')
75 expect(channel.displayName).to.equal('Squall channel')
76 }
77
78 {
79 const search = {
80 search: 'Squall',
81 start: 1,
82 count: 1
83 }
84
85 const body = await command.advancedChannelSearch({ search })
86 expect(body.total).to.equal(1)
87 expect(body.data).to.have.lengthOf(0)
88 }
89 })
90
91 it('Should filter by host', async function () {
92 {
93 const search = { search: 'channel', host: remoteServer.host }
94
95 const body = await command.advancedChannelSearch({ search })
96 expect(body.total).to.equal(1)
97 expect(body.data).to.have.lengthOf(1)
98 expect(body.data[0].displayName).to.equal('Zell channel')
99 }
100
101 {
102 const search = { search: 'Sq', host: server.host }
103
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('Squall channel')
108 }
109
110 {
111 const search = { search: 'Squall', host: 'example.com' }
112
113 const body = await command.advancedChannelSearch({ search })
114 expect(body.total).to.equal(0)
115 expect(body.data).to.have.lengthOf(0)
116 }
117 })
118
119 after(async function () {
120 await cleanupTests([ server ])
121 })
122 })