]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/search/videos.ts
Upgrade server dependencies
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / search / videos.ts
CommitLineData
d525fc39
C
1/* tslint:disable:no-unused-expression */
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
32function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
33 const path = '/api/v1/search/videos'
34
60919831
C
35 const query = {
36 start,
37 search,
38 count
39 }
40
d525fc39
C
41 const req = request(url)
42 .get(path)
60919831 43 .query(query)
d525fc39
C
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
52function searchVideoWithSort (url: string, search: string, sort: string) {
53 const path = '/api/v1/search/videos'
54
60919831
C
55 const query = { search, sort }
56
d525fc39
C
57 return request(url)
58 .get(path)
60919831 59 .query(query)
d525fc39
C
60 .set('Accept', 'application/json')
61 .expect(200)
62 .expect('Content-Type', /json/)
63}
64
65function 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
78export {
79 searchVideo,
80 advancedVideosSearch,
81 searchVideoWithToken,
82 searchVideoWithPagination,
83 searchVideoWithSort
84}