]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/search/videos.ts
Better use of space and icons in plugins administration interface
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / search / videos.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as request from 'supertest'
4 import { VideosSearchQuery } from '../../models/search'
5 import { immutableAssign } from '../miscs/miscs'
6
7 function searchVideo (url: string, search: string) {
8 const path = '/api/v1/search/videos'
9
10 const query = { sort: '-publishedAt', search: search }
11 const req = request(url)
12 .get(path)
13 .query(query)
14 .set('Accept', 'application/json')
15
16 return req.expect(200)
17 .expect('Content-Type', /json/)
18 }
19
20 function 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
32 function searchVideoWithSort (url: string, search: string, sort: string) {
33 const path = '/api/v1/search/videos'
34
35 const query = { search, sort }
36
37 return request(url)
38 .get(path)
39 .query(query)
40 .set('Accept', 'application/json')
41 .expect(200)
42 .expect('Content-Type', /json/)
43 }
44
45 function 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
58 export {
59 searchVideo,
60 advancedVideosSearch,
61 searchVideoWithToken,
62 searchVideoWithSort
63 }