Require token transition schedules for default tokens (#2005)

This commit is contained in:
sarahcaseybot 2023-04-21 17:38:10 -04:00 committed by GitHub
parent 2c258cd1bd
commit d4a91ce65a
2 changed files with 15 additions and 0 deletions

View file

@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.billing.BillingEvent.RenewalPriceBehavior.DEFAULT;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
@ -259,6 +260,10 @@ class GenerateAllocationTokensCommand implements Command {
!(UNLIMITED_USE.equals(tokenType) && CollectionUtils.isNullOrEmpty(tokenStatusTransitions)),
"For UNLIMITED_USE tokens, must specify --token_status_transitions");
checkArgument(
!(DEFAULT_PROMO.equals(tokenType) && CollectionUtils.isNullOrEmpty(tokenStatusTransitions)),
"For DEFAULT_PROMO tokens, must specify --token_status_transitions");
// A list consisting solely of the empty string means user error when formatting parameters
checkArgument(
!ImmutableList.of("").equals(allowedClientIds),

View file

@ -440,6 +440,16 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
.isEqualTo("For UNLIMITED_USE tokens, must specify --token_status_transitions");
}
@Test
void testFailure_defaultPromoMustHaveTransitions() {
assertThat(
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--number", "999", "--type", "DEFAULT_PROMO")))
.hasMessageThat()
.isEqualTo("For DEFAULT_PROMO tokens, must specify --token_status_transitions");
}
private AllocationToken createToken(
String token,
@Nullable HistoryEntryId redemptionHistoryEntryId,