PeerTube/shared/extra-utils/search/videos.ts

65 lines
1.8 KiB
TypeScript
Raw Normal View History

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 * as request from 'supertest'
2018-10-29 12:06:09 -05:00
import { VideosSearchQuery } from '../../models/search'
2018-11-19 10:08:18 -06:00
import { immutableAssign } from '../miscs/miscs'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2018-07-20 07:35:18 -05:00
2020-12-10 09:38:12 -06:00
function searchVideo (url: string, search: string, sort = '-publishedAt') {
2018-07-20 07:35:18 -05:00
const path = '/api/v1/search/videos'
2019-06-06 08:39:11 -05:00
2020-12-10 09:38:12 -06:00
const query = { sort, search: search }
2018-07-20 07:35:18 -05:00
const req = request(url)
.get(path)
2019-06-06 08:39:11 -05:00
.query(query)
2018-07-20 07:35:18 -05:00
.set('Accept', 'application/json')
return req.expect(HttpStatusCode.OK_200)
2018-07-20 07:35:18 -05:00
.expect('Content-Type', /json/)
}
function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
const path = '/api/v1/search/videos'
const req = request(url)
.get(path)
.set('Authorization', 'Bearer ' + token)
.query(immutableAssign(query, { sort: '-publishedAt', search }))
.set('Accept', 'application/json')
return req.expect(HttpStatusCode.OK_200)
2018-07-20 07:35:18 -05:00
.expect('Content-Type', /json/)
}
function searchVideoWithSort (url: string, search: string, sort: string) {
const path = '/api/v1/search/videos'
2019-06-06 08:39:11 -05:00
const query = { search, sort }
2018-07-20 07:35:18 -05:00
return request(url)
.get(path)
2019-06-06 08:39:11 -05:00
.query(query)
2018-07-20 07:35:18 -05:00
.set('Accept', 'application/json')
.expect(HttpStatusCode.OK_200)
2018-07-20 07:35:18 -05:00
.expect('Content-Type', /json/)
}
function advancedVideosSearch (url: string, options: VideosSearchQuery) {
const path = '/api/v1/search/videos'
return request(url)
.get(path)
.query(options)
.set('Accept', 'application/json')
.expect(HttpStatusCode.OK_200)
2018-07-20 07:35:18 -05:00
.expect('Content-Type', /json/)
}
// ---------------------------------------------------------------------------
export {
searchVideo,
advancedVideosSearch,
searchVideoWithToken,
searchVideoWithSort
}