diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-28 13:40:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-28 13:40:26 +0200 |
commit | 164c8d46cf5c948a28b4ac0e596fad9b83b2c229 (patch) | |
tree | 5292fb5cc46c40d6f1584f365399c91520e01732 /server | |
parent | 7bb52934b783bb9df914e0ea2488c277bdb52166 (diff) | |
download | PeerTube-164c8d46cf5c948a28b4ac0e596fad9b83b2c229.tar.gz PeerTube-164c8d46cf5c948a28b4ac0e596fad9b83b2c229.tar.zst PeerTube-164c8d46cf5c948a28b4ac0e596fad9b83b2c229.zip |
Update search index tests
Diffstat (limited to 'server')
-rw-r--r-- | server/tests/api/check-params/search.ts | 30 | ||||
-rw-r--r-- | server/tests/api/search/search-index.ts | 113 |
2 files changed, 103 insertions, 40 deletions
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index a3da54e1f..72ad6c842 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts | |||
@@ -57,7 +57,7 @@ describe('Test videos API validator', function () { | |||
57 | await checkBadSortPagination(server.url, path, null, query) | 57 | await checkBadSortPagination(server.url, path, null, query) |
58 | }) | 58 | }) |
59 | 59 | ||
60 | it('Should success with the correct parameters', async function () { | 60 | it('Should succeed with the correct parameters', async function () { |
61 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) | 61 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) |
62 | }) | 62 | }) |
63 | 63 | ||
@@ -136,13 +136,24 @@ describe('Test videos API validator', function () { | |||
136 | const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' } | 136 | const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' } |
137 | await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 137 | await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
138 | }) | 138 | }) |
139 | |||
140 | it('Should fail with an invalid host', async function () { | ||
141 | const customQuery = { ...query, host: '6565' } | ||
142 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
143 | }) | ||
144 | |||
145 | it('Should succeed with a host', async function () { | ||
146 | const customQuery = { ...query, host: 'example.com' } | ||
147 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) | ||
148 | }) | ||
139 | }) | 149 | }) |
140 | 150 | ||
141 | describe('When searching video playlists', function () { | 151 | describe('When searching video playlists', function () { |
142 | const path = '/api/v1/search/video-playlists/' | 152 | const path = '/api/v1/search/video-playlists/' |
143 | 153 | ||
144 | const query = { | 154 | const query = { |
145 | search: 'coucou' | 155 | search: 'coucou', |
156 | host: 'example.com' | ||
146 | } | 157 | } |
147 | 158 | ||
148 | it('Should fail with a bad start pagination', async function () { | 159 | it('Should fail with a bad start pagination', async function () { |
@@ -157,7 +168,11 @@ describe('Test videos API validator', function () { | |||
157 | await checkBadSortPagination(server.url, path, null, query) | 168 | await checkBadSortPagination(server.url, path, null, query) |
158 | }) | 169 | }) |
159 | 170 | ||
160 | it('Should success with the correct parameters', async function () { | 171 | it('Should fail with an invalid host', async function () { |
172 | await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
173 | }) | ||
174 | |||
175 | it('Should succeed with the correct parameters', async function () { | ||
161 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) | 176 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) |
162 | }) | 177 | }) |
163 | }) | 178 | }) |
@@ -166,7 +181,8 @@ describe('Test videos API validator', function () { | |||
166 | const path = '/api/v1/search/video-channels/' | 181 | const path = '/api/v1/search/video-channels/' |
167 | 182 | ||
168 | const query = { | 183 | const query = { |
169 | search: 'coucou' | 184 | search: 'coucou', |
185 | host: 'example.com' | ||
170 | } | 186 | } |
171 | 187 | ||
172 | it('Should fail with a bad start pagination', async function () { | 188 | it('Should fail with a bad start pagination', async function () { |
@@ -181,7 +197,11 @@ describe('Test videos API validator', function () { | |||
181 | await checkBadSortPagination(server.url, path, null, query) | 197 | await checkBadSortPagination(server.url, path, null, query) |
182 | }) | 198 | }) |
183 | 199 | ||
184 | it('Should success with the correct parameters', async function () { | 200 | it('Should fail with an invalid host', async function () { |
201 | await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
202 | }) | ||
203 | |||
204 | it('Should succeed with the correct parameters', async function () { | ||
185 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) | 205 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) |
186 | }) | 206 | }) |
187 | }) | 207 | }) |
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index feb35411f..cc841a6ff 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts | |||
@@ -3,7 +3,14 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' | 5 | import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' |
6 | import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' | 6 | import { |
7 | BooleanBothQuery, | ||
8 | VideoChannelsSearchQuery, | ||
9 | VideoPlaylistPrivacy, | ||
10 | VideoPlaylistsSearchQuery, | ||
11 | VideoPlaylistType, | ||
12 | VideosSearchQuery | ||
13 | } from '@shared/models' | ||
7 | 14 | ||
8 | const expect = chai.expect | 15 | const expect = chai.expect |
9 | 16 | ||
@@ -194,6 +201,16 @@ describe('Test videos search', function () { | |||
194 | const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } | 201 | const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } |
195 | await check(search, true) | 202 | await check(search, true) |
196 | } | 203 | } |
204 | |||
205 | { | ||
206 | const search = { ...baseSearch, host: 'example.com' } | ||
207 | await check(search, false) | ||
208 | } | ||
209 | |||
210 | { | ||
211 | const search = { ...baseSearch, host: 'framatube.org' } | ||
212 | await check(search, true) | ||
213 | } | ||
197 | }) | 214 | }) |
198 | 215 | ||
199 | it('Should have a correct pagination', async function () { | 216 | it('Should have a correct pagination', async function () { |
@@ -258,21 +275,34 @@ describe('Test videos search', function () { | |||
258 | }) | 275 | }) |
259 | 276 | ||
260 | it('Should make a search and have results', async function () { | 277 | it('Should make a search and have results', async function () { |
261 | const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } }) | ||
262 | 278 | ||
263 | expect(body.total).to.be.greaterThan(0) | 279 | async function check (search: VideoChannelsSearchQuery, exists = true) { |
264 | expect(body.data).to.have.length.greaterThan(0) | 280 | const body = await command.advancedChannelSearch({ search }) |
281 | |||
282 | if (exists === false) { | ||
283 | expect(body.total).to.equal(0) | ||
284 | expect(body.data).to.have.lengthOf(0) | ||
285 | return | ||
286 | } | ||
287 | |||
288 | expect(body.total).to.be.greaterThan(0) | ||
289 | expect(body.data).to.have.length.greaterThan(0) | ||
290 | |||
291 | const videoChannel = body.data[0] | ||
292 | expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | ||
293 | expect(videoChannel.host).to.equal('framatube.org') | ||
294 | expect(videoChannel.avatar).to.exist | ||
295 | expect(videoChannel.displayName).to.exist | ||
265 | 296 | ||
266 | const videoChannel = body.data[0] | 297 | expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') |
267 | expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | 298 | expect(videoChannel.ownerAccount.name).to.equal('framasoft') |
268 | expect(videoChannel.host).to.equal('framatube.org') | 299 | expect(videoChannel.ownerAccount.host).to.equal('framatube.org') |
269 | expect(videoChannel.avatar).to.exist | 300 | expect(videoChannel.ownerAccount.avatar).to.exist |
270 | expect(videoChannel.displayName).to.exist | 301 | } |
271 | 302 | ||
272 | expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') | 303 | await check({ search: 'Framasoft', sort: 'createdAt' }, true) |
273 | expect(videoChannel.ownerAccount.name).to.equal('framasoft') | 304 | await check({ search: 'Framasoft', host: 'example.com' }, false) |
274 | expect(videoChannel.ownerAccount.host).to.equal('framatube.org') | 305 | await check({ search: 'Framasoft', host: 'framatube.org' }, true) |
275 | expect(videoChannel.ownerAccount.avatar).to.exist | ||
276 | }) | 306 | }) |
277 | 307 | ||
278 | it('Should have a correct pagination', async function () { | 308 | it('Should have a correct pagination', async function () { |
@@ -293,36 +323,49 @@ describe('Test videos search', function () { | |||
293 | }) | 323 | }) |
294 | 324 | ||
295 | it('Should make a search and have results', async function () { | 325 | it('Should make a search and have results', async function () { |
296 | const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } }) | ||
297 | 326 | ||
298 | expect(body.total).to.be.greaterThan(0) | 327 | async function check (search: VideoPlaylistsSearchQuery, exists = true) { |
299 | expect(body.data).to.have.length.greaterThan(0) | 328 | const body = await command.advancedPlaylistSearch({ search }) |
329 | |||
330 | if (exists === false) { | ||
331 | expect(body.total).to.equal(0) | ||
332 | expect(body.data).to.have.lengthOf(0) | ||
333 | return | ||
334 | } | ||
335 | |||
336 | expect(body.total).to.be.greaterThan(0) | ||
337 | expect(body.data).to.have.length.greaterThan(0) | ||
338 | |||
339 | const videoPlaylist = body.data[0] | ||
300 | 340 | ||
301 | const videoPlaylist = body.data[0] | 341 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
342 | expect(videoPlaylist.thumbnailUrl).to.exist | ||
343 | expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | ||
302 | 344 | ||
303 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 345 | expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) |
304 | expect(videoPlaylist.thumbnailUrl).to.exist | 346 | expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) |
305 | expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 347 | expect(videoPlaylist.videosLength).to.exist |
306 | 348 | ||
307 | expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) | 349 | expect(videoPlaylist.createdAt).to.exist |
308 | expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) | 350 | expect(videoPlaylist.updatedAt).to.exist |
309 | expect(videoPlaylist.videosLength).to.exist | ||
310 | 351 | ||
311 | expect(videoPlaylist.createdAt).to.exist | 352 | expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
312 | expect(videoPlaylist.updatedAt).to.exist | 353 | expect(videoPlaylist.displayName).to.exist |
313 | 354 | ||
314 | expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 355 | expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') |
315 | expect(videoPlaylist.displayName).to.exist | 356 | expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') |
357 | expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') | ||
358 | expect(videoPlaylist.ownerAccount.avatar).to.exist | ||
316 | 359 | ||
317 | expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') | 360 | expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') |
318 | expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') | 361 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') |
319 | expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') | 362 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') |
320 | expect(videoPlaylist.ownerAccount.avatar).to.exist | 363 | expect(videoPlaylist.videoChannel.avatar).to.exist |
364 | } | ||
321 | 365 | ||
322 | expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') | 366 | await check({ search: 'E2E playlist', sort: '-match' }, true) |
323 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') | 367 | await check({ search: 'E2E playlist', host: 'example.com' }, false) |
324 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') | 368 | await check({ search: 'E2E playlist', host: 'peertube2.cpy.re' }, true) |
325 | expect(videoPlaylist.videoChannel.avatar).to.exist | ||
326 | }) | 369 | }) |
327 | 370 | ||
328 | it('Should have a correct pagination', async function () { | 371 | it('Should have a correct pagination', async function () { |