-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests for the ImportConfigs controller
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |