Skip to content

Commit

Permalink
Merge pull request #49 from hmrc/SAR-345
Browse files Browse the repository at this point in the history
Sar 345
  • Loading branch information
MJCallahanPage authored Feb 20, 2017
2 parents 9f761f6 + 92b28d8 commit 507baef
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 22 deletions.
29 changes: 29 additions & 0 deletions app/models/gg/EnrolRequest.scala
Original file line number Diff line number Diff line change
@@ -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]
}
29 changes: 29 additions & 0 deletions app/models/gg/EnrolResponse.scala
Original file line number Diff line number Diff line change
@@ -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]
}
26 changes: 26 additions & 0 deletions app/models/gg/KnownFactsRequest.scala
Original file line number Diff line number Diff line change
@@ -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]
}
25 changes: 25 additions & 0 deletions app/models/gg/TypeValuePair.scala
Original file line number Diff line number Diff line change
@@ -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]
}
49 changes: 49 additions & 0 deletions test/unit/models/gg/EnrolRequestSpec.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

}
55 changes: 55 additions & 0 deletions test/unit/models/gg/EnrolResponseSpec.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

}
54 changes: 54 additions & 0 deletions test/unit/models/gg/KnownFactsRequestSpec.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

}
43 changes: 43 additions & 0 deletions test/unit/models/gg/TypeValuePairSpec.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

}
Loading

0 comments on commit 507baef

Please sign in to comment.