2018-07-20 14:35:18 +02:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import * as request from 'supertest'
|
2018-10-29 18:06:09 +01:00
|
|
|
import { VideosSearchQuery } from '../../models/search'
|
2018-11-19 17:08:18 +01:00
|
|
|
import { immutableAssign } from '../miscs/miscs'
|
2018-07-20 14:35:18 +02:00
|
|
|
|
|
|
|
function searchVideo (url: string, search: string) {
|
|
|
|
const path = '/api/v1/search/videos'
|
2019-06-06 15:39:11 +02:00
|
|
|
|
|
|
|
const query = { sort: '-publishedAt', search: search }
|
2018-07-20 14:35:18 +02:00
|
|
|
const req = request(url)
|
|
|
|
.get(path)
|
2019-06-06 15:39:11 +02:00
|
|
|
.query(query)
|
2018-07-20 14:35:18 +02:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
|
|
|
|
return req.expect(200)
|
|
|
|
.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(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
|
|
|
|
const path = '/api/v1/search/videos'
|
|
|
|
|
2019-06-06 15:39:11 +02:00
|
|
|
const query = {
|
|
|
|
start,
|
|
|
|
search,
|
|
|
|
count
|
|
|
|
}
|
|
|
|
|
2018-07-20 14:35:18 +02:00
|
|
|
const req = request(url)
|
|
|
|
.get(path)
|
2019-06-06 15:39:11 +02:00
|
|
|
.query(query)
|
2018-07-20 14:35:18 +02:00
|
|
|
|
|
|
|
if (sort) req.query({ sort })
|
|
|
|
|
|
|
|
return req.set('Accept', 'application/json')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchVideoWithSort (url: string, search: string, sort: string) {
|
|
|
|
const path = '/api/v1/search/videos'
|
|
|
|
|
2019-06-06 15:39:11 +02:00
|
|
|
const query = { search, sort }
|
|
|
|
|
2018-07-20 14:35:18 +02:00
|
|
|
return request(url)
|
|
|
|
.get(path)
|
2019-06-06 15:39:11 +02:00
|
|
|
.query(query)
|
2018-07-20 14:35:18 +02:00
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect(200)
|
|
|
|
.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(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
searchVideo,
|
|
|
|
advancedVideosSearch,
|
|
|
|
searchVideoWithToken,
|
|
|
|
searchVideoWithPagination,
|
|
|
|
searchVideoWithSort
|
|
|
|
}
|