-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIBM-145][PH] add PaymentCalculationPageSpec (#91)
- Loading branch information
1 parent
61f8849
commit 0ee39c3
Showing
8 changed files
with
177 additions
and
48 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
66 changes: 66 additions & 0 deletions
66
test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/PaymentCalculationPageSpec.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,66 @@ | ||
/* | ||
* Copyright 2020 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.merchandiseinbaggagefrontend.pagespecs | ||
|
||
import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.PaymentCalculationPage._ | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.{CustomsAgentPage, PaymentCalculationPage} | ||
|
||
class PaymentCalculationPageSpec extends BasePageSpec[PaymentCalculationPage] with TaxCalculation { | ||
override def page: PaymentCalculationPage = paymentCalculationPage | ||
|
||
private def setUpTaxCalculationAndOpenPage() = { | ||
val taxCalculation = givenADeclarationWithTaxDue(importJourneyWithTwoCompleteGoodsEntries).futureValue | ||
|
||
open(path) | ||
|
||
taxCalculation | ||
} | ||
|
||
"the Payment Calculation Page" should { | ||
behave like aPageWhichRequiresADeclarationJourney(path) | ||
behave like aPageThatRequiresACompletedGoodsEntry(path) | ||
|
||
"render" in { | ||
val taxCalculation = setUpTaxCalculationAndOpenPage() | ||
val paymentCalculations = taxCalculation.paymentCalculations | ||
|
||
page.mustRenderBasicContent(path, title(taxCalculation.totalTaxDue)) | ||
page.summaryHeaders mustBe Seq("Type of goods", "Customs Duty", "VAT", "Total") | ||
|
||
Range(0, 1).foreach { index => | ||
val calculationResult = paymentCalculations(index).calculationResult | ||
val goods = paymentCalculations(index).goods | ||
|
||
page.summaryRow(index) mustBe | ||
Seq( | ||
goods.categoryQuantityOfGoods.category, | ||
calculationResult.duty.formattedInPounds, | ||
s"${calculationResult.vat.formattedInPounds} at ${goods.goodsVatRate.value}%", | ||
calculationResult.taxDue.formattedInPounds) | ||
} | ||
|
||
page.summaryRow(2) mustBe Seq("Payment due", taxCalculation.totalTaxDue.formattedInPounds) | ||
} | ||
|
||
"redirect to the customs agent page" when { | ||
"the user clicks the CTA" in { | ||
setUpTaxCalculationAndOpenPage() | ||
page.clickOnCTA() mustBe CustomsAgentPage.path | ||
} | ||
} | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/TaxCalculation.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,53 @@ | ||
/* | ||
* Copyright 2020 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.merchandiseinbaggagefrontend.pagespecs | ||
|
||
import uk.gov.hmrc.http.HeaderCarrier | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{DeclarationJourney, PaymentCalculations} | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.currencyconversion.Currency | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.service.CalculationService | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.stubs.CurrencyConversionStub.givenCurrencyIsFound | ||
|
||
import scala.concurrent.Future | ||
|
||
trait TaxCalculation { | ||
this: BasePageSpec[_] => | ||
|
||
private lazy val calculationService = injector.instanceOf[CalculationService] | ||
|
||
def givenADeclarationWithTaxDue(declarationJourney: DeclarationJourney): Future[PaymentCalculations] = { | ||
implicit val hc: HeaderCarrier = HeaderCarrier() | ||
|
||
def givenCurrenciesAreFound(): Unit = | ||
declarationJourney | ||
.goodsEntries | ||
.declarationGoodsIfComplete | ||
.get | ||
.goods | ||
.map(_.purchaseDetails.currency) | ||
.toSet | ||
.foreach { ccy: Currency => | ||
givenCurrencyIsFound(ccy.currencyCode, wireMockServer) | ||
() | ||
} | ||
|
||
givenADeclarationJourney(declarationJourney) | ||
givenCurrenciesAreFound() | ||
|
||
calculationService.paymentCalculation(declarationJourney.goodsEntries.declarationGoodsIfComplete.get) | ||
} | ||
} |
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