mirror of
https://github.com/google/nomulus.git
synced 2025-07-01 16:53:35 +02:00
Add the ability to nullify the entire billing account map (#1630)
This commit is contained in:
parent
d03cd5bb76
commit
fe89a8cd0b
2 changed files with 21 additions and 9 deletions
|
@ -173,7 +173,8 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
|
|||
"Registrar Billing Account key-value pairs (formatted as key=value[,key=value...]), "
|
||||
+ "where key is a currency unit (USD, JPY, etc) and value is the registrar's billing "
|
||||
+ "account id for that currency. During update, only the pairs that need updating "
|
||||
+ "need to be provided.",
|
||||
+ "need to be provided, except when an empty string is provided, in which case the"
|
||||
+ "entire map is nullified.",
|
||||
converter = CurrencyUnitToStringMap.class,
|
||||
validateWith = CurrencyUnitToStringMap.class)
|
||||
private Map<CurrencyUnit, String> billingAccountMap;
|
||||
|
@ -368,7 +369,9 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
|
|||
Optional.ofNullable(poNumber).ifPresent(builder::setPoNumber);
|
||||
if (billingAccountMap != null) {
|
||||
LinkedHashMap<CurrencyUnit, String> newBillingAccountMap = new LinkedHashMap<>();
|
||||
if (oldRegistrar != null && oldRegistrar.getBillingAccountMap() != null) {
|
||||
if (oldRegistrar != null
|
||||
&& oldRegistrar.getBillingAccountMap() != null
|
||||
&& !billingAccountMap.isEmpty()) {
|
||||
newBillingAccountMap.putAll(oldRegistrar.getBillingAccountMap());
|
||||
}
|
||||
newBillingAccountMap.putAll(billingAccountMap);
|
||||
|
|
|
@ -25,6 +25,7 @@ import static google.registry.testing.DatabaseHelper.newRegistry;
|
|||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.JPY;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
@ -42,7 +43,6 @@ import google.registry.testing.AppEngineExtension;
|
|||
import google.registry.util.CidrAddressBlock;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -368,7 +368,18 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
|
|||
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
|
||||
runCommand("--billing_account_map=USD=abc123,JPY=789xyz", "--force", "NewRegistrar");
|
||||
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap())
|
||||
.containsExactly(CurrencyUnit.USD, "abc123", CurrencyUnit.JPY, "789xyz");
|
||||
.containsExactly(USD, "abc123", JPY, "789xyz");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_billingAccountMap_nullify() throws Exception {
|
||||
persistResource(
|
||||
loadRegistrar("NewRegistrar")
|
||||
.asBuilder()
|
||||
.setBillingAccountMap(ImmutableMap.of(USD, "abc123", JPY, "789xyz"))
|
||||
.build());
|
||||
runCommand("--billing_account_map=\"\"", "--force", "NewRegistrar");
|
||||
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -415,8 +426,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
|
|||
loadRegistrar("NewRegistrar").asBuilder().setBillingAccountMap(ImmutableMap.of()).build());
|
||||
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
|
||||
runCommand("--billing_account_map=JPY=789xyz", "--allowed_tlds=foo", "--force", "NewRegistrar");
|
||||
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap())
|
||||
.containsExactly(CurrencyUnit.JPY, "789xyz");
|
||||
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).containsExactly(JPY, "789xyz");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -425,12 +435,11 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
|
|||
persistResource(
|
||||
loadRegistrar("NewRegistrar")
|
||||
.asBuilder()
|
||||
.setBillingAccountMap(
|
||||
ImmutableMap.of(CurrencyUnit.USD, "abc123", CurrencyUnit.JPY, "789xyz"))
|
||||
.setBillingAccountMap(ImmutableMap.of(USD, "abc123", JPY, "789xyz"))
|
||||
.build());
|
||||
runCommand("--billing_account_map=JPY=123xyz", "--allowed_tlds=foo", "--force", "NewRegistrar");
|
||||
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap())
|
||||
.containsExactly(CurrencyUnit.JPY, "123xyz", CurrencyUnit.USD, "abc123");
|
||||
.containsExactly(JPY, "123xyz", USD, "abc123");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue