Skip to content

Commit

Permalink
Get rid of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertbates committed Oct 7, 2024
1 parent fe61f5d commit 1985083
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 82 deletions.
2 changes: 1 addition & 1 deletion support-frontend/app/actions/CachedActionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CachedActionBuilder(
implicit private val ec: ExecutionContext = executionContext
private val maximumBrowserAge = 1.minute

override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]): Future[Result] =
override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]): Future[Result] =
block(request).map(_.withHeaders(mergeHeader("Vary", cacheHeaders() ++ headers): _*))

private def cacheHeaders(now: DateTime = DateTime.now): List[(String, String)] = {
Expand Down
2 changes: 1 addition & 1 deletion support-frontend/app/actions/NoCacheActionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NoCacheActionBuilder(
) extends ActionBuilder[Request, AnyContent] {
implicit private val ec: ExecutionContext = executionContext

override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]): Future[Result] =
override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]): Future[Result] =
block(request).map(_.withHeaders(mergeHeader("Vary", List(CacheControl.noCache) ++ headers): _*))

}
2 changes: 1 addition & 1 deletion support-frontend/app/actions/PrivateActionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class PrivateActionBuilder(
override def composeAction[A](action: Action[A]): Action[A] =
new CSRFAction(action, csrfConfig, addToken, checkToken)

override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]): Future[Result] =
override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]): Future[Result] =
block(request).map(_.withHeaders(CacheControl.noCache))
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait PaperRoundAPI {
def chargebands(): Future[ChargeBandsEndpoint.Response]
}

case class AgentId(val id: BigInt) extends AnyVal
case class AgentId(id: BigInt) extends AnyVal

