-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write tests for JSON de/serialization
- Loading branch information
1 parent
66bec46
commit 9587e37
Showing
6 changed files
with
290 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
test/uk/gov/hmrc/hecapplicantfrontend/models/HECTaxCheckDataSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2021 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 uk.gov.hmrc.hecapplicantfrontend.models | ||
|
||
import java.time.LocalDate | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import play.api.libs.json.Json | ||
import uk.gov.hmrc.hecapplicantfrontend.models.ApplicantDetails.{CompanyApplicantDetails, IndividualApplicantDetails} | ||
import uk.gov.hmrc.hecapplicantfrontend.models.HECTaxCheckData.{CompanyHECTaxCheckData, IndividualHECTaxCheckData} | ||
import uk.gov.hmrc.hecapplicantfrontend.models.TaxDetails.{CompanyTaxDetails, IndividualTaxDetails} | ||
import uk.gov.hmrc.hecapplicantfrontend.models.ids.{CTUTR, GGCredId, NINO, SAUTR} | ||
import uk.gov.hmrc.hecapplicantfrontend.models.licence.{LicenceDetails, LicenceTimeTrading, LicenceType, LicenceValidityPeriod} | ||
|
||
class HECTaxCheckDataSpec extends AnyWordSpec with Matchers { | ||
|
||
"HECTaxCheckData" must { | ||
|
||
"perform JSON de/serialisation correctly" must { | ||
val individualTaxCheckData: HECTaxCheckData = | ||
IndividualHECTaxCheckData( | ||
IndividualApplicantDetails( | ||
GGCredId("ggCredId"), | ||
Name("first", "last"), | ||
DateOfBirth(LocalDate.now()) | ||
), | ||
LicenceDetails( | ||
LicenceType.ScrapMetalMobileCollector, | ||
LicenceTimeTrading.EightYearsOrMore, | ||
LicenceValidityPeriod.UpToThreeYears | ||
), | ||
IndividualTaxDetails( | ||
NINO("nino"), | ||
Some(SAUTR("utr")), | ||
TaxSituation.SA, | ||
Some(IncomeDeclared.Yes) | ||
) | ||
) | ||
|
||
val individualJson = Json.parse("""{ | ||
| "applicantDetails":{ | ||
| "ggCredId":"ggCredId", | ||
| "name":{ | ||
| "firstName":"first", | ||
| "lastName":"last" | ||
| }, | ||
| "dateOfBirth":"20210922" | ||
| }, | ||
| "licenceDetails":{ | ||
| "licenceType":"ScrapMetalMobileCollector", | ||
| "licenceTimeTrading":"EightYearsOrMore", | ||
| "licenceValidityPeriod":"UpToThreeYears" | ||
| }, | ||
| "taxDetails":{ | ||
| "nino":"nino", | ||
| "sautr":"utr", | ||
| "taxSituation":"SA", | ||
| "saIncomeDeclared":"Yes" | ||
| }, | ||
| "type":"Individual" | ||
|}""".stripMargin) | ||
|
||
val companyTaxCheckData: HECTaxCheckData = | ||
CompanyHECTaxCheckData( | ||
CompanyApplicantDetails( | ||
GGCredId("ggCredId") | ||
), | ||
LicenceDetails( | ||
LicenceType.ScrapMetalMobileCollector, | ||
LicenceTimeTrading.EightYearsOrMore, | ||
LicenceValidityPeriod.UpToThreeYears | ||
), | ||
CompanyTaxDetails( | ||
CTUTR("utr") | ||
) | ||
) | ||
|
||
val companyJson = Json.parse("""{ | ||
| "applicantDetails":{ | ||
| "ggCredId":"ggCredId" | ||
| }, | ||
| "licenceDetails":{ | ||
| "licenceType":"ScrapMetalMobileCollector", | ||
| "licenceTimeTrading":"EightYearsOrMore", | ||
| "licenceValidityPeriod":"UpToThreeYears" | ||
| }, | ||
| "taxDetails":{ | ||
| "ctutr":"utr" | ||
| }, | ||
| "type":"Company" | ||
|}""".stripMargin) | ||
|
||
"serialize Individual data" in { | ||
Json.toJson(individualTaxCheckData) shouldBe individualJson | ||
} | ||
|
||
"serialize Company data" in { | ||
Json.toJson(companyTaxCheckData) shouldBe companyJson | ||
} | ||
|
||
"deserialize Individual data" in { | ||
Json.fromJson[HECTaxCheckData](individualJson).get shouldBe individualTaxCheckData | ||
} | ||
|
||
"deserialize Company data" in { | ||
Json.fromJson[HECTaxCheckData](companyJson).get shouldBe companyTaxCheckData | ||
} | ||
} | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
test/uk/gov/hmrc/hecapplicantfrontend/models/RetrievedApplicantDataSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2021 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 uk.gov.hmrc.hecapplicantfrontend.models | ||
|
||
import java.time.LocalDate | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import play.api.libs.json.Json | ||
import uk.gov.hmrc.hecapplicantfrontend.models.RetrievedApplicantData.{CompanyRetrievedData, IndividualRetrievedData} | ||
import uk.gov.hmrc.hecapplicantfrontend.models.ids.{CTUTR, GGCredId, NINO, SAUTR} | ||
|
||
class RetrievedApplicantDataSpec extends AnyWordSpec with Matchers { | ||
|
||
"RetrievedApplicantData" must { | ||
|
||
"perform JSON de/serialisation correctly" must { | ||
val individualRetrievedData: RetrievedApplicantData = | ||
IndividualRetrievedData( | ||
GGCredId("ggCredId"), | ||
NINO("nino"), | ||
Some(SAUTR("utr")), | ||
Name("first", "last"), | ||
DateOfBirth(LocalDate.now()), | ||
Some(EmailAddress("email")), | ||
None | ||
) | ||
|
||
val individualJson = Json.parse("""{ | ||
|"ggCredId":"ggCredId", | ||
|"nino":"nino", | ||
|"sautr":"utr", | ||
|"name":{ | ||
| "firstName":"first", | ||
| "lastName":"last" | ||
|}, | ||
|"dateOfBirth":"20210922", | ||
|"emailAddress":"email", | ||
|"type":"Individual" | ||
|}""".stripMargin) | ||
|
||
val companyRetrievedData: RetrievedApplicantData = | ||
CompanyRetrievedData( | ||
GGCredId("ggCredId"), | ||
Some(CTUTR("utr")), | ||
Some(EmailAddress("email")) | ||
) | ||
|
||
val companyJson = Json.parse("""{ | ||
|"ggCredId":"ggCredId", | ||
|"ctutr":"utr", | ||
|"emailAddress":"email", | ||
|"type":"Company" | ||
|}""".stripMargin) | ||
|
||
"serialize Individual retrieved data" in { | ||
Json.toJson(individualRetrievedData) shouldBe individualJson | ||
} | ||
|
||
"serialize Company retrieved data" in { | ||
Json.toJson(companyRetrievedData) shouldBe companyJson | ||
} | ||
|
||
"deserialize Individual retrieved data" in { | ||
Json.fromJson[RetrievedApplicantData](individualJson).get shouldBe individualRetrievedData | ||
} | ||
|
||
"deserialize Company retrieved data" when { | ||
"all fields are present" in { | ||
Json.fromJson[RetrievedApplicantData](companyJson).get shouldBe companyRetrievedData | ||
} | ||
|
||
"only mandatory fields are present" in { | ||
Json | ||
.fromJson[RetrievedApplicantData](Json.parse("""{"ggCredId":"ggCredId", "type":"Company"}""")) | ||
.get shouldBe CompanyRetrievedData(GGCredId("ggCredId"), None, None) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters