1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as request from 'supertest'
4 import { VideosSearchQuery } from '../../models/search'
5 import { immutableAssign } from '../miscs/miscs'
6 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
8 function searchVideo (url: string, search: string, sort = '-publishedAt') {
9 const path = '/api/v1/search/videos'
11 const query = { sort, search: search }
12 const req = request(url)
15 .set('Accept', 'application/json')
17 return req.expect(HttpStatusCode.OK_200)
18 .expect('Content-Type', /json/)
21 function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
22 const path = '/api/v1/search/videos'
23 const req = request(url)
25 .set('Authorization', 'Bearer ' + token)
26 .query(immutableAssign(query, { sort: '-publishedAt', search }))
27 .set('Accept', 'application/json')
29 return req.expect(HttpStatusCode.OK_200)
30 .expect('Content-Type', /json/)
33 function searchVideoWithSort (url: string, search: string, sort: string) {
34 const path = '/api/v1/search/videos'
36 const query = { search, sort }
41 .set('Accept', 'application/json')
42 .expect(HttpStatusCode.OK_200)
43 .expect('Content-Type', /json/)
46 function advancedVideosSearch (url: string, options: VideosSearchQuery) {
47 const path = '/api/v1/search/videos'
52 .set('Accept', 'application/json')
53 .expect(HttpStatusCode.OK_200)
54 .expect('Content-Type', /json/)
57 // ---------------------------------------------------------------------------