Skip to content

Commit

Permalink
Merge '#148' added implicit conversions back to AccountingMethod model
Browse files Browse the repository at this point in the history
  • Loading branch information
r-melvin committed Sep 18, 2019
2 parents 5584966 + 1fbf0ef commit 0378814
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
5 changes: 2 additions & 3 deletions app/models/frontend/FERequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package models.frontend

import models.DateModel
import models.subscription.business.AccountingMethod
import play.api.libs.functional.syntax._
import play.api.libs.json._

Expand All @@ -28,7 +27,7 @@ case class FERequest(nino: String,
accountingPeriodStart: Option[DateModel] = None,
accountingPeriodEnd: Option[DateModel] = None,
tradingName: Option[String] = None,
cashOrAccruals: Option[AccountingMethod] = None
cashOrAccruals: Option[String] = None
)

object FERequest {
Expand All @@ -42,7 +41,7 @@ object FERequest {
(JsPath \ "accountingPeriodStart").readNullable[DateModel] and
(JsPath \ "accountingPeriodEnd").readNullable[DateModel] and
(JsPath \ "tradingName").readNullable[String] and
(JsPath \ "cashOrAccruals").readNullable[AccountingMethod]
(JsPath \ "cashOrAccruals").readNullable[String]
) (FERequest.apply _)

val writes: OWrites[FERequest] = Json.writes[FERequest]
Expand Down
2 changes: 1 addition & 1 deletion app/models/monitoring/rosmAndEnrol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object rosmAndEnrol {
"acccountingPeriodStartDate" -> fERequest.accountingPeriodStart.fold("-")(x => x.toDesDateFormat),
"acccountingPeriodEndDate" -> fERequest.accountingPeriodEnd.fold("-")(x => x.toDesDateFormat),
"tradingName" -> fERequest.tradingName.fold("-")(identity),
"cashOrAccruals" -> fERequest.cashOrAccruals.fold("-")(x => x.stringValue.toLowerCase),
"cashOrAccruals" -> fERequest.cashOrAccruals.fold("-")(x => x.toLowerCase),
"Authorization" -> urlHeaderAuthorization
)

Expand Down
11 changes: 9 additions & 2 deletions app/models/subscription/business/BusinessDetailsModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,24 @@ case object Accruals extends AccountingMethod {
}

object AccountingMethod {
val feCash = "Cash"
val feAccruals = "Accruals"

private val reader: Reads[AccountingMethod] = __.read[String].map {
case Cash.stringValue => Cash
case Accruals.stringValue => Accruals
case `feCash` | Cash.stringValue => Cash
case `feAccruals` | Accruals.stringValue => Accruals
}

private val writer: Writes[AccountingMethod] = Writes[AccountingMethod](cashOrAccruals =>
JsString(cashOrAccruals.stringValue)
)

implicit val format: Format[AccountingMethod] = Format(reader, writer)

implicit def convert(str: String): AccountingMethod = str match {
case `feCash` | Cash.stringValue => Cash
case `feAccruals` | Accruals.stringValue => Accruals
}
}

case class BusinessDetailsModel(accountingPeriodStartDate: String,
Expand Down
4 changes: 2 additions & 2 deletions it/helpers/IntegrationTestConstants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ object IntegrationTestConstants {
accountingPeriodStart = DateModel("01", "05", "2017"),
accountingPeriodEnd = DateModel("30", "04", "2018"),
tradingName = "Test Business",
cashOrAccruals = Cash
cashOrAccruals = Some("Cash")
)

val feBothRequest = FERequest(
Expand All @@ -102,7 +102,7 @@ object IntegrationTestConstants {
accountingPeriodStart = DateModel("01", "05", "2017"),
accountingPeriodEnd = DateModel("30", "04", "2018"),
tradingName = "Test Business",
cashOrAccruals = Cash
cashOrAccruals = Some("Cash")
)

val businessSubscriptionRequestPayload = BusinessSubscriptionRequestModel(
Expand Down
4 changes: 2 additions & 2 deletions test/utils/TestConstants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object TestConstants {
accountingPeriodStart = DateModel("01", "05", "2017"),
accountingPeriodEnd = DateModel("30", "04", "2018"),
tradingName = "Test Business",
cashOrAccruals = Cash
cashOrAccruals = Some("Cash")
)

val feBothRequest = FERequest(
Expand All @@ -96,7 +96,7 @@ object TestConstants {
accountingPeriodStart = DateModel("01", "05", "2017"),
accountingPeriodEnd = DateModel("30", "04", "2018"),
tradingName = "Test Business",
cashOrAccruals = Cash
cashOrAccruals = Some("Cash")
)

val businessSubscriptionRequestPayload = BusinessSubscriptionRequestModel(
Expand Down

0 comments on commit 0378814

Please sign in to comment.