diff --git a/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala b/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala index 471feb9..f277f61 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala @@ -42,7 +42,8 @@ trait JsonFormatters extends SharedJsonFormatters { (JsPath \ "name").read[String] and (JsPath \ "description").read[String] and ((JsPath \ "hint").read[String] or Reads.pure("")) and - (JsPath \ "type").read[FieldDefinitionType] + (JsPath \ "type").read[FieldDefinitionType] and + ((JsPath \ "shortDescription").read[String] or Reads.pure("")) )(FieldDefinition.apply _) val fieldDefinitionWrites = Json.writes[FieldDefinition] implicit val FieldDefinitionJF = Format(fieldDefinitionReads, fieldDefinitionWrites) diff --git a/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala b/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala index c6bd0eb..b283860 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala @@ -36,4 +36,4 @@ object FieldDefinitionType extends Enumeration { val STRING = Value("STRING") } -case class FieldDefinition(name: String, description: String, hint: String = "", `type`: FieldDefinitionType) +case class FieldDefinition(name: String, description: String, hint: String = "", `type`: FieldDefinitionType, shortDescription: String) diff --git a/run_all_tests.sh b/run_all_tests.sh index d93dcfc..f32bb10 100755 --- a/run_all_tests.sh +++ b/run_all_tests.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +export SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxMetaspaceSize=1G" sbt clean coverage test acceptance:test coverageReport diff --git a/test/uk/gov/hmrc/apisubscriptionfields/TestData.scala b/test/uk/gov/hmrc/apisubscriptionfields/TestData.scala index 2ce5a54..0b1da1f 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/TestData.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/TestData.scala @@ -64,9 +64,9 @@ trait SubscriptionFieldsTestData extends TestData { } trait FieldsDefinitionTestData extends TestData { - final val FakeFieldDefinitionUrl = FieldDefinition("name1", "desc1", "hint1", FieldDefinitionType.URL) - final val FakeFieldDefinitionString = FieldDefinition("name2", "desc2", "hint2", FieldDefinitionType.STRING) - final val FakeFieldDefinitionSecureToken = FieldDefinition("name3", "desc3", "hint3", FieldDefinitionType.SECURE_TOKEN) + final val FakeFieldDefinitionUrl = FieldDefinition("name1", "desc1", "hint1", FieldDefinitionType.URL, "short description") + final val FakeFieldDefinitionString = FieldDefinition("name2", "desc2", "hint2", FieldDefinitionType.STRING, "short description") + final val FakeFieldDefinitionSecureToken = FieldDefinition("name3", "desc3", "hint3", FieldDefinitionType.SECURE_TOKEN, "short description") final val FakeFieldsDefinitions = Seq(FakeFieldDefinitionUrl, FakeFieldDefinitionString, FakeFieldDefinitionSecureToken) final val FakeFieldsDefinition = FieldsDefinition(fakeRawContext, fakeRawVersion, FakeFieldsDefinitions) final val FakeFieldsDefinitionResponse = FieldsDefinitionResponse(fakeRawContext, fakeRawVersion, FakeFieldsDefinition.fieldDefinitions) diff --git a/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala index 8bfbcc0..fb8faae 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala @@ -41,13 +41,15 @@ class FieldsDefinitionControllerGetSpec extends UnitSpec with FieldsDefinitionTe | "name": "callback-url", | "description": "Callback URL", | "hint": "Description Hint", - | "type": "URL" + | "type": "URL", + | "shortDescription": "short desc" | }, | { | "name": "token", | "description": "Secure Token", | "hint": "Description Hint", - | "type": "SecureToken" + | "type": "SecureToken", + | "shortDescription": "" | } | ] |}""".stripMargin @@ -65,13 +67,15 @@ class FieldsDefinitionControllerGetSpec extends UnitSpec with FieldsDefinitionTe | "name": "callback-url", | "description": "Callback URL", | "hint": "Description Hint", - | "type": "URL" + | "type": "URL", + | "shortDescription": "short desc" | }, | { | "name": "token", | "description": "Secure Token", | "hint": "Description Hint", - | "type": "SecureToken" + | "type": "SecureToken", + | "shortDescription": "" | } | ] | }, @@ -83,13 +87,15 @@ class FieldsDefinitionControllerGetSpec extends UnitSpec with FieldsDefinitionTe | "name": "address", | "description": "where you live", | "hint": "Description Hint", - | "type": "STRING" + | "type": "STRING", + | "shortDescription": "" | }, | { | "name": "number", | "description": "telephone number", | "hint": "Description Hint", - | "type": "STRING" + | "type": "STRING", + | "shortDescription": "" | } | ] | } diff --git a/test/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala index 11720f5..7524f4b 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala @@ -37,7 +37,8 @@ class JsonFormatterSpec extends WordSpec private def objectAsJsonString[A](a:A)(implicit t: Writes[A]) = Json.asciiStringify(Json.toJson(a)) private val subscriptionFieldJson = s"""{"clientId":"$fakeRawClientId","apiContext":"$fakeRawContext","apiVersion":"$fakeRawVersion","fieldsId":"$FakeRawFieldsId","fields":{"f1":"v1"}}""" - private val fieldDefinitionJson = s"""{"apiContext":"$fakeRawContext","apiVersion":"$fakeRawVersion","fieldDefinitions":[{"name":"name1","description":"desc1","hint":"hint1","type":"URL"}]}""" + private val fieldDefinitionJson = + s"""{"apiContext":"$fakeRawContext","apiVersion":"$fakeRawVersion","fieldDefinitions":[{"name":"name1","description":"desc1","hint":"hint1","type":"URL","shortDescription":"short description"}]}""" "SubscriptionFieldsResponse" should { "marshal json" in { diff --git a/test/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala index e2df446..dde763a 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala @@ -23,13 +23,19 @@ import uk.gov.hmrc.play.test.UnitSpec class MongoFormattersSpec extends UnitSpec with JsonFormatters { "Field definition formatter" should { "Correctly unmarshall a JSON field definition with all the necessary fields" in { - val fieldDefinition = FieldDefinition("name", "description", "hint", FieldDefinitionType.STRING) - Json.fromJson[FieldDefinition](Json.parse("""{ "name" : "name", "description" : "description", "hint": "hint", "type" : "STRING" }""")) shouldBe JsSuccess(fieldDefinition) + val fieldDefinition = FieldDefinition("name", "description", "hint", FieldDefinitionType.STRING, "short description") + Json.fromJson[FieldDefinition](Json.parse("""{ "name" : "name", "description" : "description", "hint": "hint", "type" : "STRING", "shortDescription" : "short description"}""")) shouldBe JsSuccess(fieldDefinition) } "Correctly unmarshall a JSON field definition without the hint field" in { - val fieldDefinition = FieldDefinition("name", "description", "", FieldDefinitionType.STRING) - Json.fromJson[FieldDefinition](Json.parse("""{ "name" : "name", "description" : "description", "type" : "STRING" }""")) shouldBe JsSuccess(fieldDefinition) + val fieldDefinition = FieldDefinition("name", "description", "", FieldDefinitionType.STRING, "short description") + Json.fromJson[FieldDefinition](Json.parse("""{ "name" : "name", "description" : "description", "type" : "STRING", "shortDescription" : "short description"}""")) shouldBe JsSuccess(fieldDefinition) } + + "Correctly unmarshall a JSON field definition without the shortDescription field" in { + val fieldDefinition = FieldDefinition("name", "description", "hint", FieldDefinitionType.STRING, "") + Json.fromJson[FieldDefinition](Json.parse("""{ "name" : "name", "description" : "description", "hint": "hint", "type" : "STRING"}""")) shouldBe JsSuccess(fieldDefinition) + } + } }