Skip to content

Commit

Permalink
Add test for every operation type on projects
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyhappydan committed Mar 25, 2024
1 parent 299fbf8 commit 04151f5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,17 @@ class EndToEndTest extends BaseIntegrationSpec {

"transfer multiple revisions of a project" in {

val (project, payload, projectJson) = thereIsAProject()

val updatedProjectJson = projectIsUpdated(project, payload.copy(description = "updated description"))
val (project, revisionsAndStates) = thereAreManyRevisionsOfAProject()

whenTheExportIsRunOnProject(project)

theOldProjectIsDeleted(project, 2)
theOldProjectIsDeleted(project, revisionsAndStates.keys.max)

weRunTheImporter(project)

weFixThePermissions(project)

thereShouldBeAProject(project, updatedProjectJson)
thereShouldBeAProjectRevision(project, 1, projectJson)
thereShouldBeAProjectThatMatchesExpectations(project, revisionsAndStates)
}

"transfer the default resolver" in {
Expand Down Expand Up @@ -185,6 +182,22 @@ class EndToEndTest extends BaseIntegrationSpec {
thereIsAView(project, simpleEsView)
}

def thereAreManyRevisionsOfAProject(): (ProjectRef, Map[Int, Json]) = {
val (ref, payload, json) = thereIsAProject()
val updatedJson = projectIsUpdated(ref, payload.copy(description = "updated description"), 1)
val deprecatedJson = projectIsDeprecated(ref, 2)
val undeprecatedJson = projectIsUndeprecated(ref, 3)
(
ref,
Map(
1 -> json,
2 -> updatedJson,
3 -> deprecatedJson,
4 -> undeprecatedJson
)
)
}

def thereIsAProject(): (ProjectRef, ProjectPayload, Json) = {
val orgName = genString()
val projName = genString()
Expand All @@ -206,8 +219,23 @@ class EndToEndTest extends BaseIntegrationSpec {
projectJson
}

def projectIsUpdated(ref: ProjectRef, projectPayload: ProjectPayload): Json = {
adminDsl.updateProject(ref.organization.value, ref.project.value, projectPayload, writer, 1).accepted
def projectIsUpdated(ref: ProjectRef, projectPayload: ProjectPayload, revision: Int): Json = {
adminDsl.updateProject(ref.organization.value, ref.project.value, projectPayload, writer, revision).accepted
fetchProjectState(ref)
}

def projectIsDeprecated(ref: ProjectRef, rev: Int): Json = {
val (_, statusCode) =
deltaClient.deleteJsonAndStatus(s"/projects/${ref.organization}/${ref.project}?rev=$rev", writer).accepted
statusCode shouldBe StatusCodes.OK
fetchProjectState(ref)
}

def projectIsUndeprecated(ref: ProjectRef, rev: Int): Json = {
val (_, statusCode) = deltaClient
.putJsonAndStatus(s"/projects/${ref.organization}/${ref.project}/undeprecate?rev=$rev", Json.obj(), writer)
.accepted
statusCode shouldBe StatusCodes.OK
fetchProjectState(ref)
}

Expand Down Expand Up @@ -262,6 +290,13 @@ class EndToEndTest extends BaseIntegrationSpec {
.accepted
}

def thereShouldBeAProjectThatMatchesExpectations(project: ProjectRef, expectations: Map[Int, Json]): Assertion = {
expectations.foreach { case (rev, expectedJson) =>
thereShouldBeAProjectRevision(project, rev, expectedJson)
}
succeed
}

def weFixThePermissions(project: ProjectRef) =
aclDsl.addPermissions(s"/$project", writer, Permission.minimalPermissions).accepted

Expand Down Expand Up @@ -358,4 +393,5 @@ class EndToEndTest extends BaseIntegrationSpec {
.accepted
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class HttpClient private (baseUrl: Uri, httpExt: HttpExt)(implicit
body.flatMap(body => requestAssert(POST, url, Some(body), identity, extraHeaders)(assertResponse))
}

def putJsonAndStatus(url: String, body: Json, identity: Identity)(implicit
um: FromEntityUnmarshaller[Json]
): IO[(Json, StatusCode)] = {
requestJsonAndStatus(PUT, url, Some(body), identity, jsonHeaders)
}

def put[A](url: String, body: Json, identity: Identity, extraHeaders: Seq[HttpHeader] = jsonHeaders)(
assertResponse: (A, HttpResponse) => Assertion
)(implicit um: FromEntityUnmarshaller[A]): IO[Assertion] =
Expand Down Expand Up @@ -206,6 +212,12 @@ class HttpClient private (baseUrl: Uri, httpExt: HttpExt)(implicit
requestJsonAndStatus(GET, url, None, identity, jsonHeaders)
}

def deleteJsonAndStatus(url: String, identity: Identity)(implicit
um: FromEntityUnmarshaller[Json]
): IO[(Json, StatusCode)] = {
requestJsonAndStatus(DELETE, url, None, identity, jsonHeaders)
}

def delete[A](url: String, identity: Identity, extraHeaders: Seq[HttpHeader] = jsonHeaders)(
assertResponse: (A, HttpResponse) => Assertion
)(implicit um: FromEntityUnmarshaller[A]): IO[Assertion] =
Expand Down

0 comments on commit 04151f5

Please sign in to comment.