Skip to content

Commit e770f02

Browse files
committed
Fix unit tests
1 parent 2229022 commit e770f02

6 files changed

Lines changed: 141 additions & 4 deletions

File tree

src/main/kotlin/api/DocumentenApiRoutes.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ fun Application.documentenApiModule(useAuthentication: Boolean = true, openZaakC
9191
routing {
9292
if (useAuthentication) {
9393
authenticate("auth-jwt", "auth-zgw", strategy = AuthenticationStrategy.FirstSuccessful) {
94-
withScopes {
95-
documentenApiRoutes(openZaakConfig)
96-
}
94+
documentenApiRoutes(openZaakConfig)
9795
}
9896
} else {
9997
documentenApiRoutes(openZaakConfig)

src/test/kotlin/api/routes/EnkelvoudigInformatieObjectenRoutesTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
3333
@Test
3434
fun `test POST enkelvoudiginformatieobjecten with taal and bestandsnaam`() = testApplication {
3535
application { setup() }
36+
val client = authenticatedClient()
3637

3738
val request = generateTestDocument(taal = "dut", bestandsnaam = "test.pdf")
3839
val response = client.post("$API_BASE/$RESOURCE_SEGMENT") {
@@ -61,6 +62,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
6162
@Test
6263
fun `test GET list includes url in each result`() = testApplication {
6364
application { setup() }
65+
val client = authenticatedClient()
6466

6567
// Create two documents
6668
val req1 = generateTestDocument(taal = "dut", bestandsnaam = "doc1.pdf")
@@ -99,6 +101,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
99101
@Test
100102
fun `test GET enkelvoudiginformatieobjecten with invalid UUID`() = testApplication {
101103
application { setup() }
104+
val client = authenticatedClient()
102105

103106
val response = client.get("$API_BASE/$RESOURCE_SEGMENT/invalid-uuid")
104107

@@ -113,6 +116,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
113116
@Test
114117
fun `test GET enkelvoudiginformatieobjecten with missing UUID parameter`() = testApplication {
115118
application { setup() }
119+
val client = authenticatedClient()
116120

117121
val response = client.get("$API_BASE/$RESOURCE_SEGMENT/")
118122

@@ -122,6 +126,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
122126
@Test
123127
fun `test GET enkelvoudiginformatieobjecten with valid UUID after creation`() = testApplication {
124128
application { setup() }
129+
val client = authenticatedClient()
125130

126131
val request = generateTestDocument(taal = "dut", bestandsnaam = "test.pdf")
127132
val postResponse = client.post("$API_BASE/$RESOURCE_SEGMENT") {
@@ -146,6 +151,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
146151
@Test
147152
fun `HEAD enkelvoudiginformatieobjecten returns 200 for existing resource`() = testApplication {
148153
application { setup() }
154+
val client = authenticatedClient()
149155

150156
// create
151157
val created = client.post("$API_BASE/$RESOURCE_SEGMENT") {
@@ -164,6 +170,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
164170
@Test
165171
fun `HEAD enkelvoudiginformatieobjecten returns 404 for missing resource`() = testApplication {
166172
application { setup() }
173+
val client = authenticatedClient()
167174

168175
val resp = client.head("$API_BASE/$RESOURCE_SEGMENT/${UUID.randomUUID()}")
169176
assertEquals(HttpStatusCode.NotFound, resp.status)
@@ -172,6 +179,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
172179
@Test
173180
fun `HEAD enkelvoudiginformatieobjecten returns 400 for invalid UUID`() = testApplication {
174181
application { setup() }
182+
val client = authenticatedClient()
175183

176184
val resp = client.head("$API_BASE/$RESOURCE_SEGMENT/not-a-uuid")
177185
assertEquals(HttpStatusCode.BadRequest, resp.status)
@@ -180,6 +188,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
180188
@Test
181189
fun `DELETE enkelvoudiginformatieobjecten returns 204 and removes resource`() = testApplication {
182190
application { setup() }
191+
val client = authenticatedClient()
183192

184193
// create
185194
val created = client.post("$API_BASE/$RESOURCE_SEGMENT") {
@@ -201,6 +210,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
201210
@Test
202211
fun `DELETE enkelvoudiginformatieobjecten returns 404 for missing resource`() = testApplication {
203212
application { setup() }
213+
val client = authenticatedClient()
204214

205215
val del = client.delete("$API_BASE/$RESOURCE_SEGMENT/${UUID.randomUUID()}")
206216
assertEquals(HttpStatusCode.NotFound, del.status)
@@ -209,6 +219,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
209219
@Test
210220
fun `DELETE enkelvoudiginformatieobjecten returns 400 for invalid UUID`() = testApplication {
211221
application { setup() }
222+
val client = authenticatedClient()
212223

213224
val del = client.delete("$API_BASE/$RESOURCE_SEGMENT/not-a-uuid")
214225
assertEquals(HttpStatusCode.BadRequest, del.status)
@@ -217,6 +228,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
217228
@Test
218229
fun `DELETE enkelvoudiginformatieobjecten returns 409 for locked resource`() = testApplication {
219230
application { setup() }
231+
val client = authenticatedClient()
220232

221233
// create
222234
val created = client.post("$API_BASE/$RESOURCE_SEGMENT") {
@@ -243,6 +255,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
243255
@Test
244256
fun `test GET enkelvoudiginformatieobjecten with valid UUID returns JSON UTF-8`() = testApplication {
245257
application { setup() }
258+
val client = authenticatedClient()
246259

247260
val request = generateTestDocument(taal = "dut", bestandsnaam = "test.pdf")
248261
val postResponse = client.post("$API_BASE/$RESOURCE_SEGMENT") {
@@ -267,6 +280,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
267280
@Test
268281
fun `lock returns 200 with lock token, second lock returns 409`() = testApplication {
269282
application { setup() }
283+
val client = authenticatedClient()
270284

271285
// Create an object first
272286
val createReq = generateTestDocument()
@@ -293,6 +307,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
293307
@Test
294308
fun `unlock with correct token returns 204 and subsequent unlock returns 409`() = testApplication {
295309
application { setup() }
310+
val client = authenticatedClient()
296311

297312
// Create
298313
val createReq = generateTestDocument()
@@ -327,6 +342,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
327342
@Test
328343
fun `unlock with invalid token returns 409 Conflict`() = testApplication {
329344
application { setup() }
345+
val client = authenticatedClient()
330346

331347
// Create and lock
332348
val createReq = generateTestDocument()
@@ -350,6 +366,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
350366
@Test
351367
fun `lock and unlock with unknown UUID return 404`() = testApplication {
352368
application { setup() }
369+
val client = authenticatedClient()
353370

354371
val unknownId = "00000000-0000-0000-0000-000000000001"
355372

@@ -369,6 +386,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
369386
@Test
370387
fun `lock and unlock with invalid UUID return 400`() = testApplication {
371388
application { setup() }
389+
val client = authenticatedClient()
372390

373391
val invalidId = "not-a-uuid"
374392

@@ -385,6 +403,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
385403
@Test
386404
fun `test zoek endpoint with uuid_In`() = testApplication {
387405
application { setup() }
406+
val client = authenticatedClient()
388407

389408
// Create two documents
390409
val req1 = generateTestDocument(identificatie = "DOC-001")
@@ -430,6 +449,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
430449
@Test
431450
fun `test GET list paging`() = testApplication {
432451
application { setup() }
452+
val client = authenticatedClient()
433453

434454
// Create 12 documents
435455
for (i in 1..12) {
@@ -473,6 +493,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
473493
@Test
474494
fun `test zoek endpoint paging`() = testApplication {
475495
application { setup() }
496+
val client = authenticatedClient()
476497

477498
val createdIds = mutableListOf<String>()
478499
// Create 12 documents
@@ -524,6 +545,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
524545
@Test
525546
fun `test GET list paging with custom pageSize`() = testApplication {
526547
application { setup() }
548+
val client = authenticatedClient()
527549

528550
// Create 12 documents
529551
for (i in 1..12) {
@@ -561,6 +583,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
561583
@Test
562584
fun `test GET list paging preserves filters`() = testApplication {
563585
application { setup() }
586+
val client = authenticatedClient()
564587

565588
val bronOrganisatie = "999999999"
566589
// Create 12 documents with specific bronorganisatie
@@ -588,6 +611,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
588611
@Test
589612
fun `test GET list with experimental object filters`() = testApplication {
590613
application { setup() }
614+
val client = authenticatedClient()
591615

592616
// Create an EIO
593617
val resEio = client.post("$API_BASE/$RESOURCE_SEGMENT") {
@@ -627,6 +651,7 @@ class EnkelvoudigInformatieObjectenRoutesTest : TestBase("eio_routes") {
627651
@Test
628652
fun `test POST zoek with experimental object filters`() = testApplication {
629653
application { setup() }
654+
val client = authenticatedClient()
630655

631656
// Create an EIO
632657
val resEio = client.post("$API_BASE/$RESOURCE_SEGMENT") {

src/test/kotlin/api/routes/GlobalExceptionHandlerTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class GlobalExceptionHandlerTest : TestBase("global_exception_test") {
2020
@Test
2121
fun `test malformed JSON returns ProblemDetailsResponse`() = testApplication {
2222
application { setup() }
23+
val client = authenticatedClient()
2324

2425
val malformedJson = "{ \"identificatie\": \"test\", \"bronorganisatie\": \"012345678\", " // Missing closing brace and other fields
2526

@@ -38,6 +39,7 @@ class GlobalExceptionHandlerTest : TestBase("global_exception_test") {
3839
@Test
3940
fun `test invalid enum value in JSON returns specific error message`() = testApplication {
4041
application { setup() }
42+
val client = authenticatedClient()
4143

4244
// OIO request with "ZAAK" instead of "zaak"
4345
val invalidJson = """
@@ -74,6 +76,7 @@ class GlobalExceptionHandlerTest : TestBase("global_exception_test") {
7476
}
7577
}
7678
}
79+
val client = authenticatedClient()
7780

7881
val response = client.get("/test-serialization-error")
7982

src/test/kotlin/api/routes/ObjectInformatieObjectenRoutesTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
5252
@Test
5353
fun `test list empty objectinformatieobjecten returns empty array`() = testApplication {
5454
application { setup() }
55+
val client = authenticatedClient()
5556

5657
val response = client.get("$API_BASE/$RESOURCE_SEGMENT")
5758

@@ -65,6 +66,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
6566
@Test
6667
fun `test create objectinformatieobject returns 201 with location header`() = testApplication {
6768
application { setup() }
69+
val client = authenticatedClient()
6870
val eioId = createTestEIO()
6971

7072
val request = CreateOIORequest(
@@ -94,6 +96,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
9496
@Test
9597
fun `test create duplicate objectinformatieobject returns 400`() = testApplication {
9698
application { setup() }
99+
val client = authenticatedClient()
97100
val eioId = createTestEIO()
98101

99102
val request = CreateOIORequest(
@@ -120,6 +123,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
120123
@Test
121124
fun `test get objectinformatieobject by id returns 200`() = testApplication {
122125
application { setup() }
126+
val client = authenticatedClient()
123127
val eioId = createTestEIO()
124128
val createRequest = CreateOIORequest(
125129
informatieobject = "$API_BASE/enkelvoudiginformatieobjecten/$eioId",
@@ -149,6 +153,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
149153
@Test
150154
fun `test get non-existent objectinformatieobject returns 404`() = testApplication {
151155
application { setup() }
156+
val client = authenticatedClient()
152157

153158
val nonExistentId = UUID.randomUUID()
154159
val response = client.get("$API_BASE/$RESOURCE_SEGMENT/$nonExistentId")
@@ -159,6 +164,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
159164
@Test
160165
fun `test head existing objectinformatieobject returns 200`() = testApplication {
161166
application { setup() }
167+
val client = authenticatedClient()
162168
val eioId = createTestEIO()
163169
val createRequest = CreateOIORequest(
164170
informatieobject = "$API_BASE/enkelvoudiginformatieobjecten/$eioId",
@@ -182,6 +188,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
182188
@Test
183189
fun `test head non-existent objectinformatieobject returns 404`() = testApplication {
184190
application { setup() }
191+
val client = authenticatedClient()
185192

186193
val nonExistentId = UUID.randomUUID()
187194
val response = client.head("$API_BASE/$RESOURCE_SEGMENT/$nonExistentId")
@@ -192,6 +199,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
192199
@Test
193200
fun `test delete objectinformatieobject returns 204`() = testApplication {
194201
application { setup() }
202+
val client = authenticatedClient()
195203
val eioId = createTestEIO()
196204
val createRequest = CreateOIORequest(
197205
informatieobject = "$API_BASE/enkelvoudiginformatieobjecten/$eioId",
@@ -218,6 +226,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
218226
@Test
219227
fun `test delete non-existent objectinformatieobject returns 404`() = testApplication {
220228
application { setup() }
229+
val client = authenticatedClient()
221230

222231
val nonExistentId = UUID.randomUUID()
223232
val response = client.delete("$API_BASE/$RESOURCE_SEGMENT/$nonExistentId")
@@ -228,6 +237,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
228237
@Test
229238
fun `test filter by informatieobject returns matching relations`() = testApplication {
230239
application { setup() }
240+
val client = authenticatedClient()
231241
val sharedEioId = createTestEIO()
232242
val sharedEioUrl = "$API_BASE/enkelvoudiginformatieobjecten/$sharedEioId"
233243

@@ -274,6 +284,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
274284
@Test
275285
fun `test filter by object returns matching relations`() = testApplication {
276286
application { setup() }
287+
val client = authenticatedClient()
277288

278289
val sharedObjectUrl = "https://example.com/zaken/api/v1/zaken/87654321-4321-4321-4321-210987654321"
279290

@@ -321,6 +332,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
321332
@Test
322333
fun `test create objectinformatieobject with different object types`() = testApplication {
323334
application { setup() }
335+
val client = authenticatedClient()
324336

325337
// Create an actual EIO via API
326338
val eioId = createTestEIO()
@@ -364,6 +376,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
364376
@Test
365377
fun `test get objectinformatieobject with invalid uuid returns 400`() = testApplication {
366378
application { setup() }
379+
val client = authenticatedClient()
367380

368381
val response = client.get("$API_BASE/$RESOURCE_SEGMENT/not-a-uuid")
369382

@@ -375,6 +388,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
375388
@Test
376389
fun `test create objectinformatieobject with invalid json returns 400`() = testApplication {
377390
application { setup() }
391+
val client = authenticatedClient()
378392

379393
val response = client.post("$API_BASE/$RESOURCE_SEGMENT") {
380394
contentType(ContentType.Application.Json)
@@ -391,6 +405,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
391405
@Test
392406
fun `test head objectinformatieobject returns 200 for existing`() = testApplication {
393407
application { setup() }
408+
val client = authenticatedClient()
394409

395410
val eioId = createTestEIO()
396411
val request = CreateOIORequest(
@@ -413,6 +428,7 @@ class ObjectInformatieObjectenRoutesTest : TestBase("oio_routes") {
413428
@Test
414429
fun `test head objectinformatieobject returns 404 for non-existing`() = testApplication {
415430
application { setup() }
431+
val client = authenticatedClient()
416432

417433
val response = client.head("$API_BASE/$RESOURCE_SEGMENT/${UUID.randomUUID()}")
418434
assertEquals(HttpStatusCode.NotFound, response.status)

0 commit comments

Comments
 (0)