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