Skip to content

Commit

Permalink
Add some tests for the ImportConfigs controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesname committed Apr 10, 2024
1 parent c09d251 commit a240f51
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions test/integration/admin/ImportConfigsSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package integration.admin

import helpers._
import mockdata.privilegedUser
import models.ImportConfig
import play.api.libs.json.{JsNull, Json}
import play.api.test.FakeRequest


class ImportConfigsSpec extends IntegrationTestRunner with ResourceUtils {

private val importConfigRoutes = controllers.datasets.routes.ImportConfigs


"Import Configs API" should {

"get configs with no data" in new ITestApp {
val r = FakeRequest(importConfigRoutes.get("r1", "default"))
.withUser(privilegedUser)
.call()
status(r) must_== OK
contentAsJson(r) must_== JsNull
}

"get configs" in new DBTestApp("import-config-fixtures.sql") {
val r = FakeRequest(importConfigRoutes.get("r1", "default"))
.withUser(privilegedUser)
.call()
status(r) must_== OK
contentAsJson(r).asOpt[ImportConfig] must beSome.which { c: ImportConfig =>
c.properties must beSome("r1-ead.properties")
}
}

"save configs" in new DBTestApp("import-config-fixtures.sql") {
val data = Json.obj(
"allowUpdates" -> true,
"useSourceId" -> false,
"tolerant" -> false,
"properties" -> None,
"defaultLang" -> None,
"logMessage" -> "test",
"batchSize" -> None,
"comments" -> Some("Testing testing... 1, 2, 3...")
)
val r = FakeRequest(importConfigRoutes.save("r1", "default"))
.withUser(privilegedUser)
.callWith(data)
status(r) must_== OK
contentAsJson(r).asOpt[ImportConfig] must beSome.which { c: ImportConfig =>
c.comments must beSome("Testing testing... 1, 2, 3...")
}
}

"ingest files" in new DBTestApp("import-config-fixtures.sql") {
// NB: this job will fail (or do nothing) because there are no files
// in the test dataset
val data = Json.obj(
"allowUpdates" -> true,
"useSourceId" -> false,
"tolerant" -> false,
"properties" -> None,
"defaultLang" -> None,
"logMessage" -> "test",
"batchSize" -> None,
"comments" -> Some("Testing testing... 1, 2, 3...")
)
val payload = Json.obj(
"config" -> data,
"commit" -> true,
"files" -> Seq.empty[String]
)
val r = FakeRequest(importConfigRoutes.ingestFiles("r1", "default"))
.withUser(privilegedUser)
.callWith(payload)
status(r) must_== OK
}
}
}

0 comments on commit a240f51

Please sign in to comment.