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