object AgentId {
implicit val encoder: Encoder[AgentId] = Encoder.encodeBigInt.contramap(_.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ object AnnualisedValueTwoCalculator {
})
.getOrElse(Left("No print options supplied"))

def getMargin(a: AcquisitionModel) =
private def getMargin(a: AcquisitionModel) =
a.product match {
case AcquisitionProduct.Contribution => getContributionMargin(a)
case AcquisitionProduct.RecurringContribution => getRecurringMargin(a)
Expand Down
3 changes: 1 addition & 2 deletions support-payment-api/src/main/scala/MyApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ class MyApplicationLoader extends ApplicationLoader with StrictLogging {
try {
new MyComponents(context).application
} catch {
case err: Throwable => {
case err: Throwable =>
logger.error("Could not start application", err)
throw err
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object StripeJsonDecoder {

// Private because it should only be constructed using the accompanying Decoder
class NonEmptyString private (val value: String) extends AnyVal {
override def toString(): String = value
override def toString: String = value
}

object NonEmptyString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import model.{InitializationError, InitializationResult, SQSThreadPool}
import services.ContributionsStoreQueueService.Message

import java.time.LocalDateTime
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.concurrent.Future
import scala.util.control.NonFatal

Expand Down
90 changes: 49 additions & 41 deletions support-payment-api/src/test/scala/backend/StripeBackendSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import scala.concurrent.{ExecutionContext, Future}
class StripeBackendFixture(implicit ec: ExecutionContext) extends MockitoSugar {

// -- entities
val email = Json.fromString("[email protected]").as[NonEmptyString].toOption.get
val token = Json.fromString("token").as[NonEmptyString].toOption.get
val email: NonEmptyString = Json.fromString("[email protected]").as[NonEmptyString].toOption.get
val token: NonEmptyString = Json.fromString("token").as[NonEmptyString].toOption.get
val recaptchaToken = "recaptchaToken"
val acquisitionData =
val acquisitionData: AcquisitionData =
AcquisitionData(
Some("platform"),
None,
Expand All @@ -53,42 +53,43 @@ class StripeBackendFixture(implicit ec: ExecutionContext) extends MockitoSugar {
None,
Some("N1 9GU"),
)
val stripePaymentData = StripePaymentData(email, Currency.USD, 12, None)
val legacyStripePaymentData = LegacyStripePaymentData(email, Currency.USD, 12, None, token)
val stripePublicKey = StripePublicKey("pk_test_FOOBAR")
val stripeChargeRequest = LegacyStripeChargeRequest(legacyStripePaymentData, acquisitionData, Some(stripePublicKey))
val createPaymentIntent =
val stripePaymentData: StripePaymentData = StripePaymentData(email, Currency.USD, 12, None)
val legacyStripePaymentData: LegacyStripePaymentData = LegacyStripePaymentData(email, Currency.USD, 12, None, token)
val stripePublicKey: StripePublicKey = StripePublicKey("pk_test_FOOBAR")
val stripeChargeRequest: LegacyStripeChargeRequest =
LegacyStripeChargeRequest(legacyStripePaymentData, acquisitionData, Some(stripePublicKey))
val createPaymentIntent: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentData,
acquisitionData,
Some(stripePublicKey),
recaptchaToken,
)
val confirmPaymentIntent =
val confirmPaymentIntent: ConfirmPaymentIntent =
ConfirmPaymentIntent("id", stripePaymentData, acquisitionData, Some(stripePublicKey))

val countrySubdivisionCode = Some("NY")
val clientBrowserInfo = ClientBrowserInfo("", "", None, None, countrySubdivisionCode)
val stripeHookObject = StripeHookObject("id", "GBP")
val stripeHookData = StripeHookData(stripeHookObject)
val stripeHook = StripeRefundHook("id", PaymentStatus.Paid, stripeHookData)
val dbError = ContributionsStoreService.Error(new Exception("DB error response"))
val countrySubdivisionCode: Option[String] = Some("NY")
val clientBrowserInfo: ClientBrowserInfo = ClientBrowserInfo("", "", None, None, countrySubdivisionCode)
val stripeHookObject: StripeHookObject = StripeHookObject("id", "GBP")
val stripeHookData: StripeHookData = StripeHookData(stripeHookObject)
val stripeHook: StripeRefundHook = StripeRefundHook("id", PaymentStatus.Paid, stripeHookData)
val dbError: ContributionsStoreService.Error = ContributionsStoreService.Error(new Exception("DB error response"))

val identityError = IdentityClient.ContextualError(
val identityError: IdentityClient.ContextualError = IdentityClient.ContextualError(
IdentityClient.Error.fromThrowable(new Exception("Identity error response")),
IdentityClient.GetUser("[email protected]"),
)
val stripeDisabledErrorText = "Stripe payments are currently disabled"
val paymentError = PaypalApiError.fromString("Error response")
val stripeApiError = StripeApiError.fromThrowable(new Exception("Stripe error"), None)
val backendError = BackendError.fromStripeApiError(stripeApiError)
val paymentError: PaypalApiError = PaypalApiError.fromString("Error response")
val stripeApiError: StripeApiError = StripeApiError.fromThrowable(new Exception("Stripe error"), None)
val backendError: BackendError = BackendError.fromStripeApiError(stripeApiError)
val emailError: EmailService.Error = EmailService.Error(new Exception("Email error response"))

// -- mocks
val chargeMock: Charge = mock[Charge]
val eventMock = mock[Event]
val paymentIntentMock = mock[PaymentIntent]
val eventMock: Event = mock[Event]
val paymentIntentMock: PaymentIntent = mock[PaymentIntent]

// -- service responses
val paymentServiceResponse: EitherT[Future, StripeApiError, Charge] =
Expand Down Expand Up @@ -250,8 +251,9 @@ class StripeBackendSpec

"a request is made to create a Payment Intent" should {
"return Stripe payments are currently disabled response if stripe checkout switch is off in support-admin-console" in new StripeBackendFixture {
val stripePaymentDataWithStripe = StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout))
val createPaymentIntentWithStripeCheckout =
val stripePaymentDataWithStripe: StripePaymentData =
StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout))
val createPaymentIntentWithStripeCheckout: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentDataWithStripe,
Expand All @@ -266,8 +268,9 @@ class StripeBackendSpec
}

"return Stripe payments are currently disabled response if stripe Apple Pay switch is off in support-admin-console" in new StripeBackendFixture {
val stripePaymentDataWithApplePay = StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay))
val createPaymentIntentWithStripeApplePay =
val stripePaymentDataWithApplePay: StripePaymentData =
StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay))
val createPaymentIntentWithStripeApplePay: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentDataWithApplePay,
Expand All @@ -281,9 +284,9 @@ class StripeBackendSpec
StripeApiError.fromString(stripeDisabledErrorText, None)
}
"return Stripe payments are currently disabled response if stripe payment request button switch is off in support-admin-console" in new StripeBackendFixture {
val stripePaymentDataWithStripePaymentRequest =
val stripePaymentDataWithStripePaymentRequest: StripePaymentData =
StripePaymentData(email, Currency.USD, 12, Some(StripePaymentRequestButton))
val createPaymentIntentWithStripePaymentRequest =
val createPaymentIntentWithStripePaymentRequest: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentDataWithStripePaymentRequest,
Expand All @@ -299,8 +302,9 @@ class StripeBackendSpec
StripeApiError.fromString(stripeDisabledErrorText, None)
}
"return Success if stripe checkout switch is On in support-admin-console" in new StripeBackendFixture {
val stripePaymentDataWithStripe = StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout))
val createPaymentIntentWithStripeCheckout =
val stripePaymentDataWithStripe: StripePaymentData =
StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout))
val createPaymentIntentWithStripeCheckout: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentDataWithStripe,
Expand Down Expand Up @@ -331,8 +335,9 @@ class StripeBackendSpec
}

