]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/search/videos.ts
Allow SSL database parameter (#4114)
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / search / videos.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
d525fc39
C
2
3import * as request from 'supertest'
d4681c00 4import { VideosSearchQuery } from '../../models/search'
d175a6f7 5import { immutableAssign } from '../miscs/miscs'
2d53be02 6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
d525fc39 7
34caef7f 8function searchVideo (url: string, search: string, sort = '-publishedAt') {
d525fc39 9 const path = '/api/v1/search/videos'
60919831 10
34caef7f 11 const query = { sort, search: search }
d525fc39
C
12 const req = request(url)
13 .get(path)
60919831 14 .query(query)
d525fc39
C
15 .set('Accept', 'application/json')
16
2d53be02 17 return req.expect(HttpStatusCode.OK_200)
d525fc39
C
18 .expect('Content-Type', /json/)
19}
20
21function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
22 const path = '/api/v1/search/videos'
23 const req = request(url)
24 .get(path)
25 .set('Authorization', 'Bearer ' + token)
26 .query(immutableAssign(query, { sort: '-publishedAt', search }))
27 .set('Accept', 'application/json')
28
2d53be02 29 return req.expect(HttpStatusCode.OK_200)
d525fc39
C
30 .expect('Content-Type', /json/)
31}
32
d525fc39
C
33function searchVideoWithSort (url: string, search: string, sort: string) {
34 const path = '/api/v1/search/videos'
35
60919831
C
36 const query = { search, sort }
37
d525fc39
C
38 return request(url)
39 .get(path)
60919831 40 .query(query)
d525fc39 41 .set('Accept', 'application/json')
2d53be02 42 .expect(HttpStatusCode.OK_200)
d525fc39
C
43 .expect('Content-Type', /json/)
44}
45
46function advancedVideosSearch (url: string, options: VideosSearchQuery) {
47 const path = '/api/v1/search/videos'
48
49 return request(url)
50 .get(path)
51 .query(options)
52 .set('Accept', 'application/json')
2d53be02 53 .expect(HttpStatusCode.OK_200)
d525fc39
C
54 .expect('Content-Type', /json/)
55}
56
57// ---------------------------------------------------------------------------
58
59export {
60 searchVideo,
61 advancedVideosSearch,
62 searchVideoWithToken,
d525fc39
C
63 searchVideoWithSort
64}