]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/search/videos.ts
Upgrade server dependencies
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / search / videos.ts
1 /* tslint:disable:no-unused-expression */
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 searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
33 const path = '/api/v1/search/videos'
34
35 const query = {
36 start,
37 search,
38 count
39 }
40
41 const req = request(url)
42 .get(path)
43 .query(query)
44
45 if (sort) req.query({ sort })
46
47 return req.set('Accept', 'application/json')
48 .expect(200)
49 .expect('Content-Type', /json/)
50 }
51
52 function searchVideoWithSort (url: string, search: string, sort: string) {
53 const path = '/api/v1/search/videos'
54
55 const query = { search, sort }
56
57 return request(url)
58 .get(path)
59 .query(query)
60 .set('Accept', 'application/json')
61 .expect(200)
62 .expect('Content-Type', /json/)
63 }
64
65 function advancedVideosSearch (url: string, options: VideosSearchQuery) {
66 const path = '/api/v1/search/videos'
67
68 return request(url)
69 .get(path)
70 .query(options)
71 .set('Accept', 'application/json')
72 .expect(200)
73 .expect('Content-Type', /json/)
74 }
75
76 // ---------------------------------------------------------------------------
77
78 export {
79 searchVideo,
80 advancedVideosSearch,
81 searchVideoWithToken,
82 searchVideoWithPagination,
83 searchVideoWithSort
84 }