From 1b965a95794efd0a9b0c6252b7197cee23f2cb35 Mon Sep 17 00:00:00 2001 From: Su-Yang Yu Date: Fri, 17 Feb 2017 09:12:53 +0000 Subject: [PATCH 1/2] added models for known facts to gg admin --- app/models/gg/KnownFact.scala | 10 ++++ app/models/gg/KnownFactsRequest.scala | 10 ++++ .../models/gg/KnownFactsRequestSpec.scala | 58 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 app/models/gg/KnownFact.scala create mode 100644 app/models/gg/KnownFactsRequest.scala create mode 100644 test/unit/models/gg/KnownFactsRequestSpec.scala diff --git a/app/models/gg/KnownFact.scala b/app/models/gg/KnownFact.scala new file mode 100644 index 00000000..bab272d3 --- /dev/null +++ b/app/models/gg/KnownFact.scala @@ -0,0 +1,10 @@ +package models.gg + +import play.api.libs.json.Json + +case class KnownFact(`type`: String, value: String) + +object KnownFact { + implicit val format = Json.format[KnownFact] +} + diff --git a/app/models/gg/KnownFactsRequest.scala b/app/models/gg/KnownFactsRequest.scala new file mode 100644 index 00000000..8bd71443 --- /dev/null +++ b/app/models/gg/KnownFactsRequest.scala @@ -0,0 +1,10 @@ +package models.gg + +import play.api.libs.json.Json + + +case class KnownFactsRequest(facts: List[KnownFact]) + +object KnownFactsRequest { + implicit val formats = Json.format[KnownFactsRequest] +} diff --git a/test/unit/models/gg/KnownFactsRequestSpec.scala b/test/unit/models/gg/KnownFactsRequestSpec.scala new file mode 100644 index 00000000..626053ba --- /dev/null +++ b/test/unit/models/gg/KnownFactsRequestSpec.scala @@ -0,0 +1,58 @@ +package unit.models.gg + +import models.gg.{KnownFact, KnownFactsRequest} +import play.api.libs.json.{JsValue, Json} +import uk.gov.hmrc.play.test.UnitSpec +import utils.JsonUtils._ + +class KnownFactsRequestSpec extends UnitSpec { + + val testType1 = "MOSW2Number" + val testValue1 = "10" + val testType2 = "MOSW2ID" + val testValue2 = "A" + + "KnownFact" should { + "Provide the correct writer for KnownFact" in { + val knownFact = KnownFact( + `type` = testType1, + value = testValue1 + ) + + val request: JsValue = Json.toJson(knownFact) + val expected = Json.fromJson[KnownFact]( + s"""{"type" : "$testType1", + | "value" : "$testValue1" + | }""".stripMargin).get + val actual = Json.fromJson[KnownFact](request).get + + actual shouldBe expected + } + } + + "KnownFactsRequest" should { + "Provide the correct writer for KnownFactsRequest" in { + val knownFact1 = KnownFact( + `type` = testType1, + value = testValue1 + ) + val knownFact2 = KnownFact( + `type` = testType2, + value = testValue2 + ) + val knownFactsRequest = KnownFactsRequest(List(knownFact1, knownFact2)) + + val request: JsValue = Json.toJson(knownFactsRequest) + val expected = Json.fromJson[KnownFactsRequest]( + s"""{ + | "facts": [ + | { "type" : "MOSW2Number", "value": "10" }, + | { "type" : "MOSW2ID", "value": "A" }] + | }""".stripMargin).get + val actual = Json.fromJson[KnownFactsRequest](request).get + + actual shouldBe expected + } + } + +} From 92b28d87cd0828aca3aa2a71ea166b95e9fd9e4b Mon Sep 17 00:00:00 2001 From: Su-Yang Yu Date: Fri, 17 Feb 2017 11:08:24 +0000 Subject: [PATCH 2/2] SAR-345: added models to GG Enrolment --- app/models/gg/EnrolRequest.scala | 29 +++++ app/models/gg/EnrolResponse.scala | 29 +++++ app/models/gg/KnownFact.scala | 10 -- app/models/gg/KnownFactsRequest.scala | 18 +++- app/models/gg/TypeValuePair.scala | 25 +++++ test/unit/models/gg/EnrolRequestSpec.scala | 49 +++++++++ test/unit/models/gg/EnrolResponseSpec.scala | 55 ++++++++++ .../models/gg/KnownFactsRequestSpec.scala | 50 ++++----- test/unit/models/gg/TypeValuePairSpec.scala | 43 ++++++++ test/utils/TestConstants.scala | 100 ++++++++++++++---- 10 files changed, 348 insertions(+), 60 deletions(-) create mode 100644 app/models/gg/EnrolRequest.scala create mode 100644 app/models/gg/EnrolResponse.scala delete mode 100644 app/models/gg/KnownFact.scala create mode 100644 app/models/gg/TypeValuePair.scala create mode 100644 test/unit/models/gg/EnrolRequestSpec.scala create mode 100644 test/unit/models/gg/EnrolResponseSpec.scala create mode 100644 test/unit/models/gg/TypeValuePairSpec.scala diff --git a/app/models/gg/EnrolRequest.scala b/app/models/gg/EnrolRequest.scala new file mode 100644 index 00000000..cd8d19a1 --- /dev/null +++ b/app/models/gg/EnrolRequest.scala @@ -0,0 +1,29 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models.gg + +import play.api.libs.json.Json + + +case class EnrolRequest(portalId: String, + serviceName: String, + friendlyName: String, + knownFacts: List[String]) + +object EnrolRequest { + implicit val format = Json.format[EnrolRequest] +} diff --git a/app/models/gg/EnrolResponse.scala b/app/models/gg/EnrolResponse.scala new file mode 100644 index 00000000..335634f1 --- /dev/null +++ b/app/models/gg/EnrolResponse.scala @@ -0,0 +1,29 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models.gg + +import play.api.libs.json.Json + + +case class EnrolResponse(serviceName: String, + state: String, + friendlyName: String, + identifiers: List[TypeValuePair]) + +object EnrolResponse { + implicit val format = Json.format[EnrolResponse] +} diff --git a/app/models/gg/KnownFact.scala b/app/models/gg/KnownFact.scala deleted file mode 100644 index bab272d3..00000000 --- a/app/models/gg/KnownFact.scala +++ /dev/null @@ -1,10 +0,0 @@ -package models.gg - -import play.api.libs.json.Json - -case class KnownFact(`type`: String, value: String) - -object KnownFact { - implicit val format = Json.format[KnownFact] -} - diff --git a/app/models/gg/KnownFactsRequest.scala b/app/models/gg/KnownFactsRequest.scala index 8bd71443..6d62df77 100644 --- a/app/models/gg/KnownFactsRequest.scala +++ b/app/models/gg/KnownFactsRequest.scala @@ -1,9 +1,25 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package models.gg import play.api.libs.json.Json -case class KnownFactsRequest(facts: List[KnownFact]) +case class KnownFactsRequest(facts: List[TypeValuePair]) object KnownFactsRequest { implicit val formats = Json.format[KnownFactsRequest] diff --git a/app/models/gg/TypeValuePair.scala b/app/models/gg/TypeValuePair.scala new file mode 100644 index 00000000..221bd79f --- /dev/null +++ b/app/models/gg/TypeValuePair.scala @@ -0,0 +1,25 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models.gg + +import play.api.libs.json.Json + +case class TypeValuePair(`type`: String, value: String) + +object TypeValuePair { + implicit val format = Json.format[TypeValuePair] +} diff --git a/test/unit/models/gg/EnrolRequestSpec.scala b/test/unit/models/gg/EnrolRequestSpec.scala new file mode 100644 index 00000000..a00f9c87 --- /dev/null +++ b/test/unit/models/gg/EnrolRequestSpec.scala @@ -0,0 +1,49 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package unit.models.gg + +import models.gg.EnrolRequest +import play.api.libs.json.JsValue +import uk.gov.hmrc.play.test.UnitSpec +import utils.JsonUtils._ +import utils.TestConstants.GG.EnrolRequestExamples + +class EnrolRequestSpec extends UnitSpec { + + import EnrolRequestExamples._ + + "EnrolRequest" should { + "Provide the correct writer for EnrolRequest" in { + val request: JsValue = EnrolRequest( + portalId, + serviceName, + friendlyName, + List(knownFact1, knownFact2) + ) + + val expected: JsValue = jsonEnrolRequest( + portalId, + serviceName, + friendlyName, + List(knownFact1, knownFact2) + ) + + request shouldBe expected + } + } + +} diff --git a/test/unit/models/gg/EnrolResponseSpec.scala b/test/unit/models/gg/EnrolResponseSpec.scala new file mode 100644 index 00000000..8b4553f8 --- /dev/null +++ b/test/unit/models/gg/EnrolResponseSpec.scala @@ -0,0 +1,55 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package unit.models.gg + +import models.gg.{EnrolResponse, TypeValuePair} +import play.api.libs.json.JsValue +import uk.gov.hmrc.play.test.UnitSpec +import utils.JsonUtils._ +import utils.TestConstants.GG.EnrolResponseExamples + +class EnrolResponseSpec extends UnitSpec { + + import EnrolResponseExamples._ + + "EnrolResponse" should { + "Provide the correct reader for EnrolResponse" in { + val response: JsValue = EnrolResponse( + serviceName, + state, + friendlyName, + List( + TypeValuePair(testType1, testValue1), + TypeValuePair(testType2, testValue2) + ) + ) + + val expected = jsonEnrolResponse( + serviceName, + state, + friendlyName, + List( + TypeValuePair(testType1, testValue1), + TypeValuePair(testType2, testValue2) + ) + ) + + response shouldBe expected + } + } + +} diff --git a/test/unit/models/gg/KnownFactsRequestSpec.scala b/test/unit/models/gg/KnownFactsRequestSpec.scala index 626053ba..e8ed0445 100644 --- a/test/unit/models/gg/KnownFactsRequestSpec.scala +++ b/test/unit/models/gg/KnownFactsRequestSpec.scala @@ -1,42 +1,38 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package unit.models.gg -import models.gg.{KnownFact, KnownFactsRequest} +import models.gg.{KnownFactsRequest, TypeValuePair} import play.api.libs.json.{JsValue, Json} import uk.gov.hmrc.play.test.UnitSpec import utils.JsonUtils._ +import utils.TestConstants.GG.TypeValuePairExamples class KnownFactsRequestSpec extends UnitSpec { - val testType1 = "MOSW2Number" - val testValue1 = "10" - val testType2 = "MOSW2ID" - val testValue2 = "A" - - "KnownFact" should { - "Provide the correct writer for KnownFact" in { - val knownFact = KnownFact( - `type` = testType1, - value = testValue1 - ) - - val request: JsValue = Json.toJson(knownFact) - val expected = Json.fromJson[KnownFact]( - s"""{"type" : "$testType1", - | "value" : "$testValue1" - | }""".stripMargin).get - val actual = Json.fromJson[KnownFact](request).get - - actual shouldBe expected - } - } + import TypeValuePairExamples._ "KnownFactsRequest" should { "Provide the correct writer for KnownFactsRequest" in { - val knownFact1 = KnownFact( + val knownFact1 = TypeValuePair( `type` = testType1, value = testValue1 ) - val knownFact2 = KnownFact( + val knownFact2 = TypeValuePair( `type` = testType2, value = testValue2 ) @@ -46,8 +42,8 @@ class KnownFactsRequestSpec extends UnitSpec { val expected = Json.fromJson[KnownFactsRequest]( s"""{ | "facts": [ - | { "type" : "MOSW2Number", "value": "10" }, - | { "type" : "MOSW2ID", "value": "A" }] + | ${jsonTypeValuePair(testType1, testValue1).get}, + | ${jsonTypeValuePair(testType2, testValue2).get}] | }""".stripMargin).get val actual = Json.fromJson[KnownFactsRequest](request).get diff --git a/test/unit/models/gg/TypeValuePairSpec.scala b/test/unit/models/gg/TypeValuePairSpec.scala new file mode 100644 index 00000000..648e319d --- /dev/null +++ b/test/unit/models/gg/TypeValuePairSpec.scala @@ -0,0 +1,43 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package unit.models.gg + +import models.gg.TypeValuePair +import play.api.libs.json.{JsValue, Json} +import uk.gov.hmrc.play.test.UnitSpec +import utils.TestConstants.GG.TypeValuePairExamples + +class TypeValuePairSpec extends UnitSpec { + + import TypeValuePairExamples._ + + "TypeValuePair" should { + "Provide the correct writer for TypeValuePair" in { + val knownFact = TypeValuePair( + `type` = testType1, + value = testValue1 + ) + + val request: JsValue = Json.toJson(knownFact) + val expected = Json.fromJson[TypeValuePair](jsonTypeValuePair(testType1,testValue1)).get + val actual = Json.fromJson[TypeValuePair](request).get + + actual shouldBe expected + } + } + +} diff --git a/test/utils/TestConstants.scala b/test/utils/TestConstants.scala index 9659fef1..e5752ade 100644 --- a/test/utils/TestConstants.scala +++ b/test/utils/TestConstants.scala @@ -16,14 +16,15 @@ package utils -import play.api.libs.json.JsValue -import uk.gov.hmrc.domain.Generator -import JsonUtils._ -import models.{DateModel, ErrorModel} import models.frontend.{Both, Business, FERequest, Property} +import models.gg.TypeValuePair import models.registration.RegistrationRequestModel import models.subscription.business.{BusinessDetailsModel, BusinessSubscriptionRequestModel} +import models.{DateModel, ErrorModel} import play.api.http.Status._ +import play.api.libs.json.JsValue +import uk.gov.hmrc.domain.Generator +import utils.JsonUtils._ object TestConstants { @@ -59,8 +60,8 @@ object TestConstants { nino = testNino, incomeSource = Business, isAgent = false, - accountingPeriodStart = DateModel("01","05","2017"), - accountingPeriodEnd = DateModel("30","04","2018"), + accountingPeriodStart = DateModel("01", "05", "2017"), + accountingPeriodEnd = DateModel("30", "04", "2018"), tradingName = "Test Business", cashOrAccruals = "cash" ) @@ -69,8 +70,8 @@ object TestConstants { nino = testNino, incomeSource = Both, isAgent = false, - accountingPeriodStart = DateModel("01","05","2017"), - accountingPeriodEnd = DateModel("30","04","2018"), + accountingPeriodStart = DateModel("01", "05", "2017"), + accountingPeriodEnd = DateModel("30", "04", "2018"), tradingName = "Test Business", cashOrAccruals = "cash" ) @@ -176,26 +177,26 @@ object TestConstants { object BusinessSubscriptionResponse { def successResponse(safeId: String, mtditId: String, sourceId: String): JsValue = s"""{ - | "safeId": "$safeId", - | "mtditId": "$mtditId", - | "incomeSources": [{ - | "incomeSourceId": "$sourceId" - | }] - |} + | "safeId": "$safeId", + | "mtditId": "$mtditId", + | "incomeSources": [{ + | "incomeSourceId": "$sourceId" + | }] + |} """.stripMargin } object PropertySubscriptionResponse { def successResponse(safeId: String, mtditId: String, sourceId: String): JsValue = s""" - |{ - | "safeId": "$safeId", - | "mtditId": "$mtditId", - | "incomeSource": - | { - | "incomeSourceId": "$sourceId" - | } - |} + |{ + | "safeId": "$safeId", + | "mtditId": "$mtditId", + | "incomeSource": + | { + | "incomeSourceId": "$sourceId" + | } + |} """.stripMargin } @@ -207,4 +208,59 @@ object TestConstants { | "reason":"$reason" |} """.stripMargin + + object GG { + + object TypeValuePairExamples { + val testType1 = "MOSW2Number" + val testValue1 = "10" + val testType2 = "MOSW2ID" + val testValue2 = "A" + + def jsonTypeValuePair(testType: String, testValue: String): JsValue = + s"""{"type" : "$testType", + | "value" : "$testValue" + | }""".stripMargin + } + + object EnrolRequestExamples { + val portalId = "MOSW" + val serviceName = "MOSW5" + val friendlyName = "Main Enrolment" + val knownFact1 = "DV200L" + val knownFact2 = "13 66GH" + + def jsonEnrolRequest(portalId: String, serviceName: String, friendlyName: String, knownFacts: List[String]): JsValue = + s"""{ + | "portalId": "$portalId", + | "serviceName": "$serviceName", + | "friendlyName": "$friendlyName", + | "knownFacts": [ + | ${knownFacts.map(x =>s""" "$x" """).mkString(",")} + | ] + |}""".stripMargin + } + + object EnrolResponseExamples { + val serviceName = "MOSW5" + val state = "NotYetActivated" + val friendlyName = "" + val testType1 = "MOSW5PostCode" + val testValue1 = "13 9DF" + val testType2 = "MOSW5Reference" + val testValue2 = "DV200L" + + def jsonEnrolResponse(serviceName: String, state: String, friendlyName: String, identifier: List[TypeValuePair]): JsValue = + s"""{ + | "serviceName": "$serviceName", + | "state": "$state", + | "friendlyName": "$friendlyName", + | "identifiers": [ + | ${identifier.map(x => s"""{ "type" : "${x.`type`}", "value" : "${x.value}"}""").mkString(",")} + | ] + |}""".stripMargin + } + + } + }