2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-12-17 11:58:15 +01:00
|
|
|
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
|
2021-07-16 14:27:30 +02:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2021-12-17 11:58:15 +01:00
|
|
|
import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) {
|
2021-07-16 09:04:35 +02:00
|
|
|
return server.config.updateCustomSubConfig({
|
2021-07-07 11:51:09 +02:00
|
|
|
newConfig: {
|
|
|
|
search: {
|
|
|
|
searchIndex: {
|
|
|
|
enabled,
|
|
|
|
disableLocalSearch
|
|
|
|
}
|
2020-06-09 16:39:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-20 14:35:18 +02:00
|
|
|
describe('Test videos API validator', function () {
|
2021-07-16 09:47:51 +02:00
|
|
|
let server: PeerTubeServer
|
2018-07-20 14:35:18 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
server = await createSingleServer(1)
|
2020-06-09 16:39:45 +02:00
|
|
|
await setAccessTokensToServers([ server ])
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When searching videos', function () {
|
2018-08-24 11:04:02 +02:00
|
|
|
const path = '/api/v1/search/videos/'
|
|
|
|
|
2018-07-20 14:35:18 +02: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)
|
|
|
|
})
|
|
|
|
|
2021-07-28 13:40:26 +02:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid category', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, categoryOneOf: 'a' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with a valid category', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, categoryOneOf: 1 }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid licence', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, licenceOneOf: 'a' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with a valid licence', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, licenceOneOf: 1 }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with a valid language', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, languageOneOf: 'fr' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with valid tags', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, tagsOneOf: 'tag1' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery4 = { ...query, tagsAllOf: 'tag1' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.OK_200 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with invalid durations', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, durationMin: 'hello' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, durationMax: 'hello' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with invalid dates', async function () {
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery1 = { ...query, startDate: 'hello' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery2 = { ...query, endDate: 'hello' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-11-27 18:57:02 +01:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-11-27 18:57:02 +01:00
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
2021-07-28 13:40:26 +02:00
|
|
|
|
|
|
|
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 })
|
|
|
|
})
|
2021-07-28 16:40:21 +02:00
|
|
|
|
|
|
|
it('Should fail with invalid uuids', async function () {
|
|
|
|
const customQuery = { ...query, uuids: [ '6565', 'dfd70b83-639f-4980-94af-304a56ab4b35' ] }
|
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with valid uuids', async function () {
|
|
|
|
const customQuery = { ...query, uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] }
|
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
|
|
|
|
})
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
|
2021-06-17 16:02:38 +02:00
|
|
|
describe('When searching video playlists', function () {
|
|
|
|
const path = '/api/v1/search/video-playlists/'
|
|
|
|
|
|
|
|
const query = {
|
2021-07-28 13:40:26 +02:00
|
|
|
search: 'coucou',
|
|
|
|
host: 'example.com'
|
2021-06-17 16:02:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2021-07-28 13:40:26 +02:00
|
|
|
it('Should fail with an invalid host', async function () {
|
|
|
|
await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
2021-07-28 16:40:21 +02:00
|
|
|
it('Should fail with invalid uuids', async function () {
|
|
|
|
const customQuery = { ...query, uuids: [ '6565', 'dfd70b83-639f-4980-94af-304a56ab4b35' ] }
|
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
2021-07-28 13:40:26 +02:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
|
2021-06-17 16:02:38 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-24 11:04:02 +02:00
|
|
|
describe('When searching video channels', function () {
|
|
|
|
const path = '/api/v1/search/video-channels/'
|
|
|
|
|
|
|
|
const query = {
|
2021-07-28 13:40:26 +02:00
|
|
|
search: 'coucou',
|
|
|
|
host: 'example.com'
|
2018-08-24 11:04:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2021-07-28 13:40:26 +02:00
|
|
|
it('Should fail with an invalid host', async function () {
|
|
|
|
await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
2021-07-29 10:27:24 +02:00
|
|
|
it('Should fail with invalid handles', async function () {
|
|
|
|
await makeGetRequest({ url: server.url, path, query: { ...query, handles: [ '' ] }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
2021-07-28 13:40:26 +02:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
|
2018-08-24 11:04:02 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-06-09 16:39:45 +02:00
|
|
|
describe('Search target', function () {
|
|
|
|
|
|
|
|
it('Should fail/succeed depending on the search target', async function () {
|
|
|
|
const query = { search: 'coucou' }
|
|
|
|
const paths = [
|
2021-06-17 16:02:38 +02:00
|
|
|
'/api/v1/search/video-playlists/',
|
2020-06-09 16:39:45 +02:00
|
|
|
'/api/v1/search/video-channels/',
|
|
|
|
'/api/v1/search/videos/'
|
|
|
|
]
|
|
|
|
|
|
|
|
for (const path of paths) {
|
|
|
|
{
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery = { ...query, searchTarget: 'hello' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2020-06-09 16:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery = { ...query, searchTarget: undefined }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
|
2020-06-09 16:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery = { ...query, searchTarget: 'local' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
|
2020-06-09 16:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery = { ...query, searchTarget: 'search-index' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2020-06-09 16:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateSearchIndex(server, true, true)
|
|
|
|
|
|
|
|
{
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery = { ...query, searchTarget: 'search-index' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
|
2020-06-09 16:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateSearchIndex(server, true, false)
|
|
|
|
|
|
|
|
{
|
2021-07-13 09:43:59 +02:00
|
|
|
const customQuery = { ...query, searchTarget: 'local' }
|
2021-07-16 10:42:24 +02:00
|
|
|
await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
|
2020-06-09 16:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateSearchIndex(server, false, false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 15:10:37 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
2018-07-20 14:35:18 +02:00
|
|
|
})
|
|
|
|
})
|