]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/search.ts
Move utils to /shared
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / search.ts
CommitLineData
d525fc39
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
9639bd17 5import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../../../shared/utils'
6import {
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination
10} from '../../../../shared/utils/requests/check-api-params'
d525fc39
C
11
12describe('Test videos API validator', function () {
d525fc39
C
13 let server: ServerInfo
14
15 // ---------------------------------------------------------------
16
17 before(async function () {
18 this.timeout(30000)
19
20 await flushTests()
21
22 server = await runServer(1)
23 })
24
25 describe('When searching videos', function () {
f5b0af50
C
26 const path = '/api/v1/search/videos/'
27
d525fc39
C
28 const query = {
29 search: 'coucou'
30 }
31
32 it('Should fail with a bad start pagination', async function () {
33 await checkBadStartPagination(server.url, path, null, query)
34 })
35
36 it('Should fail with a bad count pagination', async function () {
37 await checkBadCountPagination(server.url, path, null, query)
38 })
39
40 it('Should fail with an incorrect sort', async function () {
41 await checkBadSortPagination(server.url, path, null, query)
42 })
43
44 it('Should success with the correct parameters', async function () {
45 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
46 })
47
48 it('Should fail with an invalid category', async function () {
49 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
50 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
51
52 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
53 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
54 })
55
56 it('Should succeed with a valid category', async function () {
57 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
58 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
59
60 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
61 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
62 })
63
64 it('Should fail with an invalid licence', async function () {
65 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
66 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
67
68 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
69 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
70 })
71
72 it('Should succeed with a valid licence', async function () {
73 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
74 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
75
76 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
77 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
78 })
79
80 it('Should succeed with a valid language', async function () {
81 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
82 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
83
84 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
85 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
86 })
87
88 it('Should succeed with valid tags', async function () {
89 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
90 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
91
92 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
93 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
94
95 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
96 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })
97
98 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
99 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
100 })
101
102 it('Should fail with invalid durations', async function () {
103 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
104 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
105
106 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
107 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
108 })
109
110 it('Should fail with invalid dates', async function () {
111 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
112 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
113
114 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
115 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
116 })
117 })
118
f5b0af50
C
119 describe('When searching video channels', function () {
120 const path = '/api/v1/search/video-channels/'
121
122 const query = {
123 search: 'coucou'
124 }
125
126 it('Should fail with a bad start pagination', async function () {
127 await checkBadStartPagination(server.url, path, null, query)
128 })
129
130 it('Should fail with a bad count pagination', async function () {
131 await checkBadCountPagination(server.url, path, null, query)
132 })
133
134 it('Should fail with an incorrect sort', async function () {
135 await checkBadSortPagination(server.url, path, null, query)
136 })
137
138 it('Should success with the correct parameters', async function () {
139 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
140 })
141 })
142
d525fc39
C
143 after(async function () {
144 killallServers([ server ])
145
146 // Keep the logs if the test failed
147 if (this['ok']) {
148 await flushTests()
149 }
150 })
151})