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