aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/search.ts
blob: f8d0cd4ecea43664d03aa1a03872aee67394d2db (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'

import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils'
import {
  checkBadCountPagination,
  checkBadSortPagination,
  checkBadStartPagination
} from '../../../../shared/extra-utils/requests/check-api-params'

describe('Test videos API validator', function () {
  let server: ServerInfo

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

  before(async function () {
    this.timeout(30000)

    server = await flushAndRunServer(1)
  })

  describe('When searching videos', function () {
    const path = '/api/v1/search/videos/'

    const query = {
      search: 'coucou'
    }

    it('Should fail with a bad start pagination', async function () {
      await checkBadStartPagination(server.url, path, null, query)
    })

    it('Should fail with a bad count pagination', async function () {
      await checkBadCountPagination(server.url, path, null, query)
    })

    it('Should fail with an incorrect sort', async function () {
      await checkBadSortPagination(server.url, path, null, query)
    })

    it('Should success with the correct parameters', async function () {
      await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
    })

    it('Should fail with an invalid category', async function () {
      const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })

      const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
    })

    it('Should succeed with a valid category', async function () {
      const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })

      const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
    })

    it('Should fail with an invalid licence', async function () {
      const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })

      const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
    })

    it('Should succeed with a valid licence', async function () {
      const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })

      const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
    })

    it('Should succeed with a valid language', async function () {
      const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })

      const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
    })

    it('Should succeed with valid tags', async function () {
      const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })

      const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })

      const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
      await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })

      const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
      await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
    })

    it('Should fail with invalid durations', async function () {
      const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })

      const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
    })

    it('Should fail with invalid dates', async function () {
      const customQuery1 = immutableAssign(query, { startDate: 'hello' })
      await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })

      const customQuery2 = immutableAssign(query, { endDate: 'hello' })
      await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })

      const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
      await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 })

      const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
      await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 })
    })
  })

  describe('When searching video channels', function () {
    const path = '/api/v1/search/video-channels/'

    const query = {
      search: 'coucou'
    }

    it('Should fail with a bad start pagination', async function () {
      await checkBadStartPagination(server.url, path, null, query)
    })

    it('Should fail with a bad count pagination', async function () {
      await checkBadCountPagination(server.url, path, null, query)
    })

    it('Should fail with an incorrect sort', async function () {
      await checkBadSortPagination(server.url, path, null, query)
    })

    it('Should success with the correct parameters', async function () {
      await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
    })
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})