Skip to content

Commit

Permalink
SASS-6706: Save and continue for financial charges journey (happy pat…
Browse files Browse the repository at this point in the history
…h) (#60)

* SASS-6706: Save and continue for financial charges

* SASS-6706: Add header

* SASS-6706: Remove comment

* SASS-6706: Test rename
  • Loading branch information
harry-ritchie authored Jan 4, 2024
1 parent 21de07e commit f5b2fdb
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/controllers/JourneyAnswersController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import models.frontend.expenses.advertisingOrMarketing.AdvertisingOrMarketingJou
import models.frontend.expenses.construction.ConstructionJourneyAnswers
import models.frontend.expenses.depreciation.DepreciationCostsJourneyAnswers
import models.frontend.expenses.entertainment.EntertainmentJourneyAnswers
import models.frontend.expenses.financialCharges.FinancialChargesJourneyAnswers
import models.frontend.expenses.goodsToSellOrUse.GoodsToSellOrUseJourneyAnswers
import models.frontend.expenses.interest.InterestJourneyAnswers
import models.frontend.expenses.officeSupplies.OfficeSuppliesJourneyAnswers
Expand Down Expand Up @@ -206,4 +207,11 @@ class JourneyAnswersController @Inject() (auth: AuthorisedAction,
}
}

def saveFinancialCharges(taxYear: TaxYear, businessId: BusinessId, nino: Nino): Action[AnyContent] = auth.async { implicit user =>
getBody[FinancialChargesJourneyAnswers](user) { value =>
val ctx = JourneyContextWithNino(taxYear, businessId, user.getMtditid, nino)
expensesService.saveAnswers(ctx, value).map(_ => NoContent)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 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.frontend.expenses.financialCharges

import play.api.libs.json.{Format, Json}

case class FinancialChargesJourneyAnswers(financialChargesAmount: BigDecimal, financialChargesDisallowableAmount: Option[BigDecimal])

object FinancialChargesJourneyAnswers {
implicit val formats: Format[FinancialChargesJourneyAnswers] = Json.format[FinancialChargesJourneyAnswers]
}
6 changes: 6 additions & 0 deletions app/utils/DeductionsBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import models.frontend.expenses.advertisingOrMarketing.AdvertisingOrMarketingJou
import models.frontend.expenses.construction.ConstructionJourneyAnswers
import models.frontend.expenses.depreciation.DepreciationCostsJourneyAnswers
import models.frontend.expenses.entertainment.EntertainmentJourneyAnswers
import models.frontend.expenses.financialCharges.FinancialChargesJourneyAnswers
import models.frontend.expenses.goodsToSellOrUse.GoodsToSellOrUseJourneyAnswers
import models.frontend.expenses.interest.InterestJourneyAnswers
import models.frontend.expenses.officeSupplies.OfficeSuppliesJourneyAnswers
Expand Down Expand Up @@ -126,4 +127,9 @@ object DeductionsBuilder {
(answers: OtherExpensesJourneyAnswers) =>
Deductions.empty.copy(other =
Some(SelfEmploymentDeductionsDetailType(Some(answers.otherExpensesAmount), answers.otherExpensesDisallowableAmount)))

implicit val financialCharges: DeductionsBuilder[FinancialChargesJourneyAnswers] =
(answers: FinancialChargesJourneyAnswers) =>
Deductions.empty.copy(financialCharges =
Some(SelfEmploymentDeductionsDetailPosNegType(Some(answers.financialChargesAmount), answers.financialChargesDisallowableAmount)))
}
2 changes: 2 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ POST /:taxYear/:businessId/expenses-depreciation/:nino/answers
GET /:taxYear/:businessId/expenses-depreciation/:nino/answers controllers.JourneyAnswersController.getDepreciationCosts(taxYear: TaxYear, businessId: BusinessId, nino: Nino)

POST /:taxYear/:businessId/expenses-other-expenses/:nino/answers controllers.JourneyAnswersController.saveOtherExpenses(taxYear: TaxYear, businessId: BusinessId, nino: Nino)

POST /:taxYear/:businessId/expenses-financial-charges/:nino/answers controllers.JourneyAnswersController.saveFinancialCharges(taxYear: TaxYear, businessId: BusinessId, nino: Nino)
12 changes: 12 additions & 0 deletions test/controllers/JourneyAnswersControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ class JourneyAnswersControllerSpec extends ControllerBehaviours with ScalaCheckP
}
}
}
"FinancialCharges" should {
s"Save answers and return a $NO_CONTENT when successful" in {
forAll(financialChargesJourneyAnswersGen) { data =>
behave like testRoute(
request = buildRequest(data),
expectedStatus = NO_CONTENT,
expectedBody = "",
methodBlock = () => underTest.saveFinancialCharges(currTaxYear, businessId, nino)
)
}
}
}

trait GetExpensesTest[T] {
val expensesService: ExpensesAnswersService = mock[ExpensesAnswersService]
Expand Down
6 changes: 6 additions & 0 deletions test/gens/ExpensesJourneyAnswersGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import models.frontend.expenses.advertisingOrMarketing.AdvertisingOrMarketingJou
import models.frontend.expenses.construction.ConstructionJourneyAnswers
import models.frontend.expenses.depreciation.DepreciationCostsJourneyAnswers
import models.frontend.expenses.entertainment.EntertainmentJourneyAnswers
import models.frontend.expenses.financialCharges.FinancialChargesJourneyAnswers
import models.frontend.expenses.goodsToSellOrUse.GoodsToSellOrUseJourneyAnswers
import models.frontend.expenses.interest.InterestJourneyAnswers
import models.frontend.expenses.officeSupplies.OfficeSuppliesJourneyAnswers
Expand Down Expand Up @@ -84,4 +85,9 @@ object ExpensesJourneyAnswersGen {
disallowableAmount <- Gen.option(bigDecimalGen)
} yield OtherExpensesJourneyAnswers(amount, disallowableAmount)

val financialChargesJourneyAnswersGen: Gen[FinancialChargesJourneyAnswers] = for {
amount <- bigDecimalGen
disallowableAmount <- Gen.option(bigDecimalGen)
} yield FinancialChargesJourneyAnswers(amount, disallowableAmount)

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ class FinancialsTypeSpec extends AnyWordSpec with Matchers {
)))
)

FinancialsType.fromFrontendModel(answers) shouldBe expectedResult
}
"work with financial charges" in {
val answers = financialChargesJourneyAnswersGen.sample.get

val expectedResult = FinancialsType(
None,
Some(
Deductions.empty.copy(financialCharges = Some(
SelfEmploymentDeductionsDetailPosNegType(Some(answers.financialChargesAmount), answers.financialChargesDisallowableAmount)
)))
)

FinancialsType.fromFrontendModel(answers) shouldBe expectedResult
}
}
Expand Down

0 comments on commit f5b2fdb

Please sign in to comment.