Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove invoicing api call from holiday stop processor #2504

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ object Handler extends Logging {
getAccountFromZuora(config, backend),
idGenerator,
FulfilmentDatesFetcher(fetchString, Stage()),
PreviewPublications.preview,
now,
)(
request,
Expand All @@ -136,7 +135,6 @@ object Handler extends Logging {
getAccount: (AccessToken, String) => Either[ApiFailure, ZuoraAccount],
idGenerator: => String,
fulfilmentDatesFetcher: FulfilmentDatesFetcher,
previewPublications: (String, String, String) => Either[ApiFailure, PreviewPublicationsResponse] = null, // FIXME
now: () => ZonedDateTime,
): (ApiGatewayRequest, HttpOp[StringHttpRequest, BodyAsString]) => ApiResponse = {
(for {
Expand All @@ -150,7 +148,6 @@ object Handler extends Logging {
getAccount,
idGenerator,
fulfilmentDatesFetcher,
previewPublications,
now,
)).fold(
{ errorMessage: String =>
Expand Down Expand Up @@ -182,13 +179,12 @@ object Handler extends Logging {
getAccount: (AccessToken, String) => Either[ApiFailure, ZuoraAccount],
idGenerator: => String,
fulfilmentDatesFetcher: FulfilmentDatesFetcher,
previewPublications: (String, String, String) => Either[ApiFailure, PreviewPublicationsResponse] = null, // FIXME
now: () => ZonedDateTime,
) = {
path match {
case "potential" :: _ :: Nil =>
httpMethod match {
case "GET" => stepsForPotentialHolidayStop(getAccessToken, getSubscription, getAccount, previewPublications) _
case "GET" => stepsForPotentialHolidayStop(getAccessToken, getSubscription, getAccount) _
case _ => unsupported _
}
case "hsr" :: Nil =>
Expand Down Expand Up @@ -246,54 +242,10 @@ object Handler extends Logging {
endDate: LocalDate,
)

// FIXME: Temporary test in production to validate migration to https://github.com/guardian/invoicing-api/pull/23
// FIXME: Make sure to add .filter(_.price > 0.0) if it ever replaces old potential endpoint
import scala.concurrent.{ExecutionContext, Future}
import java.util.concurrent.Executors
private val ecForTestInProd = ExecutionContext.fromExecutor(Executors.newSingleThreadExecutor)
private def testInProdPreviewPublications(
previewPublications: (String, String, String) => Either[ApiFailure, PreviewPublicationsResponse],
subscription: Subscription,
queryParams: PotentialHolidayStopsQueryParams,
potentialHolidayStops: List[PotentialHolidayStop],
nextInvoiceDateAfterToday: LocalDate,
): Future[_] = Future {
lazy val testCase =
s"${subscription.subscriptionNumber}?startDate=${queryParams.startDate}&endDate=${queryParams.endDate}"

(previewPublications(subscription.subscriptionNumber, queryParams.startDate.toString, queryParams.endDate.toString)
.map { actual =>
val actualPotentialHolidayStops =
actual.publicationsWithinRange
.filter(
_.price > 0.0,
) // invoicing-api/preview endpoint is general and calculates the price of each publication (even if it is 0)
.map(pub => PotentialHolidayStop(pub.publicationDate, Credit(-pub.price, pub.nextInvoiceDate)))
.sortBy(_.publicationDate)

val actualNextInvoiceDateAfterToday = actual.nextInvoiceDateAfterToday

if (
(potentialHolidayStops == actualPotentialHolidayStops) && (nextInvoiceDateAfterToday == actualNextInvoiceDateAfterToday)
) {
// 1logger.info("testInProdPreviewPublications OK")
} else {
logger.error(
s"testInProdPreviewPublications failed $testCase because $potentialHolidayStops =/= $actualPotentialHolidayStops or $nextInvoiceDateAfterToday =/= $actualNextInvoiceDateAfterToday",
)
}
})
.left
.map { e =>
logger.error(s"testInProdPreviewPublications failed $testCase because invoicing-api error: $e")
}
}(ecForTestInProd)

def stepsForPotentialHolidayStop(
getAccessToken: () => Either[ApiFailure, AccessToken],
getSubscription: (AccessToken, SubscriptionName) => Either[ApiFailure, Subscription],
getAccount: (AccessToken, String) => Either[ApiFailure, ZuoraAccount],
previewPublications: (String, String, String) => Either[ApiFailure, PreviewPublicationsResponse] = null, // FIXME
)(req: ApiGatewayRequest, unused: SfClient): ApiResponse = {
implicit val reads: Reads[PotentialHolidayStopsQueryParams] = Json.reads[PotentialHolidayStopsQueryParams]
(for {
Expand Down Expand Up @@ -321,13 +273,6 @@ object Handler extends Logging {
.filter(_.nextBillingPeriodStartDate.isAfter(MutableCalendar.today))
.minBy(_.nextBillingPeriodStartDate)(Ordering.by(_.toEpochDay))
.nextBillingPeriodStartDate
_ = testInProdPreviewPublications(
previewPublications,
subscription,
queryParams,
potentialHolidayStops,
nextInvoiceDateAfterToday,
) // FIXME
} yield ApiGatewayResponse(
"200",
PotentialHolidayStopsResponse(nextInvoiceDateAfterToday, potentialHolidayStops),
Expand Down

This file was deleted.

This file was deleted.

Loading