Skip to content

Commit

Permalink
refactor: Migrate POST /admin/lists and `POST /admin/lists/<parentL…
Browse files Browse the repository at this point in the history
…istIri>` to Tapir (DEV-1589) (#3018)
  • Loading branch information
seakayone authored Feb 5, 2024
1 parent 569a6c1 commit 63fe560
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 814 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
response.status should be(StatusCodes.Forbidden)
}

"return a BadRequestException during list creation when payload is not correct" in {
// no project IRI
"return a BadRequestException during list creation when request does not contain a projectIri" in {
//
val params01 =
s"""
|{
Expand All @@ -306,11 +306,15 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
|}
""".stripMargin

val request01 = Post(baseApiUrl + s"/admin/lists", HttpEntity(ContentTypes.`application/json`, params01))
val request01 =
Post(baseApiUrl + s"/admin/lists", HttpEntity(ContentTypes.`application/json`, params01)) ~> addCredentials(
anythingAdminUserCreds.basicHttpCredentials
)
val response01: HttpResponse = singleAwaitingRequest(request01)
response01.status should be(StatusCodes.BadRequest)
}

// invalid project IRI
"return a BadRequestException during list creation when request has invalid project IRI" in {
val params02 =
s"""
|{
Expand All @@ -320,11 +324,15 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
|}
""".stripMargin

val request02 = Post(baseApiUrl + s"/admin/lists", HttpEntity(ContentTypes.`application/json`, params02))
val request02 =
Post(baseApiUrl + s"/admin/lists", HttpEntity(ContentTypes.`application/json`, params02)) ~> addCredentials(
anythingAdminUserCreds.basicHttpCredentials
)
val response02: HttpResponse = singleAwaitingRequest(request02)
response02.status should be(StatusCodes.BadRequest)
}

// missing label
"return a BadRequestException during list creation when request has a missing label" in {
val params03 =
s"""
|{
Expand All @@ -334,7 +342,10 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
|}
""".stripMargin

val request03 = Post(baseApiUrl + s"/admin/lists", HttpEntity(ContentTypes.`application/json`, params03))
val request03 =
Post(baseApiUrl + s"/admin/lists", HttpEntity(ContentTypes.`application/json`, params03)) ~> addCredentials(
anythingAdminUserCreds.basicHttpCredentials
)
val response03: HttpResponse = singleAwaitingRequest(request03)
response03.status should be(StatusCodes.BadRequest)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ package org.knora.webapi.messages.admin.responder.listsmessages

import spray.json.*

import dsp.errors.BadRequestException
import dsp.valueobjects.Iri.*
import org.knora.webapi.CoreSpec
import org.knora.webapi.messages.store.triplestoremessages.StringLiteralSequenceV2
import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2
import org.knora.webapi.sharedtestdata.SharedListsTestDataADM
import org.knora.webapi.slice.admin.domain.model.ListProperties.*

/**
* This spec is used to test 'ListAdminMessages'.
Expand Down Expand Up @@ -114,50 +111,5 @@ class ListsMessagesADMSpec extends CoreSpec with ListADMJsonProtocol {
converted.nodeinfo should be(nodeInfo)
converted.children should be(children)
}

"throw 'BadRequestException' for `ChangeNodePositionApiRequestADM` when no parent node iri is given" in {
val payload =
s"""
|{
| "parentNodeIri": "",
| "position": 1
|}
""".stripMargin

val thrown = the[BadRequestException] thrownBy payload.parseJson.convertTo[ChangeNodePositionApiRequestADM]

thrown.getMessage should equal("IRI of parent node is missing.")
}

"throw 'BadRequestException' for `ChangeNodePositionApiRequestADM` when parent node IRI is invalid" in {
val invalid_parentIri = "invalid-iri"
val payload =
s"""
|{
| "parentNodeIri": "$invalid_parentIri",
| "position": 1
|}
""".stripMargin

val thrown = the[BadRequestException] thrownBy payload.parseJson.convertTo[ChangeNodePositionApiRequestADM]

thrown.getMessage should equal(s"Invalid IRI is given: $invalid_parentIri.")
}

"throw 'BadRequestException' for `ChangeNodePositionApiRequestADM` when position is invalid" in {
val payload =
s"""
|{
| "parentNodeIri": "http://rdfh.ch/lists/0001/notUsedList01",
| "position": -2
|}
""".stripMargin

val thrown = the[BadRequestException] thrownBy payload.parseJson.convertTo[ChangeNodePositionApiRequestADM]

thrown.getMessage should equal(
"Invalid position value is given. Position should be either a positive value, 0 or -1."
)
}
}
}
Loading

0 comments on commit 63fe560

Please sign in to comment.