"return Success if stripe apple pay switch is On in support-admin-console" in new StripeBackendFixture {
val stripePaymentDataWithStripeApplePay = StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay))
val createPaymentIntentWithStripeApplePay =
val stripePaymentDataWithStripeApplePay: StripePaymentData =
StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay))
val createPaymentIntentWithStripeApplePay: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentDataWithStripeApplePay,
Expand Down Expand Up @@ -361,9 +366,9 @@ class StripeBackendSpec
StripePaymentIntentsApiResponse.Success()
}
"return Success if stripe payment request button switch is On in support-admin-console" in new StripeBackendFixture {
val stripePaymentDataWithStripePaymentRequest =
val stripePaymentDataWithStripePaymentRequest: StripePaymentData =
StripePaymentData(email, Currency.USD, 12, Some(StripePaymentRequestButton))
val createPaymentIntentWithStripePaymentRequest =
val createPaymentIntentWithStripePaymentRequest: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentDataWithStripePaymentRequest,
Expand Down Expand Up @@ -398,9 +403,10 @@ class StripeBackendSpec
"a request is made to create a charge/payment" should {

"return error if the email address is invalid due to a comma in it" in new StripeBackendFixture {
val emailWithComma = Json.fromString("email,[email protected]").as[NonEmptyString].toOption.get
val stripePaymentDataWithStripe = StripePaymentData(emailWithComma, Currency.USD, 12, Some(StripeCheckout))
val createPaymentIntentWithStripeCheckout =
val emailWithComma: NonEmptyString = Json.fromString("email,[email protected]").as[NonEmptyString].toOption.get
val stripePaymentDataWithStripe: StripePaymentData =
StripePaymentData(emailWithComma, Currency.USD, 12, Some(StripeCheckout))
val createPaymentIntentWithStripeCheckout: CreatePaymentIntent =
CreatePaymentIntent(
"payment-method-id",
stripePaymentDataWithStripe,
Expand Down Expand Up @@ -491,8 +497,9 @@ class StripeBackendSpec
when(mockSoftOptInsService.sendMessage(any(), any())(any())).thenReturn(softOptInsResponse)
when(mockAcquisitionsEventBusService.putAcquisitionEvent(any()))
.thenReturn(acquisitionsEventBusResponse)
val trackContribution = PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution"))
val result =
val trackContribution: PrivateMethod[Future[List[BackendError]]] =
PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution"))
val result: Future[List[BackendError]] =
stripeBackend invokePrivate trackContribution(chargeMock, stripeChargeRequest, None, clientBrowserInfo)
result.futureValue mustBe List(BackendError.Database(dbError))

Expand All @@ -508,10 +515,11 @@ class StripeBackendSpec
when(mockSoftOptInsService.sendMessage(any(), any())(any())).thenReturn(softOptInsResponse)
when(mockAcquisitionsEventBusService.putAcquisitionEvent(any()))
.thenReturn(acquisitionsEventBusResponseError)
val trackContribution = PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution"))
val result =
val trackContribution: PrivateMethod[Future[List[BackendError]]] =
PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution"))
val result: Future[List[BackendError]] =
stripeBackend invokePrivate trackContribution(chargeMock, stripeChargeRequest, None, clientBrowserInfo)
val error = List(
val error: List[BackendError] = List(
BackendError.AcquisitionsEventBusError(acquisitionsEventBusErrorMessage),
BackendError.Database(dbError),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ class PaypalControllerSpec extends AnyWordSpec with Status with Matchers {
implicit val materializer: Materializer = ActorMaterializer()
implicit val executionContext: ExecutionContext = ExecutionContext.global

val context = ApplicationLoader.Context.create(Environment.simple())
val context: ApplicationLoader.Context = ApplicationLoader.Context.create(Environment.simple())

"Paypal Controller" when {

"a request is made to create a payment" should {

val fixtureFor200Response = new PaypalControllerFixture()(executionContext, context) {
val fixtureFor200Response: PaypalControllerFixture = new PaypalControllerFixture()(executionContext, context) {
val link = new Links("http://return-url.com", "approval_url")
val links: java.util.List[Links] = List(link).asJava
when(enrichedPaymentMock.payment)
Expand Down Expand Up @@ -188,7 +188,7 @@ class PaypalControllerSpec extends AnyWordSpec with Status with Matchers {
}

"return a 500 response if the response contains an invalid return url" in {
val fixture = new PaypalControllerFixture()(executionContext, context) {
val fixture: PaypalControllerFixture = new PaypalControllerFixture()(executionContext, context) {

import scala.jdk.CollectionConverters._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class StripeControllerSpec extends AnyWordSpec with Status with Matchers {
implicit val materializer: Materializer = ActorMaterializer()
implicit val executionContext: ExecutionContext = ExecutionContext.global

val context = ApplicationLoader.Context.create(Environment.simple())
val context: ApplicationLoader.Context = ApplicationLoader.Context.create(Environment.simple())

"StripeController" when {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package services

import io.circe.Json

import java.time.LocalDateTime
import java.util.UUID

import model.{Currency, PaymentProvider, PaymentStatus}
import model.db.ContributionData
import services.ContributionsStoreQueueService.NewContributionData
Expand All @@ -12,9 +13,9 @@ import org.scalatest.matchers.must.Matchers

class ContributionsStoreServiceSpec extends AnyFlatSpec with Matchers {

val uuid = UUID.randomUUID()
val uuid: UUID = UUID.randomUUID()

val contributionData = ContributionData(
val contributionData: ContributionData = ContributionData(
paymentProvider = PaymentProvider.Paypal,
paymentStatus = PaymentStatus.Paid,
paymentId = "paymentId",
Expand All @@ -29,7 +30,7 @@ class ContributionsStoreServiceSpec extends AnyFlatSpec with Matchers {
postalCode = Some("N1 9GU"),
)

val expectedJson = parse(
val expectedJson: Json = parse(
s"""|{
| "newContributionData" : {
| "paymentProvider" : "Paypal",
Expand Down
Loading

0 comments on commit 1985083

Please sign in to comment.