2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-07-20 07:35:18 -05:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-07 04:51:09 -05:00
|
|
|
import { HttpStatusCode } from '@shared/core-utils'
|
2020-06-09 09:39:45 -05:00
|
|
|
import {
|
2021-07-07 04:51:09 -05:00
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination,
|
2020-06-09 09:39:45 -05:00
|
|
|
cleanupTests,
|
|
|
|
flushAndRunServer,
|
|
|
|
makeGetRequest,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers
|
2021-07-07 04:51:09 -05:00
|
|
|
} from '@shared/extra-utils'
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2020-06-09 09:39:45 -05:00
|
|
|
function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) {
|
2021-07-07 04:51:09 -05:00
|
|
|
return server.configCommand.updateCustomSubConfig({
|
|
|
|
newConfig: {
|
|
|
|
search: {
|
|
|
|
searchIndex: {
|
|
|
|
enabled,
|
|
|
|
disableLocalSearch
|
|
|
|
}
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-20 07:35:18 -05:00
|
|
|
describe('Test videos API validator', function () {
|
|
|
|
let server: ServerInfo
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2019-04-24 03:53:40 -05:00
|
|
|
server = await flushAndRunServer(1)
|
2020-06-09 09:39:45 -05:00
|
|
|
await setAccessTokensToServers([ server ])
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When searching videos', function () {
|
2018-08-24 04:04:02 -05:00
|
|
|
const path = '/api/v1/search/videos/'
|
|
|
|
|
2018-07-20 07:35:18 -05:00
|
|
|
const query = {
|
|
|
|
search: 'coucou'
|
|
|
|
}
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
|
|
|
await checkBadStartPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
|
|
|
await checkBadCountPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
|
|
|
await checkBadSortPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should success with the correct parameters', async function () {
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid category', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, categoryOneOf: 'a' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with a valid category', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, categoryOneOf: 1 }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid licence', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, licenceOneOf: 'a' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with a valid licence', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, licenceOneOf: 1 }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with a valid language', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, languageOneOf: 'fr' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with valid tags', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, tagsOneOf: 'tag1' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery4 = { ...query, tagsAllOf: 'tag1' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with invalid durations', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, durationMin: 'hello' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, durationMax: 'hello' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with invalid dates', async function () {
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery1 = { ...query, startDate: 'hello' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery2 = { ...query, endDate: 'hello' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-11-27 11:57:02 -06:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-11-27 11:57:02 -06:00
|
|
|
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-06-17 09:02:38 -05:00
|
|
|
describe('When searching video playlists', function () {
|
|
|
|
const path = '/api/v1/search/video-playlists/'
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
search: 'coucou'
|
|
|
|
}
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
|
|
|
await checkBadStartPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
|
|
|
await checkBadCountPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
|
|
|
await checkBadSortPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should success with the correct parameters', async function () {
|
|
|
|
await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-24 04:04:02 -05:00
|
|
|
describe('When searching video channels', function () {
|
|
|
|
const path = '/api/v1/search/video-channels/'
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
search: 'coucou'
|
|
|
|
}
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
|
|
|
await checkBadStartPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
|
|
|
await checkBadCountPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
|
|
|
await checkBadSortPagination(server.url, path, null, query)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should success with the correct parameters', async function () {
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
|
2018-08-24 04:04:02 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-06-09 09:39:45 -05:00
|
|
|
describe('Search target', function () {
|
|
|
|
|
|
|
|
it('Should fail/succeed depending on the search target', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
const query = { search: 'coucou' }
|
|
|
|
const paths = [
|
2021-06-17 09:02:38 -05:00
|
|
|
'/api/v1/search/video-playlists/',
|
2020-06-09 09:39:45 -05:00
|
|
|
'/api/v1/search/video-channels/',
|
|
|
|
'/api/v1/search/videos/'
|
|
|
|
]
|
|
|
|
|
|
|
|
for (const path of paths) {
|
|
|
|
{
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery = { ...query, searchTarget: 'hello' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery = { ...query, searchTarget: undefined }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery = { ...query, searchTarget: 'local' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery = { ...query, searchTarget: 'search-index' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateSearchIndex(server, true, true)
|
|
|
|
|
|
|
|
{
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery = { ...query, searchTarget: 'local' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery = { ...query, searchTarget: 'search-index' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateSearchIndex(server, true, false)
|
|
|
|
|
|
|
|
{
|
2021-07-13 02:43:59 -05:00
|
|
|
const customQuery = { ...query, searchTarget: 'local' }
|
2020-12-07 07:32:36 -06:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
|
2020-06-09 09:39:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateSearchIndex(server, false, false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 08:10:37 -05:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
2018-07-20 07:35:18 -05:00
|
|
|
})
|
|
|
|
})
|