Skip to content

Commit

Permalink
APIS-4688 - Added shortDescription to FieldDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
anjumabbas5 committed Mar 20, 2020
1 parent 0bea821 commit cb0a8ba
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions run_all_tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash

export SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxMetaspaceSize=1G"
sbt clean coverage test acceptance:test coverageReport
6 changes: 3 additions & 3 deletions test/uk/gov/hmrc/apisubscriptionfields/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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": ""
| }
| ]
| },
Expand All @@ -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": ""
| }
| ]
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
}

0 comments on commit cb0a8ba

Please sign in to comment.