Skip to content

Commit

Permalink
brazenames
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Sep 4, 2024
1 parent aaf823e commit 6bca7dd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ object NotificationHandler extends CohortHandler {
sp2024_previous_combined_amount <- ZIO.fromEither(sp2024_previous_combined_amount(cohortSpec, subscription))
sp2024_new_combined_amount <- ZIO.fromEither(sp2024_new_combined_amount(cohortSpec, subscription))

brazeName <- ZIO.fromEither(brazeName(cohortSpec, subscription))

_ <- EmailSender.sendEmail(
message = EmailMessage(
EmailPayload(
Expand Down Expand Up @@ -159,7 +161,7 @@ object NotificationHandler extends CohortHandler {
)
)
),
cohortSpec.brazeCampaignName,
brazeName,
contact.Id,
contact.IdentityID__c
)
Expand Down Expand Up @@ -498,4 +500,25 @@ object NotificationHandler extends CohortHandler {
case _ => Right(None)
}
}

// -------------------------------------------------------------------
// Braze names

// Note:

// This function was introduced in September 2024, when as part of SupporterPlus2024 we integrated two different
// email templates in Braze to serve communication to the users.

// Traditionally the name of the campaign or canvas has been part of the CohortSpec, making
// `cohortSpec.brazeCampaignName` the default carrier of this information, but in the case of SupporterPlus 2024
// we have two canvases and need to decide one depending on the structure of the subscription. Once
// SupporterPlus2024 finished, we may decide to go back to a simpler format, or keep that function, depending
// on the likelihood of Marketing adopting this variation in the future.

def brazeName(cohortSpec: CohortSpec, subscription: ZuoraSubscription): Either[Failure, String] = {
MigrationType(cohortSpec) match {
case SupporterPlus2024 => SupporterPlus2024Migration.brazeName(subscription)
case _ => Right(cohortSpec.brazeCampaignName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,32 @@ object SupporterPlus2024Migration {
)
}

def hasNonTrivialContribution(subscription: ZuoraSubscription): Either[Failure, Boolean] = {
for {
amountOpt <- sp2024_contribution_amount(subscription: ZuoraSubscription)
amount <- amountOpt.toRight(
AmendmentDataFailure(
s"(error: 232760f5) could not extract contribution amount for subscription ${subscription.subscriptionNumber}"
)
)
} yield amount > 0
}

// -------------------------------------------------------------------
// Braze names

def brazeName(subscription: ZuoraSubscription): Either[Failure, String] = {
for {
status <- hasNonTrivialContribution(subscription: ZuoraSubscription)
} yield {
if (status) {
"SV_SP2_Contributors_PriceRise2024"
} else {
"SV_SP2_PriceRise2024"
}
}
}

// ------------------------------------------------
// Primary Interface
// ------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import pricemigrationengine.Fixtures
import pricemigrationengine.migrations.SupporterPlus2024Migration

class SupporterPlus2024MigrationTest extends munit.FunSuite {

// -----------------------------------
// Cancellation saves

test("isInCancellationSave") {
val subscriptionNo =
Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/sub-with-cancellation-save/subscription-no.json")
Expand All @@ -21,7 +25,6 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
true
)
}

test("cancellationSaveEffectiveDate") {
val subscriptionNo =
Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/sub-with-cancellation-save/subscription-no.json")
Expand All @@ -37,6 +40,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
)
}

// -----------------------------------
// Price Grid

test("Price Grid (Old)") {
assertEquals(
SupporterPlus2024Migration.getOldPrice(Monthly, "USD"),
Expand All @@ -58,6 +64,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
)
}

// -----------------------------------
// Rate plans extraction

// The monthly is GBP without a contribution [10, 0]
// The annual is a AUD with contribution [160, 340]
// sub-without-LastChangeType is a EUR without a contribution [6, 0]
Expand Down Expand Up @@ -462,6 +471,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
)
}

// -----------------------------------
// Notification helpers sp2024_*

test("sp2024_previous_base_amount (monthly)") {
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json")
assertEquals(
Expand Down Expand Up @@ -615,6 +627,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
)
}

// -----------------------------------
// priceData

test("priceData (monthly)") {
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json")
assertEquals(
Expand All @@ -637,6 +652,9 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
)
}

// -----------------------------------
// EstimationResult

test("EstimationResult (monthly)") {
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json")
val invoices = Fixtures.invoiceListFromJson("Migrations/SupporterPlus2024/monthly/invoices.json")
Expand Down Expand Up @@ -690,6 +708,27 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
)
}

// -----------------------------------
// braze names

test("brazeName (monthly)") {
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json")
assertEquals(
SupporterPlus2024Migration.brazeName(subscription),
Right("SV_SP2_PriceRise2024")
)
}
test("brazeName (annual)") {
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/annual/subscription.json")
assertEquals(
SupporterPlus2024Migration.brazeName(subscription),
Right("SV_SP2_Contributors_PriceRise2024")
)
}

// -----------------------------------
// zuoraUpdate

test("zuoraUpdate (monthly)") {
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json")
assertEquals(
Expand Down

0 comments on commit 6bca7dd

Please sign in to comment.