aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/search.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/search.ts')
-rw-r--r--server/tests/api/check-params/search.ts152
1 files changed, 75 insertions, 77 deletions
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index 20ad46cff..a3da54e1f 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -2,41 +2,39 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
5 cleanupTests, 8 cleanupTests,
6 flushAndRunServer, 9 createSingleServer,
7 immutableAssign,
8 makeGetRequest, 10 makeGetRequest,
9 ServerInfo, 11 PeerTubeServer,
10 updateCustomSubConfig,
11 setAccessTokensToServers 12 setAccessTokensToServers
12} from '../../../../shared/extra-utils' 13} from '@shared/extra-utils'
13import { 14import { HttpStatusCode } from '@shared/models'
14 checkBadCountPagination, 15
15 checkBadSortPagination, 16function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) {
16 checkBadStartPagination 17 return server.config.updateCustomSubConfig({
17} from '../../../../shared/extra-utils/requests/check-api-params' 18 newConfig: {
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 19 search: {
19 20 searchIndex: {
20function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { 21 enabled,
21 return updateCustomSubConfig(server.url, server.accessToken, { 22 disableLocalSearch
22 search: { 23 }
23 searchIndex: {
24 enabled,
25 disableLocalSearch
26 } 24 }
27 } 25 }
28 }) 26 })
29} 27}
30 28
31describe('Test videos API validator', function () { 29describe('Test videos API validator', function () {
32 let server: ServerInfo 30 let server: PeerTubeServer
33 31
34 // --------------------------------------------------------------- 32 // ---------------------------------------------------------------
35 33
36 before(async function () { 34 before(async function () {
37 this.timeout(30000) 35 this.timeout(30000)
38 36
39 server = await flushAndRunServer(1) 37 server = await createSingleServer(1)
40 await setAccessTokensToServers([ server ]) 38 await setAccessTokensToServers([ server ])
41 }) 39 })
42 40
@@ -60,83 +58,83 @@ describe('Test videos API validator', function () {
60 }) 58 })
61 59
62 it('Should success with the correct parameters', async function () { 60 it('Should success with the correct parameters', async function () {
63 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) 61 await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
64 }) 62 })
65 63
66 it('Should fail with an invalid category', async function () { 64 it('Should fail with an invalid category', async function () {
67 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) 65 const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] }
68 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 66 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
69 67
70 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) 68 const customQuery2 = { ...query, categoryOneOf: 'a' }
71 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 69 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
72 }) 70 })
73 71
74 it('Should succeed with a valid category', async function () { 72 it('Should succeed with a valid category', async function () {
75 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) 73 const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] }
76 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 74 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
77 75
78 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) 76 const customQuery2 = { ...query, categoryOneOf: 1 }
79 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 77 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
80 }) 78 })
81 79
82 it('Should fail with an invalid licence', async function () { 80 it('Should fail with an invalid licence', async function () {
83 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) 81 const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] }
84 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 82 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
85 83
86 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) 84 const customQuery2 = { ...query, licenceOneOf: 'a' }
87 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 85 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
88 }) 86 })
89 87
90 it('Should succeed with a valid licence', async function () { 88 it('Should succeed with a valid licence', async function () {
91 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) 89 const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] }
92 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 90 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
93 91
94 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) 92 const customQuery2 = { ...query, licenceOneOf: 1 }
95 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 93 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
96 }) 94 })
97 95
98 it('Should succeed with a valid language', async function () { 96 it('Should succeed with a valid language', async function () {
99 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) 97 const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] }
100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 98 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
101 99
102 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) 100 const customQuery2 = { ...query, languageOneOf: 'fr' }
103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 101 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
104 }) 102 })
105 103
106 it('Should succeed with valid tags', async function () { 104 it('Should succeed with valid tags', async function () {
107 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) 105 const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] }
108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 106 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
109 107
110 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) 108 const customQuery2 = { ...query, tagsOneOf: 'tag1' }
111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 109 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
112 110
113 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) 111 const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] }
114 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) 112 await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.OK_200 })
115 113
116 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) 114 const customQuery4 = { ...query, tagsAllOf: 'tag1' }
117 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) 115 await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.OK_200 })
118 }) 116 })
119 117
120 it('Should fail with invalid durations', async function () { 118 it('Should fail with invalid durations', async function () {
121 const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) 119 const customQuery1 = { ...query, durationMin: 'hello' }
122 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 120 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
123 121
124 const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) 122 const customQuery2 = { ...query, durationMax: 'hello' }
125 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 123 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
126 }) 124 })
127 125
128 it('Should fail with invalid dates', async function () { 126 it('Should fail with invalid dates', async function () {
129 const customQuery1 = immutableAssign(query, { startDate: 'hello' }) 127 const customQuery1 = { ...query, startDate: 'hello' }
130 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 128 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
131 129
132 const customQuery2 = immutableAssign(query, { endDate: 'hello' }) 130 const customQuery2 = { ...query, endDate: 'hello' }
133 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 131 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
134 132
135 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) 133 const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' }
136 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 134 await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
137 135
138 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) 136 const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' }
139 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 137 await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
140 }) 138 })
141 }) 139 })
142 140
@@ -160,7 +158,7 @@ describe('Test videos API validator', function () {
160 }) 158 })
161 159
162 it('Should success with the correct parameters', async function () { 160 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) 161 await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
164 }) 162 })
165 }) 163 })
166 164
@@ -184,7 +182,7 @@ describe('Test videos API validator', function () {
184 }) 182 })
185 183
186 it('Should success with the correct parameters', async function () { 184 it('Should success with the correct parameters', async function () {
187 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) 185 await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
188 }) 186 })
189 }) 187 })
190 188
@@ -202,42 +200,42 @@ describe('Test videos API validator', function () {
202 200
203 for (const path of paths) { 201 for (const path of paths) {
204 { 202 {
205 const customQuery = immutableAssign(query, { searchTarget: 'hello' }) 203 const customQuery = { ...query, searchTarget: 'hello' }
206 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 204 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
207 } 205 }
208 206
209 { 207 {
210 const customQuery = immutableAssign(query, { searchTarget: undefined }) 208 const customQuery = { ...query, searchTarget: undefined }
211 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 209 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
212 } 210 }
213 211
214 { 212 {
215 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 213 const customQuery = { ...query, searchTarget: 'local' }
216 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 214 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
217 } 215 }
218 216
219 { 217 {
220 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 218 const customQuery = { ...query, searchTarget: 'search-index' }
221 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 219 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
222 } 220 }
223 221
224 await updateSearchIndex(server, true, true) 222 await updateSearchIndex(server, true, true)
225 223
226 { 224 {
227 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 225 const customQuery = { ...query, searchTarget: 'local' }
228 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 226 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
229 } 227 }
230 228
231 { 229 {
232 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 230 const customQuery = { ...query, searchTarget: 'search-index' }
233 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 231 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
234 } 232 }
235 233
236 await updateSearchIndex(server, true, false) 234 await updateSearchIndex(server, true, false)
237 235
238 { 236 {
239 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 237 const customQuery = { ...query, searchTarget: 'local' }
240 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 238 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
241 } 239 }
242 240
243 await updateSearchIndex(server, false, false) 241 await updateSearchIndex(server, false, false)