aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/search.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/tests/api/check-params/search.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/tests/api/check-params/search.ts')
-rw-r--r--server/tests/api/check-params/search.ts59
1 files changed, 30 insertions, 29 deletions
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index 1a8a7235e..8378c3a89 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -15,6 +15,7 @@ import {
15 checkBadSortPagination, 15 checkBadSortPagination,
16 checkBadStartPagination 16 checkBadStartPagination
17} from '../../../../shared/extra-utils/requests/check-api-params' 17} from '../../../../shared/extra-utils/requests/check-api-params'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { 20function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) {
20 return updateCustomSubConfig(server.url, server.accessToken, { 21 return updateCustomSubConfig(server.url, server.accessToken, {
@@ -59,83 +60,83 @@ describe('Test videos API validator', function () {
59 }) 60 })
60 61
61 it('Should success with the correct parameters', async function () { 62 it('Should success with the correct parameters', async function () {
62 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) 63 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
63 }) 64 })
64 65
65 it('Should fail with an invalid category', async function () { 66 it('Should fail with an invalid category', async function () {
66 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) 67 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
67 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 68 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
68 69
69 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) 70 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
70 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 71 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
71 }) 72 })
72 73
73 it('Should succeed with a valid category', async function () { 74 it('Should succeed with a valid category', async function () {
74 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) 75 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
75 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 76 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
76 77
77 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) 78 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
78 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 79 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
79 }) 80 })
80 81
81 it('Should fail with an invalid licence', async function () { 82 it('Should fail with an invalid licence', async function () {
82 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) 83 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
83 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 84 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
84 85
85 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) 86 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
86 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 87 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
87 }) 88 })
88 89
89 it('Should succeed with a valid licence', async function () { 90 it('Should succeed with a valid licence', async function () {
90 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) 91 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
91 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 92 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
92 93
93 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) 94 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
94 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 95 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
95 }) 96 })
96 97
97 it('Should succeed with a valid language', async function () { 98 it('Should succeed with a valid language', async function () {
98 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) 99 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
99 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
100 101
101 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) 102 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
102 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
103 }) 104 })
104 105
105 it('Should succeed with valid tags', async function () { 106 it('Should succeed with valid tags', async function () {
106 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) 107 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
107 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
108 109
109 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) 110 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
110 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
111 112
112 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) 113 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
113 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 }) 114 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
114 115
115 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) 116 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
116 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 }) 117 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
117 }) 118 })
118 119
119 it('Should fail with invalid durations', async function () { 120 it('Should fail with invalid durations', async function () {
120 const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) 121 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
121 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 122 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
122 123
123 const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) 124 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
124 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 125 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
125 }) 126 })
126 127
127 it('Should fail with invalid dates', async function () { 128 it('Should fail with invalid dates', async function () {
128 const customQuery1 = immutableAssign(query, { startDate: 'hello' }) 129 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
129 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 130 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
130 131
131 const customQuery2 = immutableAssign(query, { endDate: 'hello' }) 132 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
132 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 133 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
133 134
134 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) 135 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
135 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 }) 136 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
136 137
137 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) 138 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
138 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 }) 139 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
139 }) 140 })
140 }) 141 })
141 142
@@ -159,7 +160,7 @@ describe('Test videos API validator', function () {
159 }) 160 })
160 161
161 it('Should success with the correct parameters', async function () { 162 it('Should success with the correct parameters', async function () {
162 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) 163 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
163 }) 164 })
164 }) 165 })
165 166
@@ -177,41 +178,41 @@ describe('Test videos API validator', function () {
177 for (const path of paths) { 178 for (const path of paths) {
178 { 179 {
179 const customQuery = immutableAssign(query, { searchTarget: 'hello' }) 180 const customQuery = immutableAssign(query, { searchTarget: 'hello' })
180 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 181 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
181 } 182 }
182 183
183 { 184 {
184 const customQuery = immutableAssign(query, { searchTarget: undefined }) 185 const customQuery = immutableAssign(query, { searchTarget: undefined })
185 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 186 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
186 } 187 }
187 188
188 { 189 {
189 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 190 const customQuery = immutableAssign(query, { searchTarget: 'local' })
190 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 191 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
191 } 192 }
192 193
193 { 194 {
194 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 195 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
195 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 196 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
196 } 197 }
197 198
198 await updateSearchIndex(server, true, true) 199 await updateSearchIndex(server, true, true)
199 200
200 { 201 {
201 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 202 const customQuery = immutableAssign(query, { searchTarget: 'local' })
202 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 203 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
203 } 204 }
204 205
205 { 206 {
206 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 207 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
207 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 208 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
208 } 209 }
209 210
210 await updateSearchIndex(server, true, false) 211 await updateSearchIndex(server, true, false)
211 212
212 { 213 {
213 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 214 const customQuery = immutableAssign(query, { searchTarget: 'local' })
214 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 215 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
215 } 216 }
216 217
217 await updateSearchIndex(server, false, false) 218 await updateSearchIndex(server, false, false)