mirror of
https://github.com/google/nomulus
synced 2026-09-10 10:06:25 +00:00
Grandfather in old data for one-time billing event requirement (#1423)
* Grandfather in old data for one-time billing event requirement We have data from 2018 and earlier where we didn't consistently set periodYears for OneTime BillingEvents with certain reasons. This grandfathers in that old data so that we can successfully move it over to Cloud SQL for now, then we can later run a query that will backfill it, after which we can then tighten up the requirement again. Note that the requirement is still being enforced for all billing events from 2019 onwards. This also improves the handling of validation, by adding a private field to the Reason enum rather than creating a throwaway inline ImmmutableSet in the Builder.
This commit is contained in:
@@ -416,4 +416,62 @@ public class BillingEventTest extends EntityTestCase {
|
||||
assertThat(recurring.getParentKey()).isEqualTo(Key.create(domainHistory));
|
||||
new BillingEvent.OneTime.Builder().setParent(Key.create(domainHistory));
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testReasonRequiringPeriodYears_missingPeriodYears_throwsException() {
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setBillingTime(DateTime.parse("2020-02-05T15:33:11Z"))
|
||||
.setEventTime(DateTime.parse("2020-01-05T15:33:11Z"))
|
||||
.setCost(Money.of(USD, 10))
|
||||
.setReason(Reason.RENEW)
|
||||
.setCost(Money.of(USD, 10))
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setTargetId("example.tld")
|
||||
.setParent(domainHistory)
|
||||
.build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Period years must be set if and only if reason is");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testReasonNotRequiringPeriodYears_havingPeriodYears_throwsException() {
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setBillingTime(DateTime.parse("2020-02-05T15:33:11Z"))
|
||||
.setEventTime(DateTime.parse("2020-01-05T15:33:11Z"))
|
||||
.setCost(Money.of(USD, 10))
|
||||
.setPeriodYears(2)
|
||||
.setReason(Reason.SERVER_STATUS)
|
||||
.setCost(Money.of(USD, 10))
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setTargetId("example.tld")
|
||||
.setParent(domainHistory)
|
||||
.build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Period years must be set if and only if reason is");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testReasonRequiringPeriodYears_missingPeriodYears_isAllowedOnOldData() {
|
||||
// This won't throw even though periodYears is missing on a RESTORE because the event time
|
||||
// is before 2019.
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setBillingTime(DateTime.parse("2018-02-05T15:33:11Z"))
|
||||
.setEventTime(DateTime.parse("2018-01-05T15:33:11Z"))
|
||||
.setReason(Reason.RESTORE)
|
||||
.setCost(Money.of(USD, 10))
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setTargetId("example.tld")
|
||||
.setParent(domainHistory)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user