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/KnownFactsRequest.scala b/app/models/gg/KnownFactsRequest.scala new file mode 100644 index 00000000..6d62df77 --- /dev/null +++ b/app/models/gg/KnownFactsRequest.scala @@ -0,0 +1,26 @@ +/* + * 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[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 new file mode 100644 index 00000000..e8ed0445 --- /dev/null +++ b/test/unit/models/gg/KnownFactsRequestSpec.scala @@ -0,0 +1,54 @@ +/* + * 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.{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 { + + import TypeValuePairExamples._ + + "KnownFactsRequest" should { + "Provide the correct writer for KnownFactsRequest" in { + val knownFact1 = TypeValuePair( + `type` = testType1, + value = testValue1 + ) + val knownFact2 = TypeValuePair( + `type` = testType2, + value = testValue2 + ) + val knownFactsRequest = KnownFactsRequest(List(knownFact1, knownFact2)) + + val request: JsValue = Json.toJson(knownFactsRequest) + val expected = Json.fromJson[KnownFactsRequest]( + s"""{ + | "facts": [ + | ${jsonTypeValuePair(testType1, testValue1).get}, + | ${jsonTypeValuePair(testType2, testValue2).get}] + | }""".stripMargin).get + val actual = Json.fromJson[KnownFactsRequest](request).get + + actual shouldBe expected + } + } + +} 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 + } + + } + }