Add a check so newly saved createCostTransitions get recognized and saved to the database (#2335)

* Add a check so newly saved createCostTransitions get recognized and saved to the database

* Fix equals check

* Rename equals method

* Add comment explaining need for createBillingCostTransitionEqualCheck
This commit is contained in:
sarahcaseybot 2024-02-28 14:21:58 -05:00 committed by GitHub
parent a4bd85068b
commit 02fd6d4756
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View file

@ -138,7 +138,10 @@ public class Tld extends ImmutableObject implements Buildable, UnsafeSerializabl
try { try {
String thisYaml = mapper.writeValueAsString(this); String thisYaml = mapper.writeValueAsString(this);
String otherYaml = mapper.writeValueAsString(tldToCompare); String otherYaml = mapper.writeValueAsString(tldToCompare);
return thisYaml.equals(otherYaml); // Since Jackson uses getters and not field values to construct the YAML representation, an
// explicit check of the createBillingCostTransitions is necessary since this field is
// auto-populated in the getter when the field is set to null.
return thisYaml.equals(otherYaml) && createBillingCostTransitionsEqual(tldToCompare);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -692,6 +695,15 @@ public class Tld extends ImmutableObject implements Buildable, UnsafeSerializabl
.toValueMap(); .toValueMap();
} }
public boolean createBillingCostTransitionsEqual(Tld newTld) {
if (createBillingCostTransitions == null) {
return false;
}
return createBillingCostTransitions
.toValueMap()
.equals(newTld.getCreateBillingCostTransitions());
}
/** /**
* Returns the add-on cost of a domain restore (the flat tld-wide fee charged in addition to one * Returns the add-on cost of a domain restore (the flat tld-wide fee charged in addition to one
* year of renewal for that name). * year of renewal for that name).

View file

@ -140,6 +140,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
tld.asBuilder() tld.asBuilder()
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN)) .setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
.setCreateBillingCostTransitions(
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
.build()); .build());
File tldFile = tmpDir.resolve("idns.yaml").toFile(); File tldFile = tmpDir.resolve("idns.yaml").toFile();
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml")); Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml"));
@ -149,6 +151,22 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
.hasLogAtLevelWithMessage(INFO, "TLD YAML file contains no new changes"); .hasLogAtLevelWithMessage(INFO, "TLD YAML file contains no new changes");
} }
@Test
void testSuccess_addCreateCostTransitions_hasDiff() throws Exception {
Tld tld = createTld("idns");
persistResource(
tld.asBuilder()
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
.build());
File tldFile = tmpDir.resolve("idns.yaml").toFile();
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml"));
runCommandForced("--input=" + tldFile);
Tld updatedTld = Tld.get("idns");
testTldConfiguredSuccessfully(updatedTld, "idns.yaml");
assertThat(tld.createBillingCostTransitionsEqual(updatedTld)).isFalse();
}
@Test @Test
void testSuccess_outOfOrderFieldsOnCreate() throws Exception { void testSuccess_outOfOrderFieldsOnCreate() throws Exception {
File tldFile = tmpDir.resolve("outoforderfields.yaml").toFile(); File tldFile = tmpDir.resolve("outoforderfields.yaml").toFile();
@ -580,6 +598,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
tld.asBuilder() tld.asBuilder()
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN)) .setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
.setCreateBillingCostTransitions(
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
.build()); .build());
File tldFile = tmpDir.resolve("idns.yaml").toFile(); File tldFile = tmpDir.resolve("idns.yaml").toFile();
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml")); Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml"));
@ -626,6 +646,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
tld.asBuilder() tld.asBuilder()
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN)) .setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
.setCreateBillingCostTransitions(
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
.setBreakglassMode(true) .setBreakglassMode(true)
.build()); .build());
File tldFile = tmpDir.resolve("idns.yaml").toFile(); File tldFile = tmpDir.resolve("idns.yaml").toFile();
@ -645,6 +667,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
tld.asBuilder() tld.asBuilder()
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN)) .setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
.setCreateBillingCostTransitions(
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
.setBreakglassMode(true) .setBreakglassMode(true)
.build()); .build());
File tldFile = tmpDir.resolve("idns.yaml").toFile(); File tldFile = tmpDir.resolve("idns.yaml").toFile();