]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-channels.ts
Add ability to search by uuids/actor names
[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(120000)
24
25 const servers = await Promise.all([
26 createSingleServer(1),
27 createSingleServer(2, { transcoding: { enabled: false } })
28 ])
29 server = servers[0]
30 remoteServer = servers[1]
31
32 await setAccessTokensToServers([ server, remoteServer ])
33
34 {
35 await server.users.create({ username: 'user1' })
36 const channel = {
37 name: 'squall_channel',
38 displayName: 'Squall channel'
39 }
40 await server.channels.create({ attributes: channel })
41 }
42
43 {
44 await remoteServer.users.create({ username: 'user1' })
45 const channel = {
46 name: 'zell_channel',
47 displayName: 'Zell channel'
48 }
49 const { id } = await remoteServer.channels.create({ attributes: channel })
50
51 await remoteServer.videos.upload({ attributes: { channelId: id } })
52 }
53
54 await doubleFollow(server, remoteServer)
55
56 command = server.search
57 })
58
59 it('Should make a simple search and not have results', async function () {
60 const body = await command.searchChannels({ search: 'abc' })
61
62 expect(body.total).to.equal(0)
63 expect(body.data).to.have.lengthOf(0)
64 })
65
66 it('Should make a search and have results', async function () {
67 {
68 const search = {
69 search: 'Squall',
70 start: 0,
71 count: 1
72 }
73 const body = await command.advancedChannelSearch({ search })
74 expect(body.total).to.equal(1)
75 expect(body.data).to.have.lengthOf(1)
76
77 const channel: VideoChannel = body.data[0]
78 expect(channel.name).to.equal('squall_channel')
79 expect(channel.displayName).to.equal('Squall channel')
80 }
81
82 {
83 const search = {
84 search: 'Squall',
85 start: 1,
86 count: 1
87 }
88
89 const body = await command.advancedChannelSearch({ search })
90 expect(body.total).to.equal(1)
91 expect(body.data).to.have.lengthOf(0)
92 }
93 })
94
95 it('Should filter by host', async function () {
96 {
97 const search = { search: 'channel', host: remoteServer.host }
98
99 const body = await command.advancedChannelSearch({ search })
100 expect(body.total).to.equal(1)
101 expect(body.data).to.have.lengthOf(1)
102 expect(body.data[0].displayName).to.equal('Zell channel')
103 }
104
105 {
106 const search = { search: 'Sq', host: server.host }
107
108 const body = await command.advancedChannelSearch({ search })
109 expect(body.total).to.equal(1)
110 expect(body.data).to.have.lengthOf(1)
111 expect(body.data[0].displayName).to.equal('Squall channel')
112 }
113
114 {
115 const search = { search: 'Squall', host: 'example.com' }
116
117 const body = await command.advancedChannelSearch({ search })
118 expect(body.total).to.equal(0)
119 expect(body.data).to.have.lengthOf(0)
120 }
121 })
122
123 it('Should filter by names', async function () {
124 {
125 const body = await command.advancedChannelSearch({ search: { names: [ 'squall_channel', 'zell_channel' ] } })
126 expect(body.total).to.equal(2)
127 expect(body.data).to.have.lengthOf(2)
128 expect(body.data[0].displayName).to.equal('Squall channel')
129 expect(body.data[1].displayName).to.equal('Zell channel')
130 }
131
132 {
133 const body = await command.advancedChannelSearch({ search: { names: [ 'chocobozzz_channel' ] } })
134 expect(body.total).to.equal(0)
135 expect(body.data).to.have.lengthOf(0)
136 }
137 })
138
139 after(async function () {
140 await cleanupTests([ server ])
141 })
142 })