aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/tests/api/search/search-index.ts231
1 files changed, 120 insertions, 111 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index d1aa5ef41..4c8b1f608 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -110,6 +110,49 @@ describe('Test videos search', function () {
110 110
111 describe('Videos search', async function () { 111 describe('Videos search', async function () {
112 112
113 async function check (search: VideosSearchQuery, exists = true) {
114 const body = await command.advancedVideoSearch({ search })
115
116 if (exists === false) {
117 expect(body.total).to.equal(0)
118 expect(body.data).to.have.lengthOf(0)
119 return
120 }
121
122 expect(body.total).to.equal(1)
123 expect(body.data).to.have.lengthOf(1)
124
125 const video = body.data[0]
126
127 expect(video.name).to.equal('What is PeerTube?')
128 expect(video.category.label).to.equal('Science & Technology')
129 expect(video.licence.label).to.equal('Attribution - Share Alike')
130 expect(video.privacy.label).to.equal('Public')
131 expect(video.duration).to.equal(113)
132 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
133
134 expect(video.account.host).to.equal('framatube.org')
135 expect(video.account.name).to.equal('framasoft')
136 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
137 expect(video.account.avatar).to.exist
138
139 expect(video.channel.host).to.equal('framatube.org')
140 expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8')
141 expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
142 expect(video.channel.avatar).to.exist
143 }
144
145 const baseSearch: VideosSearchQuery = {
146 search: 'what is peertube',
147 start: 0,
148 count: 2,
149 categoryOneOf: [ 15 ],
150 licenceOneOf: [ 2 ],
151 tagsAllOf: [ 'framasoft', 'peertube' ],
152 startDate: '2018-10-01T10:50:46.396Z',
153 endDate: '2018-10-01T10:55:46.396Z'
154 }
155
113 it('Should make a simple search and not have results', async function () { 156 it('Should make a simple search and not have results', async function () {
114 const body = await command.searchVideos({ search: 'djidane'.repeat(50) }) 157 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
115 158
@@ -123,70 +166,26 @@ describe('Test videos search', function () {
123 expect(body.total).to.be.greaterThan(1) 166 expect(body.total).to.be.greaterThan(1)
124 }) 167 })
125 168
126 it('Should make a complex search', async function () { 169 it('Should make a simple search', async function () {
127 170 await check(baseSearch)
128 async function check (search: VideosSearchQuery, exists = true) { 171 })
129 const body = await command.advancedVideoSearch({ search })
130
131 if (exists === false) {
132 expect(body.total).to.equal(0)
133 expect(body.data).to.have.lengthOf(0)
134 return
135 }
136
137 expect(body.total).to.equal(1)
138 expect(body.data).to.have.lengthOf(1)
139
140 const video = body.data[0]
141
142 expect(video.name).to.equal('What is PeerTube?')
143 expect(video.category.label).to.equal('Science & Technology')
144 expect(video.licence.label).to.equal('Attribution - Share Alike')
145 expect(video.privacy.label).to.equal('Public')
146 expect(video.duration).to.equal(113)
147 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
148
149 expect(video.account.host).to.equal('framatube.org')
150 expect(video.account.name).to.equal('framasoft')
151 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
152 expect(video.account.avatar).to.exist
153
154 expect(video.channel.host).to.equal('framatube.org')
155 expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8')
156 expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
157 expect(video.channel.avatar).to.exist
158 }
159
160 const baseSearch: VideosSearchQuery = {
161 search: 'what is peertube',
162 start: 0,
163 count: 2,
164 categoryOneOf: [ 15 ],
165 licenceOneOf: [ 2 ],
166 tagsAllOf: [ 'framasoft', 'peertube' ],
167 startDate: '2018-10-01T10:50:46.396Z',
168 endDate: '2018-10-01T10:55:46.396Z'
169 }
170
171 {
172 await check(baseSearch)
173 }
174 172
175 { 173 it('Should search by start date', async function () {
176 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' } 174 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
177 await check(search, false) 175 await check(search, false)
178 } 176 })
179 177
180 { 178 it('Should search by tags', async function () {
181 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] } 179 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
182 await check(search, false) 180 await check(search, false)
183 } 181 })
184 182
185 { 183 it('Should search by duration', async function () {
186 const search = { ...baseSearch, durationMin: 2000 } 184 const search = { ...baseSearch, durationMin: 2000 }
187 await check(search, false) 185 await check(search, false)
188 } 186 })
189 187
188 it('Should search by nsfw attribute', async function () {
190 { 189 {
191 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery } 190 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
192 await check(search, false) 191 await check(search, false)
@@ -201,7 +200,9 @@ describe('Test videos search', function () {
201 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } 200 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
202 await check(search, true) 201 await check(search, true)
203 } 202 }
203 })
204 204
205 it('Should search by host', async function () {
205 { 206 {
206 const search = { ...baseSearch, host: 'example.com' } 207 const search = { ...baseSearch, host: 'example.com' }
207 await check(search, false) 208 await check(search, false)
@@ -211,37 +212,37 @@ describe('Test videos search', function () {
211 const search = { ...baseSearch, host: 'framatube.org' } 212 const search = { ...baseSearch, host: 'framatube.org' }
212 await check(search, true) 213 await check(search, true)
213 } 214 }
215 })
216
217 it('Should search by uuids', async function () {
218 const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d'
219 const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv'
220 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
221 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
214 222
215 { 223 {
216 const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d' 224 const uuidsMatrix = [
217 const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv' 225 [ goodUUID ],
218 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0' 226 [ goodUUID, badShortUUID ],
219 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej' 227 [ badShortUUID, goodShortUUID ],
220 228 [ goodUUID, goodShortUUID ]
221 { 229 ]
222 const uuidsMatrix = [ 230
223 [ goodUUID ], 231 for (const uuids of uuidsMatrix) {
224 [ goodUUID, badShortUUID ], 232 const search = { ...baseSearch, uuids }
225 [ badShortUUID, goodShortUUID ], 233 await check(search, true)
226 [ goodUUID, goodShortUUID ]
227 ]
228
229 for (const uuids of uuidsMatrix) {
230 const search = { ...baseSearch, uuids }
231 await check(search, true)
232 }
233 } 234 }
235 }
234 236
235 { 237 {
236 const uuidsMatrix = [ 238 const uuidsMatrix = [
237 [ badUUID ], 239 [ badUUID ],
238 [ badShortUUID ] 240 [ badShortUUID ]
239 ] 241 ]
240 242
241 for (const uuids of uuidsMatrix) { 243 for (const uuids of uuidsMatrix) {
242 const search = { ...baseSearch, uuids } 244 const search = { ...baseSearch, uuids }
243 await check(search, false) 245 await check(search, false)
244 }
245 } 246 }
246 } 247 }
247 }) 248 })
@@ -300,6 +301,30 @@ describe('Test videos search', function () {
300 301
301 describe('Channels search', async function () { 302 describe('Channels search', async function () {
302 303
304 async function check (search: VideoChannelsSearchQuery, exists = true) {
305 const body = await command.advancedChannelSearch({ search })
306
307 if (exists === false) {
308 expect(body.total).to.equal(0)
309 expect(body.data).to.have.lengthOf(0)
310 return
311 }
312
313 expect(body.total).to.be.greaterThan(0)
314 expect(body.data).to.have.length.greaterThan(0)
315
316 const videoChannel = body.data[0]
317 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
318 expect(videoChannel.host).to.equal('framatube.org')
319 expect(videoChannel.avatar).to.exist
320 expect(videoChannel.displayName).to.exist
321
322 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
323 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
324 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
325 expect(videoChannel.ownerAccount.avatar).to.exist
326 }
327
303 it('Should make a simple search and not have results', async function () { 328 it('Should make a simple search and not have results', async function () {
304 const body = await command.searchChannels({ search: 'a'.repeat(500) }) 329 const body = await command.searchChannels({ search: 'a'.repeat(500) })
305 330
@@ -308,36 +333,20 @@ describe('Test videos search', function () {
308 }) 333 })
309 334
310 it('Should make a search and have results', async function () { 335 it('Should make a search and have results', async function () {
311
312 async function check (search: VideoChannelsSearchQuery, exists = true) {
313 const body = await command.advancedChannelSearch({ search })
314
315 if (exists === false) {
316 expect(body.total).to.equal(0)
317 expect(body.data).to.have.lengthOf(0)
318 return
319 }
320
321 expect(body.total).to.be.greaterThan(0)
322 expect(body.data).to.have.length.greaterThan(0)
323
324 const videoChannel = body.data[0]
325 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
326 expect(videoChannel.host).to.equal('framatube.org')
327 expect(videoChannel.avatar).to.exist
328 expect(videoChannel.displayName).to.exist
329
330 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
331 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
332 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
333 expect(videoChannel.ownerAccount.avatar).to.exist
334 }
335
336 await check({ search: 'Framasoft', sort: 'createdAt' }, true) 336 await check({ search: 'Framasoft', sort: 'createdAt' }, true)
337 })
338
339 it('Should make host search and have appropriate results', async function () {
337 await check({ search: 'Framasoft', host: 'example.com' }, false) 340 await check({ search: 'Framasoft', host: 'example.com' }, false)
338 await check({ search: 'Framasoft', host: 'framatube.org' }, true) 341 await check({ search: 'Framasoft', host: 'framatube.org' }, true)
339 }) 342 })
340 343
344 it('Should make handles search and have appropriate results', async function () {
345 await check({ handles: [ 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
346 await check({ handles: [ 'jeanine', 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
347 await check({ handles: [ 'jeanine', 'chocobozzz_channel2@peertube2.cpy.re' ] }, false)
348 })
349
341 it('Should have a correct pagination', async function () { 350 it('Should have a correct pagination', async function () {
342 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) 351 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
343 352