aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/search/search-index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/search/search-index.ts')
-rw-r--r--server/tests/api/search/search-index.ts206
1 files changed, 105 insertions, 101 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index 00f79232a..feb35411f 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -2,36 +2,27 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { advancedVideoChannelSearch, searchVideoChannel } from '@shared/extra-utils/search/video-channels' 5import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils'
6import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' 6import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
7import {
8 advancedVideoPlaylistSearch,
9 advancedVideosSearch,
10 cleanupTests,
11 flushAndRunServer,
12 immutableAssign,
13 searchVideo,
14 searchVideoPlaylists,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateCustomSubConfig,
18 uploadVideo
19} from '../../../../shared/extra-utils'
20 7
21const expect = chai.expect 8const expect = chai.expect
22 9
23describe('Test videos search', function () { 10describe('Test videos search', function () {
24 let server: ServerInfo = null
25 const localVideoName = 'local video' + new Date().toISOString() 11 const localVideoName = 'local video' + new Date().toISOString()
26 12
13 let server: PeerTubeServer = null
14 let command: SearchCommand
15
27 before(async function () { 16 before(async function () {
28 this.timeout(30000) 17 this.timeout(30000)
29 18
30 server = await flushAndRunServer(1) 19 server = await createSingleServer(1)
31 20
32 await setAccessTokensToServers([ server ]) 21 await setAccessTokensToServers([ server ])
33 22
34 await uploadVideo(server.url, server.accessToken, { name: localVideoName }) 23 await server.videos.upload({ attributes: { name: localVideoName } })
24
25 command = server.search
35 }) 26 })
36 27
37 describe('Default search', async function () { 28 describe('Default search', async function () {
@@ -39,101 +30,107 @@ describe('Test videos search', function () {
39 it('Should make a local videos search by default', async function () { 30 it('Should make a local videos search by default', async function () {
40 this.timeout(10000) 31 this.timeout(10000)
41 32
42 await updateCustomSubConfig(server.url, server.accessToken, { 33 await server.config.updateCustomSubConfig({
43 search: { 34 newConfig: {
44 searchIndex: { 35 search: {
45 enabled: true, 36 searchIndex: {
46 isDefaultSearch: false, 37 enabled: true,
47 disableLocalSearch: false 38 isDefaultSearch: false,
39 disableLocalSearch: false
40 }
48 } 41 }
49 } 42 }
50 }) 43 })
51 44
52 const res = await searchVideo(server.url, 'local video') 45 const body = await command.searchVideos({ search: 'local video' })
53 46
54 expect(res.body.total).to.equal(1) 47 expect(body.total).to.equal(1)
55 expect(res.body.data[0].name).to.equal(localVideoName) 48 expect(body.data[0].name).to.equal(localVideoName)
56 }) 49 })
57 50
58 it('Should make a local channels search by default', async function () { 51 it('Should make a local channels search by default', async function () {
59 const res = await searchVideoChannel(server.url, 'root') 52 const body = await command.searchChannels({ search: 'root' })
60 53
61 expect(res.body.total).to.equal(1) 54 expect(body.total).to.equal(1)
62 expect(res.body.data[0].name).to.equal('root_channel') 55 expect(body.data[0].name).to.equal('root_channel')
63 expect(res.body.data[0].host).to.equal('localhost:' + server.port) 56 expect(body.data[0].host).to.equal('localhost:' + server.port)
64 }) 57 })
65 58
66 it('Should make an index videos search by default', async function () { 59 it('Should make an index videos search by default', async function () {
67 await updateCustomSubConfig(server.url, server.accessToken, { 60 await server.config.updateCustomSubConfig({
68 search: { 61 newConfig: {
69 searchIndex: { 62 search: {
70 enabled: true, 63 searchIndex: {
71 isDefaultSearch: true, 64 enabled: true,
72 disableLocalSearch: false 65 isDefaultSearch: true,
66 disableLocalSearch: false
67 }
73 } 68 }
74 } 69 }
75 }) 70 })
76 71
77 const res = await searchVideo(server.url, 'local video') 72 const body = await command.searchVideos({ search: 'local video' })
78 expect(res.body.total).to.be.greaterThan(2) 73 expect(body.total).to.be.greaterThan(2)
79 }) 74 })
80 75
81 it('Should make an index channels search by default', async function () { 76 it('Should make an index channels search by default', async function () {
82 const res = await searchVideoChannel(server.url, 'root') 77 const body = await command.searchChannels({ search: 'root' })
83 expect(res.body.total).to.be.greaterThan(2) 78 expect(body.total).to.be.greaterThan(2)
84 }) 79 })
85 80
86 it('Should make an index videos search if local search is disabled', async function () { 81 it('Should make an index videos search if local search is disabled', async function () {
87 await updateCustomSubConfig(server.url, server.accessToken, { 82 await server.config.updateCustomSubConfig({
88 search: { 83 newConfig: {
89 searchIndex: { 84 search: {
90 enabled: true, 85 searchIndex: {
91 isDefaultSearch: false, 86 enabled: true,
92 disableLocalSearch: true 87 isDefaultSearch: false,
88 disableLocalSearch: true
89 }
93 } 90 }
94 } 91 }
95 }) 92 })
96 93
97 const res = await searchVideo(server.url, 'local video') 94 const body = await command.searchVideos({ search: 'local video' })
98 expect(res.body.total).to.be.greaterThan(2) 95 expect(body.total).to.be.greaterThan(2)
99 }) 96 })
100 97
101 it('Should make an index channels search if local search is disabled', async function () { 98 it('Should make an index channels search if local search is disabled', async function () {
102 const res = await searchVideoChannel(server.url, 'root') 99 const body = await command.searchChannels({ search: 'root' })
103 expect(res.body.total).to.be.greaterThan(2) 100 expect(body.total).to.be.greaterThan(2)
104 }) 101 })
105 }) 102 })
106 103
107 describe('Videos search', async function () { 104 describe('Videos search', async function () {
108 105
109 it('Should make a simple search and not have results', async function () { 106 it('Should make a simple search and not have results', async function () {
110 const res = await searchVideo(server.url, 'djidane'.repeat(50)) 107 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
111 108
112 expect(res.body.total).to.equal(0) 109 expect(body.total).to.equal(0)
113 expect(res.body.data).to.have.lengthOf(0) 110 expect(body.data).to.have.lengthOf(0)
114 }) 111 })
115 112
116 it('Should make a simple search and have results', async function () { 113 it('Should make a simple search and have results', async function () {
117 const res = await searchVideo(server.url, 'What is PeerTube') 114 const body = await command.searchVideos({ search: 'What is PeerTube' })
118 115
119 expect(res.body.total).to.be.greaterThan(1) 116 expect(body.total).to.be.greaterThan(1)
120 }) 117 })
121 118
122 it('Should make a complex search', async function () { 119 it('Should make a complex search', async function () {
123 120
124 async function check (search: VideosSearchQuery, exists = true) { 121 async function check (search: VideosSearchQuery, exists = true) {
125 const res = await advancedVideosSearch(server.url, search) 122 const body = await command.advancedVideoSearch({ search })
126 123
127 if (exists === false) { 124 if (exists === false) {
128 expect(res.body.total).to.equal(0) 125 expect(body.total).to.equal(0)
129 expect(res.body.data).to.have.lengthOf(0) 126 expect(body.data).to.have.lengthOf(0)
130 return 127 return
131 } 128 }
132 129
133 expect(res.body.total).to.equal(1) 130 expect(body.total).to.equal(1)
134 expect(res.body.data).to.have.lengthOf(1) 131 expect(body.data).to.have.lengthOf(1)
135 132
136 const video: Video = res.body.data[0] 133 const video = body.data[0]
137 134
138 expect(video.name).to.equal('What is PeerTube?') 135 expect(video.name).to.equal('What is PeerTube?')
139 expect(video.category.label).to.equal('Science & Technology') 136 expect(video.category.label).to.equal('Science & Technology')
@@ -169,32 +166,32 @@ describe('Test videos search', function () {
169 } 166 }
170 167
171 { 168 {
172 const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' }) 169 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
173 await check(search, false) 170 await check(search, false)
174 } 171 }
175 172
176 { 173 {
177 const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] }) 174 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
178 await check(search, false) 175 await check(search, false)
179 } 176 }
180 177
181 { 178 {
182 const search = immutableAssign(baseSearch, { durationMin: 2000 }) 179 const search = { ...baseSearch, durationMin: 2000 }
183 await check(search, false) 180 await check(search, false)
184 } 181 }
185 182
186 { 183 {
187 const search = immutableAssign(baseSearch, { nsfw: 'true' }) 184 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
188 await check(search, false) 185 await check(search, false)
189 } 186 }
190 187
191 { 188 {
192 const search = immutableAssign(baseSearch, { nsfw: 'false' }) 189 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
193 await check(search, true) 190 await check(search, true)
194 } 191 }
195 192
196 { 193 {
197 const search = immutableAssign(baseSearch, { nsfw: 'both' }) 194 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
198 await check(search, true) 195 await check(search, true)
199 } 196 }
200 }) 197 })
@@ -206,37 +203,44 @@ describe('Test videos search', function () {
206 count: 5 203 count: 5
207 } 204 }
208 205
209 const res = await advancedVideosSearch(server.url, search) 206 const body = await command.advancedVideoSearch({ search })
210 207
211 expect(res.body.total).to.be.greaterThan(5) 208 expect(body.total).to.be.greaterThan(5)
212 expect(res.body.data).to.have.lengthOf(5) 209 expect(body.data).to.have.lengthOf(5)
213 }) 210 })
214 211
215 it('Should use the nsfw instance policy as default', async function () { 212 it('Should use the nsfw instance policy as default', async function () {
216 let nsfwUUID: string 213 let nsfwUUID: string
217 214
218 { 215 {
219 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) 216 await server.config.updateCustomSubConfig({
217 newConfig: {
218 instance: { defaultNSFWPolicy: 'display' }
219 }
220 })
220 221
221 const res = await searchVideo(server.url, 'NSFW search index', '-match') 222 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
222 const video = res.body.data[0] as Video 223 expect(body.data).to.have.length.greaterThan(0)
223 224
224 expect(res.body.data).to.have.length.greaterThan(0) 225 const video = body.data[0]
225 expect(video.nsfw).to.be.true 226 expect(video.nsfw).to.be.true
226 227
227 nsfwUUID = video.uuid 228 nsfwUUID = video.uuid
228 } 229 }
229 230
230 { 231 {
231 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) 232 await server.config.updateCustomSubConfig({
233 newConfig: {
234 instance: { defaultNSFWPolicy: 'do_not_list' }
235 }
236 })
232 237
233 const res = await searchVideo(server.url, 'NSFW search index', '-match') 238 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
234 239
235 try { 240 try {
236 expect(res.body.data).to.have.lengthOf(0) 241 expect(body.data).to.have.lengthOf(0)
237 } catch (err) { 242 } catch {
238 // 243 const video = body.data[0]
239 const video = res.body.data[0] as Video
240 244
241 expect(video.uuid).not.equal(nsfwUUID) 245 expect(video.uuid).not.equal(nsfwUUID)
242 } 246 }
@@ -247,19 +251,19 @@ describe('Test videos search', function () {
247 describe('Channels search', async function () { 251 describe('Channels search', async function () {
248 252
249 it('Should make a simple search and not have results', async function () { 253 it('Should make a simple search and not have results', async function () {
250 const res = await searchVideoChannel(server.url, 'a'.repeat(500)) 254 const body = await command.searchChannels({ search: 'a'.repeat(500) })
251 255
252 expect(res.body.total).to.equal(0) 256 expect(body.total).to.equal(0)
253 expect(res.body.data).to.have.lengthOf(0) 257 expect(body.data).to.have.lengthOf(0)
254 }) 258 })
255 259
256 it('Should make a search and have results', async function () { 260 it('Should make a search and have results', async function () {
257 const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' }) 261 const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } })
258 262
259 expect(res.body.total).to.be.greaterThan(0) 263 expect(body.total).to.be.greaterThan(0)
260 expect(res.body.data).to.have.length.greaterThan(0) 264 expect(body.data).to.have.length.greaterThan(0)
261 265
262 const videoChannel: VideoChannel = res.body.data[0] 266 const videoChannel = body.data[0]
263 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') 267 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
264 expect(videoChannel.host).to.equal('framatube.org') 268 expect(videoChannel.host).to.equal('framatube.org')
265 expect(videoChannel.avatar).to.exist 269 expect(videoChannel.avatar).to.exist
@@ -272,29 +276,29 @@ describe('Test videos search', function () {
272 }) 276 })
273 277
274 it('Should have a correct pagination', async function () { 278 it('Should have a correct pagination', async function () {
275 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 279 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
276 280
277 expect(res.body.total).to.be.greaterThan(2) 281 expect(body.total).to.be.greaterThan(2)
278 expect(res.body.data).to.have.lengthOf(2) 282 expect(body.data).to.have.lengthOf(2)
279 }) 283 })
280 }) 284 })
281 285
282 describe('Playlists search', async function () { 286 describe('Playlists search', async function () {
283 287
284 it('Should make a simple search and not have results', async function () { 288 it('Should make a simple search and not have results', async function () {
285 const res = await searchVideoPlaylists(server.url, 'a'.repeat(500)) 289 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
286 290
287 expect(res.body.total).to.equal(0) 291 expect(body.total).to.equal(0)
288 expect(res.body.data).to.have.lengthOf(0) 292 expect(body.data).to.have.lengthOf(0)
289 }) 293 })
290 294
291 it('Should make a search and have results', async function () { 295 it('Should make a search and have results', async function () {
292 const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' }) 296 const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } })
293 297
294 expect(res.body.total).to.be.greaterThan(0) 298 expect(body.total).to.be.greaterThan(0)
295 expect(res.body.data).to.have.length.greaterThan(0) 299 expect(body.data).to.have.length.greaterThan(0)
296 300
297 const videoPlaylist: VideoPlaylist = res.body.data[0] 301 const videoPlaylist = body.data[0]
298 302
299 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') 303 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
300 expect(videoPlaylist.thumbnailUrl).to.exist 304 expect(videoPlaylist.thumbnailUrl).to.exist
@@ -322,10 +326,10 @@ describe('Test videos search', function () {
322 }) 326 })
323 327
324 it('Should have a correct pagination', async function () { 328 it('Should have a correct pagination', async function () {
325 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 329 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
326 330
327 expect(res.body.total).to.be.greaterThan(2) 331 expect(body.total).to.be.greaterThan(2)
328 expect(res.body.data).to.have.lengthOf(2) 332 expect(body.data).to.have.lengthOf(2)
329 }) 333 })
330 }) 334 })
331 335