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