Update search index tests

This commit is contained in:
Chocobozzz 2021-07-28 13:40:26 +02:00
parent 7bb52934b7
commit 164c8d46cf
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 103 additions and 40 deletions

View File

@ -57,7 +57,7 @@ describe('Test videos API validator', function () {
await checkBadSortPagination(server.url, path, null, query)
})
it('Should success with the correct parameters', async function () {
it('Should succeed with the correct parameters', async function () {
await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
})
@ -136,13 +136,24 @@ describe('Test videos API validator', function () {
const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' }
await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should fail with an invalid host', async function () {
const customQuery = { ...query, host: '6565' }
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should succeed with a host', async function () {
const customQuery = { ...query, host: 'example.com' }
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
})
})
describe('When searching video playlists', function () {
const path = '/api/v1/search/video-playlists/'
const query = {
search: 'coucou'
search: 'coucou',
host: 'example.com'
}
it('Should fail with a bad start pagination', async function () {
@ -157,7 +168,11 @@ describe('Test videos API validator', function () {
await checkBadSortPagination(server.url, path, null, query)
})
it('Should success with the correct parameters', async function () {
it('Should fail with an invalid host', async function () {
await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should succeed with the correct parameters', async function () {
await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
})
})
@ -166,7 +181,8 @@ describe('Test videos API validator', function () {
const path = '/api/v1/search/video-channels/'
const query = {
search: 'coucou'
search: 'coucou',
host: 'example.com'
}
it('Should fail with a bad start pagination', async function () {
@ -181,7 +197,11 @@ describe('Test videos API validator', function () {
await checkBadSortPagination(server.url, path, null, query)
})
it('Should success with the correct parameters', async function () {
it('Should fail with an invalid host', async function () {
await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should succeed with the correct parameters', async function () {
await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
})
})

View File

@ -3,7 +3,14 @@
import 'mocha'
import * as chai from 'chai'
import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils'
import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
import {
BooleanBothQuery,
VideoChannelsSearchQuery,
VideoPlaylistPrivacy,
VideoPlaylistsSearchQuery,
VideoPlaylistType,
VideosSearchQuery
} from '@shared/models'
const expect = chai.expect
@ -194,6 +201,16 @@ describe('Test videos search', function () {
const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
await check(search, true)
}
{
const search = { ...baseSearch, host: 'example.com' }
await check(search, false)
}
{
const search = { ...baseSearch, host: 'framatube.org' }
await check(search, true)
}
})
it('Should have a correct pagination', async function () {
@ -258,7 +275,15 @@ describe('Test videos search', function () {
})
it('Should make a search and have results', async function () {
const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } })
async function check (search: VideoChannelsSearchQuery, exists = true) {
const body = await command.advancedChannelSearch({ search })
if (exists === false) {
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
return
}
expect(body.total).to.be.greaterThan(0)
expect(body.data).to.have.length.greaterThan(0)
@ -273,6 +298,11 @@ describe('Test videos search', function () {
expect(videoChannel.ownerAccount.name).to.equal('framasoft')
expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
expect(videoChannel.ownerAccount.avatar).to.exist
}
await check({ search: 'Framasoft', sort: 'createdAt' }, true)
await check({ search: 'Framasoft', host: 'example.com' }, false)
await check({ search: 'Framasoft', host: 'framatube.org' }, true)
})
it('Should have a correct pagination', async function () {
@ -293,7 +323,15 @@ describe('Test videos search', function () {
})
it('Should make a search and have results', async function () {
const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } })
async function check (search: VideoPlaylistsSearchQuery, exists = true) {
const body = await command.advancedPlaylistSearch({ search })
if (exists === false) {
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
return
}
expect(body.total).to.be.greaterThan(0)
expect(body.data).to.have.length.greaterThan(0)
@ -323,6 +361,11 @@ describe('Test videos search', function () {
expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
expect(videoPlaylist.videoChannel.avatar).to.exist
}
await check({ search: 'E2E playlist', sort: '-match' }, true)
await check({ search: 'E2E playlist', host: 'example.com' }, false)
await check({ search: 'E2E playlist', host: 'peertube2.cpy.re' }, true)
})
it('Should have a correct pagination', async function () {