aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/search/videos.ts
blob: 3a0c10e4249deb31d0ea8a2369b0f9c5c16a26b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* tslint:disable:no-unused-expression */

import * as request from 'supertest'
import { VideosSearchQuery } from '../../../../shared/models/search'
import { immutableAssign } from '..'

function searchVideo (url: string, search: string) {
  const path = '/api/v1/search/videos'
  const req = request(url)
    .get(path)
    .query({ sort: '-publishedAt', search })
    .set('Accept', 'application/json')

  return req.expect(200)
            .expect('Content-Type', /json/)
}

function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
  const path = '/api/v1/search/videos'
  const req = request(url)
    .get(path)
    .set('Authorization', 'Bearer ' + token)
    .query(immutableAssign(query, { sort: '-publishedAt', search }))
    .set('Accept', 'application/json')

  return req.expect(200)
            .expect('Content-Type', /json/)
}

function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
  const path = '/api/v1/search/videos'

  const req = request(url)
    .get(path)
    .query({ start })
    .query({ search })
    .query({ count })

  if (sort) req.query({ sort })

  return req.set('Accept', 'application/json')
            .expect(200)
            .expect('Content-Type', /json/)
}

function searchVideoWithSort (url: string, search: string, sort: string) {
  const path = '/api/v1/search/videos'

  return request(url)
    .get(path)
    .query({ search })
    .query({ sort })
    .set('Accept', 'application/json')
    .expect(200)
    .expect('Content-Type', /json/)
}

function advancedVideosSearch (url: string, options: VideosSearchQuery) {
  const path = '/api/v1/search/videos'

  return request(url)
    .get(path)
    .query(options)
    .set('Accept', 'application/json')
    .expect(200)
    .expect('Content-Type', /json/)
}

// ---------------------------------------------------------------------------

export {
  searchVideo,
  advancedVideosSearch,
  searchVideoWithToken,
  searchVideoWithPagination,
  searchVideoWithSort
}