]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/search/videos.ts
Merge branch 'release/2.3.0' into develop
[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'
d525fc39
C
6
7function searchVideo (url: string, search: string) {
8 const path = '/api/v1/search/videos'
60919831
C
9
10 const query = { sort: '-publishedAt', search: search }
d525fc39
C
11 const req = request(url)
12 .get(path)
60919831 13 .query(query)
d525fc39
C
14 .set('Accept', 'application/json')
15
16 return req.expect(200)
17 .expect('Content-Type', /json/)
18}
19
20function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
21 const path = '/api/v1/search/videos'
22 const req = request(url)
23 .get(path)
24 .set('Authorization', 'Bearer ' + token)
25 .query(immutableAssign(query, { sort: '-publishedAt', search }))
26 .set('Accept', 'application/json')
27
28 return req.expect(200)
29 .expect('Content-Type', /json/)
30}
31
d525fc39
C
32function searchVideoWithSort (url: string, search: string, sort: string) {
33 const path = '/api/v1/search/videos'
34
60919831
C
35 const query = { search, sort }
36
d525fc39
C
37 return request(url)
38 .get(path)
60919831 39 .query(query)
d525fc39
C
40 .set('Accept', 'application/json')
41 .expect(200)
42 .expect('Content-Type', /json/)
43}
44
45function advancedVideosSearch (url: string, options: VideosSearchQuery) {
46 const path = '/api/v1/search/videos'
47
48 return request(url)
49 .get(path)
50 .query(options)
51 .set('Accept', 'application/json')
52 .expect(200)
53 .expect('Content-Type', /json/)
54}
55
56// ---------------------------------------------------------------------------
57
58export {
59 searchVideo,
60 advancedVideosSearch,
61 searchVideoWithToken,
d525fc39
C
62 searchVideoWithSort
63}