]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-channels.ts
Bumped to version v5.2.1
[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 { expect } from 'chai'
4 import { VideoChannel } from '@shared/models'
5 import {
6 cleanupTests,
7 createSingleServer,
8 doubleFollow,
9 PeerTubeServer,
10 SearchCommand,
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar
14 } from '@shared/server-commands'
15
16 describe('Test channels search', function () {
17 let server: PeerTubeServer
18 let remoteServer: PeerTubeServer
19 let command: SearchCommand
20
21 before(async function () {
22 this.timeout(120000)
23
24 const servers = await Promise.all([
25 createSingleServer(1),
26 createSingleServer(2)
27 ])
28 server = servers[0]
29 remoteServer = servers[1]
30
31 await setAccessTokensToServers([ server, remoteServer ])
32 await setDefaultChannelAvatar(server)
33 await setDefaultAccountAvatar(server)
34
35 await servers[1].config.disableTranscoding()
36
37 {
38 await server.users.create({ username: 'user1' })
39 const channel = {
40 name: 'squall_channel',
41 displayName: 'Squall channel'
42 }
43 await server.channels.create({ attributes: channel })
44 }
45
46 {
47 await remoteServer.users.create({ username: 'user1' })
48 const channel = {
49 name: 'zell_channel',
50 displayName: 'Zell channel'
51 }
52 const { id } = await remoteServer.channels.create({ attributes: channel })
53
54 await remoteServer.videos.upload({ attributes: { channelId: id } })
55 }
56
57 await doubleFollow(server, remoteServer)
58
59 command = server.search
60 })
61
62 it('Should make a simple search and not have results', async function () {
63 const body = await command.searchChannels({ search: 'abc' })
64
65 expect(body.total).to.equal(0)
66 expect(body.data).to.have.lengthOf(0)
67 })
68
69 it('Should make a search and have results', async function () {
70 {
71 const search = {
72 search: 'Squall',
73 start: 0,
74 count: 1
75 }
76 const body = await command.advancedChannelSearch({ search })
77 expect(body.total).to.equal(1)
78 expect(body.data).to.have.lengthOf(1)
79
80 const channel: VideoChannel = body.data[0]
81 expect(channel.name).to.equal('squall_channel')
82 expect(channel.displayName).to.equal('Squall channel')
83 }
84
85 {
86 const search = {
87 search: 'Squall',
88 start: 1,
89 count: 1
90 }
91
92 const body = await command.advancedChannelSearch({ search })
93 expect(body.total).to.equal(1)
94 expect(body.data).to.have.lengthOf(0)
95 }
96 })
97
98 it('Should filter by host', async function () {
99 {
100 const search = { search: 'channel', host: remoteServer.host }
101
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')
106 }
107
108 {
109 const search = { search: 'Sq', host: server.host }
110
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')
115 }
116
117 {
118 const search = { search: 'Squall', host: 'example.com' }
119
120 const body = await command.advancedChannelSearch({ search })
121 expect(body.total).to.equal(0)
122 expect(body.data).to.have.lengthOf(0)
123 }
124 })
125
126 it('Should filter by names', async function () {
127 {
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')
132 }
133
134 {
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')
139 }
140
141 {
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)
145 }
146
147 {
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')
153 }
154 })
155
156 after(async function () {
157 await cleanupTests([ server, remoteServer ])
158 })
159 })