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.ts129
1 files changed, 64 insertions, 65 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index 00f79232a..b2c0857a7 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -2,28 +2,26 @@
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'
6import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
7import { 5import {
8 advancedVideoPlaylistSearch,
9 advancedVideosSearch,
10 cleanupTests, 6 cleanupTests,
11 flushAndRunServer, 7 flushAndRunServer,
12 immutableAssign, 8 immutableAssign,
13 searchVideo, 9 SearchCommand,
14 searchVideoPlaylists,
15 ServerInfo, 10 ServerInfo,
16 setAccessTokensToServers, 11 setAccessTokensToServers,
17 updateCustomSubConfig, 12 updateCustomSubConfig,
18 uploadVideo 13 uploadVideo
19} from '../../../../shared/extra-utils' 14} from '@shared/extra-utils'
15import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
20 16
21const expect = chai.expect 17const expect = chai.expect
22 18
23describe('Test videos search', function () { 19describe('Test videos search', function () {
24 let server: ServerInfo = null
25 const localVideoName = 'local video' + new Date().toISOString() 20 const localVideoName = 'local video' + new Date().toISOString()
26 21
22 let server: ServerInfo = null
23 let command: SearchCommand
24
27 before(async function () { 25 before(async function () {
28 this.timeout(30000) 26 this.timeout(30000)
29 27
@@ -32,6 +30,8 @@ describe('Test videos search', function () {
32 await setAccessTokensToServers([ server ]) 30 await setAccessTokensToServers([ server ])
33 31
34 await uploadVideo(server.url, server.accessToken, { name: localVideoName }) 32 await uploadVideo(server.url, server.accessToken, { name: localVideoName })
33
34 command = server.searchCommand
35 }) 35 })
36 36
37 describe('Default search', async function () { 37 describe('Default search', async function () {
@@ -49,18 +49,18 @@ describe('Test videos search', function () {
49 } 49 }
50 }) 50 })
51 51
52 const res = await searchVideo(server.url, 'local video') 52 const body = await command.searchVideos({ search: 'local video' })
53 53
54 expect(res.body.total).to.equal(1) 54 expect(body.total).to.equal(1)
55 expect(res.body.data[0].name).to.equal(localVideoName) 55 expect(body.data[0].name).to.equal(localVideoName)
56 }) 56 })
57 57
58 it('Should make a local channels search by default', async function () { 58 it('Should make a local channels search by default', async function () {
59 const res = await searchVideoChannel(server.url, 'root') 59 const body = await command.searchChannels({ search: 'root' })
60 60
61 expect(res.body.total).to.equal(1) 61 expect(body.total).to.equal(1)
62 expect(res.body.data[0].name).to.equal('root_channel') 62 expect(body.data[0].name).to.equal('root_channel')
63 expect(res.body.data[0].host).to.equal('localhost:' + server.port) 63 expect(body.data[0].host).to.equal('localhost:' + server.port)
64 }) 64 })
65 65
66 it('Should make an index videos search by default', async function () { 66 it('Should make an index videos search by default', async function () {
@@ -74,13 +74,13 @@ describe('Test videos search', function () {
74 } 74 }
75 }) 75 })
76 76
77 const res = await searchVideo(server.url, 'local video') 77 const body = await command.searchVideos({ search: 'local video' })
78 expect(res.body.total).to.be.greaterThan(2) 78 expect(body.total).to.be.greaterThan(2)
79 }) 79 })
80 80
81 it('Should make an index channels search by default', async function () { 81 it('Should make an index channels search by default', async function () {
82 const res = await searchVideoChannel(server.url, 'root') 82 const body = await command.searchChannels({ search: 'root' })
83 expect(res.body.total).to.be.greaterThan(2) 83 expect(body.total).to.be.greaterThan(2)
84 }) 84 })
85 85
86 it('Should make an index videos search if local search is disabled', async function () { 86 it('Should make an index videos search if local search is disabled', async function () {
@@ -94,46 +94,46 @@ describe('Test videos search', function () {
94 } 94 }
95 }) 95 })
96 96
97 const res = await searchVideo(server.url, 'local video') 97 const body = await command.searchVideos({ search: 'local video' })
98 expect(res.body.total).to.be.greaterThan(2) 98 expect(body.total).to.be.greaterThan(2)
99 }) 99 })
100 100
101 it('Should make an index channels search if local search is disabled', async function () { 101 it('Should make an index channels search if local search is disabled', async function () {
102 const res = await searchVideoChannel(server.url, 'root') 102 const body = await command.searchChannels({ search: 'root' })
103 expect(res.body.total).to.be.greaterThan(2) 103 expect(body.total).to.be.greaterThan(2)
104 }) 104 })
105 }) 105 })
106 106
107 describe('Videos search', async function () { 107 describe('Videos search', async function () {
108 108
109 it('Should make a simple search and not have results', async function () { 109 it('Should make a simple search and not have results', async function () {
110 const res = await searchVideo(server.url, 'djidane'.repeat(50)) 110 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
111 111
112 expect(res.body.total).to.equal(0) 112 expect(body.total).to.equal(0)
113 expect(res.body.data).to.have.lengthOf(0) 113 expect(body.data).to.have.lengthOf(0)
114 }) 114 })
115 115
116 it('Should make a simple search and have results', async function () { 116 it('Should make a simple search and have results', async function () {
117 const res = await searchVideo(server.url, 'What is PeerTube') 117 const body = await command.searchVideos({ search: 'What is PeerTube' })
118 118
119 expect(res.body.total).to.be.greaterThan(1) 119 expect(body.total).to.be.greaterThan(1)
120 }) 120 })
121 121
122 it('Should make a complex search', async function () { 122 it('Should make a complex search', async function () {
123 123
124 async function check (search: VideosSearchQuery, exists = true) { 124 async function check (search: VideosSearchQuery, exists = true) {
125 const res = await advancedVideosSearch(server.url, search) 125 const body = await command.advancedVideoSearch({ search })
126 126
127 if (exists === false) { 127 if (exists === false) {
128 expect(res.body.total).to.equal(0) 128 expect(body.total).to.equal(0)
129 expect(res.body.data).to.have.lengthOf(0) 129 expect(body.data).to.have.lengthOf(0)
130 return 130 return
131 } 131 }
132 132
133 expect(res.body.total).to.equal(1) 133 expect(body.total).to.equal(1)
134 expect(res.body.data).to.have.lengthOf(1) 134 expect(body.data).to.have.lengthOf(1)
135 135
136 const video: Video = res.body.data[0] 136 const video = body.data[0]
137 137
138 expect(video.name).to.equal('What is PeerTube?') 138 expect(video.name).to.equal('What is PeerTube?')
139 expect(video.category.label).to.equal('Science & Technology') 139 expect(video.category.label).to.equal('Science & Technology')
@@ -206,10 +206,10 @@ describe('Test videos search', function () {
206 count: 5 206 count: 5
207 } 207 }
208 208
209 const res = await advancedVideosSearch(server.url, search) 209 const body = await command.advancedVideoSearch({ search })
210 210
211 expect(res.body.total).to.be.greaterThan(5) 211 expect(body.total).to.be.greaterThan(5)
212 expect(res.body.data).to.have.lengthOf(5) 212 expect(body.data).to.have.lengthOf(5)
213 }) 213 })
214 214
215 it('Should use the nsfw instance policy as default', async function () { 215 it('Should use the nsfw instance policy as default', async function () {
@@ -218,10 +218,10 @@ describe('Test videos search', function () {
218 { 218 {
219 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) 219 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } })
220 220
221 const res = await searchVideo(server.url, 'NSFW search index', '-match') 221 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
222 const video = res.body.data[0] as Video 222 expect(body.data).to.have.length.greaterThan(0)
223 223
224 expect(res.body.data).to.have.length.greaterThan(0) 224 const video = body.data[0]
225 expect(video.nsfw).to.be.true 225 expect(video.nsfw).to.be.true
226 226
227 nsfwUUID = video.uuid 227 nsfwUUID = video.uuid
@@ -230,13 +230,12 @@ describe('Test videos search', function () {
230 { 230 {
231 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) 231 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } })
232 232
233 const res = await searchVideo(server.url, 'NSFW search index', '-match') 233 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
234 234
235 try { 235 try {
236 expect(res.body.data).to.have.lengthOf(0) 236 expect(body.data).to.have.lengthOf(0)
237 } catch (err) { 237 } catch {
238 // 238 const video = body.data[0]
239 const video = res.body.data[0] as Video
240 239
241 expect(video.uuid).not.equal(nsfwUUID) 240 expect(video.uuid).not.equal(nsfwUUID)
242 } 241 }
@@ -247,19 +246,19 @@ describe('Test videos search', function () {
247 describe('Channels search', async function () { 246 describe('Channels search', async function () {
248 247
249 it('Should make a simple search and not have results', async function () { 248 it('Should make a simple search and not have results', async function () {
250 const res = await searchVideoChannel(server.url, 'a'.repeat(500)) 249 const body = await command.searchChannels({ search: 'a'.repeat(500) })
251 250
252 expect(res.body.total).to.equal(0) 251 expect(body.total).to.equal(0)
253 expect(res.body.data).to.have.lengthOf(0) 252 expect(body.data).to.have.lengthOf(0)
254 }) 253 })
255 254
256 it('Should make a search and have results', async function () { 255 it('Should make a search and have results', async function () {
257 const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' }) 256 const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } })
258 257
259 expect(res.body.total).to.be.greaterThan(0) 258 expect(body.total).to.be.greaterThan(0)
260 expect(res.body.data).to.have.length.greaterThan(0) 259 expect(body.data).to.have.length.greaterThan(0)
261 260
262 const videoChannel: VideoChannel = res.body.data[0] 261 const videoChannel = body.data[0]
263 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') 262 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
264 expect(videoChannel.host).to.equal('framatube.org') 263 expect(videoChannel.host).to.equal('framatube.org')
265 expect(videoChannel.avatar).to.exist 264 expect(videoChannel.avatar).to.exist
@@ -272,29 +271,29 @@ describe('Test videos search', function () {
272 }) 271 })
273 272
274 it('Should have a correct pagination', async function () { 273 it('Should have a correct pagination', async function () {
275 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 274 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
276 275
277 expect(res.body.total).to.be.greaterThan(2) 276 expect(body.total).to.be.greaterThan(2)
278 expect(res.body.data).to.have.lengthOf(2) 277 expect(body.data).to.have.lengthOf(2)
279 }) 278 })
280 }) 279 })
281 280
282 describe('Playlists search', async function () { 281 describe('Playlists search', async function () {
283 282
284 it('Should make a simple search and not have results', async function () { 283 it('Should make a simple search and not have results', async function () {
285 const res = await searchVideoPlaylists(server.url, 'a'.repeat(500)) 284 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
286 285
287 expect(res.body.total).to.equal(0) 286 expect(body.total).to.equal(0)
288 expect(res.body.data).to.have.lengthOf(0) 287 expect(body.data).to.have.lengthOf(0)
289 }) 288 })
290 289
291 it('Should make a search and have results', async function () { 290 it('Should make a search and have results', async function () {
292 const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' }) 291 const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } })
293 292
294 expect(res.body.total).to.be.greaterThan(0) 293 expect(body.total).to.be.greaterThan(0)
295 expect(res.body.data).to.have.length.greaterThan(0) 294 expect(body.data).to.have.length.greaterThan(0)
296 295
297 const videoPlaylist: VideoPlaylist = res.body.data[0] 296 const videoPlaylist = body.data[0]
298 297
299 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') 298 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
300 expect(videoPlaylist.thumbnailUrl).to.exist 299 expect(videoPlaylist.thumbnailUrl).to.exist
@@ -322,10 +321,10 @@ describe('Test videos search', function () {
322 }) 321 })
323 322
324 it('Should have a correct pagination', async function () { 323 it('Should have a correct pagination', async function () {
325 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 324 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
326 325
327 expect(res.body.total).to.be.greaterThan(2) 326 expect(body.total).to.be.greaterThan(2)
328 expect(res.body.data).to.have.lengthOf(2) 327 expect(body.data).to.have.lengthOf(2)
329 }) 328 })
330 }) 329 })
331 330