]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/search.ts
Add notification on new instance follower (server side)
[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 })
31d065cc
AM
116
117 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
118 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 })
119
120 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
121 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 })
d525fc39
C
122 })
123 })
124
f5b0af50
C
125 describe('When searching video channels', function () {
126 const path = '/api/v1/search/video-channels/'
127
128 const query = {
129 search: 'coucou'
130 }
131
132 it('Should fail with a bad start pagination', async function () {
133 await checkBadStartPagination(server.url, path, null, query)
134 })
135
136 it('Should fail with a bad count pagination', async function () {
137 await checkBadCountPagination(server.url, path, null, query)
138 })
139
140 it('Should fail with an incorrect sort', async function () {
141 await checkBadSortPagination(server.url, path, null, query)
142 })
143
144 it('Should success with the correct parameters', async function () {
145 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
146 })
147 })
148
d525fc39
C
149 after(async function () {
150 killallServers([ server ])
151
152 // Keep the logs if the test failed
153 if (this['ok']) {
154 await flushTests()
155 }
156 })
157})