summaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@vespa.ai>2023-10-30 10:59:19 +0100
committerBjørn Christian Seime <bjorncs@vespa.ai>2023-10-30 10:59:19 +0100
commit1abe5ce96b8708c781edeab654c2347157cdc4b0 (patch)
treed7a36c3098fbe1d4679e466ad6ac7130b457bba4 /controller-server/src/test/java/com/yahoo
parentf61444b7c981a8ecb2c131ad1a5f8bcd2de5ebfd (diff)
Simplify unit test for trial notifications
Use same file name as original template
Diffstat (limited to 'controller-server/src/test/java/com/yahoo')
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java49
1 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();
}
-
}