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