]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
d525fc39 C |
2 | |
3 | import * as request from 'supertest' | |
d4681c00 | 4 | import { VideosSearchQuery } from '../../models/search' |
d175a6f7 | 5 | import { immutableAssign } from '../miscs/miscs' |
2d53be02 | 6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
d525fc39 C |
7 | |
8 | function searchVideo (url: string, search: string) { | |
9 | const path = '/api/v1/search/videos' | |
60919831 C |
10 | |
11 | const query = { sort: '-publishedAt', 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 | ||
21 | function 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 |
33 | function 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 | ||
46 | function 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 | ||
59 | export { | |
60 | searchVideo, | |
61 | advancedVideosSearch, | |
62 | searchVideoWithToken, | |
d525fc39 C |
63 | searchVideoWithSort |
64 | } |