diff options
author | Øyvind Grønnesby <oyving@yahooinc.com> | 2023-10-16 15:58:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-16 15:58:05 +0200 |
commit | 5af33f2eb25475eabe3c8136920104e3bf25907e (patch) | |
tree | 5ea1fb20b0e9bb1a4857d9d9b72631fa7bc4859d /controller-server/src/test/java/com | |
parent | c11a6d32d06a115cce22c87066698f7436588030 (diff) | |
parent | 6a1b57f988a07ac265b072182952bc54c9115c8e (diff) |
Merge pull request #28938 from vespa-engine/bjorncs/email-notification
Bjorncs/email notification
Diffstat (limited to 'controller-server/src/test/java/com')
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java index 95cffae8728..b595c8a8be3 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java @@ -3,12 +3,16 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; +import com.yahoo.test.ManualClock; +import com.yahoo.vespa.flags.Flags; import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.flags.PermanentFlags; import com.yahoo.vespa.hosted.controller.ControllerTester; import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanId; import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; +import com.yahoo.vespa.hosted.controller.notification.Notification; +import com.yahoo.vespa.hosted.controller.notification.NotificationSource; import com.yahoo.vespa.hosted.controller.tenant.LastLoginInfo; import com.yahoo.vespa.hosted.controller.tenant.Tenant; import org.junit.jupiter.api.Test; @@ -89,6 +93,33 @@ public class CloudTrialExpirerTest { assertPlan("active", "none"); } + @Test + void queues_trial_notification_based_on_account_age() { + var clock = (ManualClock)tester.controller().clock(); + var tenant = TenantName.from("trial-tenant"); + ((InMemoryFlagSource) tester.controller().flagSource()) + .withBooleanFlag(Flags.CLOUD_TRIAL_NOTIFICATIONS.id(), true); + registerTenant(tenant.value(), "trial", Duration.ZERO); + assertEquals(0.0, expirer.maintain()); + assertEquals("Welcome to Vespa Cloud", lastAccountLevelNotificationTitle(tenant)); + + clock.advance(Duration.ofDays(7)); + assertEquals(0.0, expirer.maintain()); + assertEquals("How is your Vespa Cloud trial going?", lastAccountLevelNotificationTitle(tenant)); + + clock.advance(Duration.ofDays(5)); + assertEquals(0.0, expirer.maintain()); + assertEquals("Your Vespa Cloud trial expires in 2 days", lastAccountLevelNotificationTitle(tenant)); + + clock.advance(Duration.ofDays(1)); + assertEquals(0.0, expirer.maintain()); + assertEquals("Your Vespa Cloud trial expires tomorrow", lastAccountLevelNotificationTitle(tenant)); + + clock.advance(Duration.ofDays(2)); + assertEquals(0.0, expirer.maintain()); + assertEquals("Your Vespa Cloud trial has expired", lastAccountLevelNotificationTitle(tenant)); + } + private void registerTenant(String tenantName, String plan, Duration timeSinceLastLogin) { var name = TenantName.from(tenantName); tester.createTenant(tenantName, Tenant.Type.cloud); @@ -111,4 +142,11 @@ public class CloudTrialExpirerTest { assertEquals(planId, tester.serviceRegistry().billingController().getPlan(TenantName.from(tenant)).value()); } + private String lastAccountLevelNotificationTitle(TenantName tenant) { + return tester.controller().notificationsDb() + .listNotifications(NotificationSource.from(tenant), false).stream() + .filter(n -> n.type() == Notification.Type.account).map(n -> n.messages().get(0)) + .findFirst().orElseThrow(); + } + } |