diff options
author | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-10-30 10:59:19 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-10-30 10:59:19 +0100 |
commit | 1abe5ce96b8708c781edeab654c2347157cdc4b0 (patch) | |
tree | d7a36c3098fbe1d4679e466ad6ac7130b457bba4 /controller-server/src/test | |
parent | f61444b7c981a8ecb2c131ad1a5f8bcd2de5ebfd (diff) |
Simplify unit test for trial notifications
Use same file name as original template
Diffstat (limited to 'controller-server/src/test')
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java | 49 | ||||
-rw-r--r-- | controller-server/src/test/resources/mail/trial-expires-immediately.html (renamed from controller-server/src/test/resources/mail/trial-expiring-immediately.html) | 0 | ||||
-rw-r--r-- | controller-server/src/test/resources/mail/trial-expires-soon.html (renamed from controller-server/src/test/resources/mail/trial-expiring-soon.html) | 0 | ||||
-rw-r--r-- | controller-server/src/test/resources/mail/trial-midway-checkin.html (renamed from controller-server/src/test/resources/mail/trial-reminder.html) | 0 | ||||
-rw-r--r-- | controller-server/src/test/resources/mail/trial-signed-up.html (renamed from controller-server/src/test/resources/mail/welcome.html) | 0 |
5 files changed, 28 insertions, 21 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 4056459c532..f5af8987a51 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 @@ -110,40 +110,48 @@ public class CloudTrialExpirerTest { .withBooleanFlag(Flags.CLOUD_TRIAL_NOTIFICATIONS.id(), true); registerTenant(tenant.value(), "trial", Duration.ZERO); assertEquals(0.0, expirer.maintain()); - var expected = "Welcome to Vespa Cloud trial! [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; - assertEquals(expected, lastAccountLevelNotificationTitle(tenant)); - assertLastEmailEquals(mailer, "welcome.html"); - - expected = "You're halfway through the **14 day** trial period. [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; + var expectedConsoleNotification = + "Welcome to Vespa Cloud trial! [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; + var notification = lastAccountLevelNotification(tenant); + assertEquals(expectedConsoleNotification, notification.title()); + assertLastEmail(mailer, notification); + + expectedConsoleNotification = + "You're halfway through the **14 day** trial period. [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; clock.advance(Duration.ofDays(7)); assertEquals(0.0, expirer.maintain()); - assertEquals(expected, lastAccountLevelNotificationTitle(tenant)); - assertLastEmailEquals(mailer, "trial-reminder.html"); + notification = lastAccountLevelNotification(tenant); + assertEquals(expectedConsoleNotification, notification.title()); + assertLastEmail(mailer, notification); - expected = "Your Vespa Cloud trial expires in **2** days. [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; + expectedConsoleNotification = "Your Vespa Cloud trial expires in **2** days. [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; clock.advance(Duration.ofDays(5)); assertEquals(0.0, expirer.maintain()); - assertEquals(expected, lastAccountLevelNotificationTitle(tenant)); - assertLastEmailEquals(mailer, "trial-expiring-soon.html"); + notification = lastAccountLevelNotification(tenant); + assertEquals(expectedConsoleNotification, notification.title()); + assertLastEmail(mailer, notification); - expected = "Your Vespa Cloud trial expires **tomorrow**. [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; + expectedConsoleNotification = "Your Vespa Cloud trial expires **tomorrow**. [Manage plan](https://console.tld/tenant/trial-tenant/account/billing)"; clock.advance(Duration.ofDays(1)); assertEquals(0.0, expirer.maintain()); - assertEquals(expected, lastAccountLevelNotificationTitle(tenant)); - assertLastEmailEquals(mailer, "trial-expiring-immediately.html"); + notification = lastAccountLevelNotification(tenant); + assertEquals(expectedConsoleNotification, notification.title()); + assertLastEmail(mailer, notification); - expected = "Your Vespa Cloud trial has expired. [Upgrade plan](https://console.tld/tenant/trial-tenant/account/billing)"; + expectedConsoleNotification = "Your Vespa Cloud trial has expired. [Upgrade plan](https://console.tld/tenant/trial-tenant/account/billing)"; clock.advance(Duration.ofDays(2)); assertEquals(0.0, expirer.maintain()); - assertEquals(expected, lastAccountLevelNotificationTitle(tenant)); - assertLastEmailEquals(mailer, "trial-expired.html"); + notification = lastAccountLevelNotification(tenant); + assertEquals(expectedConsoleNotification, notification.title()); + assertLastEmail(mailer, notification); } - private void assertLastEmailEquals(MockMailer mailer, String expectedContentFile) throws IOException { + private void assertLastEmail(MockMailer mailer, Notification notification) throws IOException { var mails = mailer.inbox("dev-trial-tenant"); assertFalse(mails.isEmpty()); var content = mails.get(mails.size() - 1).htmlMessage().orElseThrow(); - var path = Paths.get("src/test/resources/mail/" + expectedContentFile); + var templateName = notification.mailContent().orElseThrow().values().get("mailMessageTemplate"); + var path = Paths.get("src/test/resources/mail/%s.html".formatted(templateName)); if (OVERWRITE_TEST_FILES) { Files.write(path, content.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE); @@ -175,11 +183,10 @@ public class CloudTrialExpirerTest { assertEquals(planId, tester.serviceRegistry().billingController().getPlan(TenantName.from(tenant)).value()); } - private String lastAccountLevelNotificationTitle(TenantName tenant) { + private Notification lastAccountLevelNotification(TenantName tenant) { return tester.controller().notificationsDb() .listNotifications(NotificationSource.from(tenant), false).stream() - .filter(n -> n.type() == Notification.Type.account).map(Notification::title) + .filter(n -> n.type() == Notification.Type.account) .findFirst().orElseThrow(); } - } diff --git a/controller-server/src/test/resources/mail/trial-expiring-immediately.html b/controller-server/src/test/resources/mail/trial-expires-immediately.html index db89eca195a..db89eca195a 100644 --- a/controller-server/src/test/resources/mail/trial-expiring-immediately.html +++ b/controller-server/src/test/resources/mail/trial-expires-immediately.html diff --git a/controller-server/src/test/resources/mail/trial-expiring-soon.html b/controller-server/src/test/resources/mail/trial-expires-soon.html index 17c59240cc4..17c59240cc4 100644 --- a/controller-server/src/test/resources/mail/trial-expiring-soon.html +++ b/controller-server/src/test/resources/mail/trial-expires-soon.html diff --git a/controller-server/src/test/resources/mail/trial-reminder.html b/controller-server/src/test/resources/mail/trial-midway-checkin.html index fbe0d573538..fbe0d573538 100644 --- a/controller-server/src/test/resources/mail/trial-reminder.html +++ b/controller-server/src/test/resources/mail/trial-midway-checkin.html diff --git a/controller-server/src/test/resources/mail/welcome.html b/controller-server/src/test/resources/mail/trial-signed-up.html index 2e652532db8..2e652532db8 100644 --- a/controller-server/src/test/resources/mail/welcome.html +++ b/controller-server/src/test/resources/mail/trial-signed-up.html |