From bd4701647b9a9ece8082f4f3662f90dd210aa469 Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Tue, 25 Feb 2025 14:54:56 -0500 Subject: [PATCH] Refactor logic out of domain create flow tests (#2688) This removes logic from an inner helper method so that it becomes more clear from callsites within each test exactly which behavior is expected from those test conditions. --- .../flows/domain/DomainCreateFlowTest.java | 145 ++++++++---------- 1 file changed, 67 insertions(+), 78 deletions(-) diff --git a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java index c78f2fcad..9b29f3b88 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -161,8 +161,6 @@ import google.registry.model.common.FeatureFlag; import google.registry.model.domain.Domain; import google.registry.model.domain.DomainHistory; import google.registry.model.domain.GracePeriod; -import google.registry.model.domain.fee.BaseFee.FeeType; -import google.registry.model.domain.fee.Fee; import google.registry.model.domain.fee.FeeQueryCommandExtensionItem.CommandName; import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.rgp.GracePeriodStatus; @@ -287,59 +285,45 @@ class DomainCreateFlowTest extends ResourceFlowTestCase expectedBillingFlags) + throws Exception { + assertSuccessfulCreate(domainTld, expectedBillingFlags, null, 24, null); + } + private void assertSuccessfulCreate( - String domainTld, ImmutableSet expectedBillingFlags) throws Exception { - assertSuccessfulCreate(domainTld, expectedBillingFlags, null); + String domainTld, ImmutableSet expectedBillingFlags, double createCost) + throws Exception { + assertSuccessfulCreate(domainTld, expectedBillingFlags, null, createCost, null); + } + + private void assertSuccessfulCreate( + String domainTld, ImmutableSet expectedBillingFlags, AllocationToken token) + throws Exception { + assertSuccessfulCreate(domainTld, expectedBillingFlags, token, 24, null); } private void assertSuccessfulCreate( String domainTld, - ImmutableSet expectedBillingFlags, - @Nullable AllocationToken allocationToken) + ImmutableSet expectedBillingFlags, + AllocationToken token, + double createCost) + throws Exception { + assertSuccessfulCreate(domainTld, expectedBillingFlags, token, createCost, null); + } + + private void assertSuccessfulCreate( + String domainTld, + ImmutableSet expectedBillingFlags, + @Nullable AllocationToken token, + double createCost, + @Nullable Integer specifiedRenewCost) throws Exception { Domain domain = reloadResourceByForeignKey(); boolean isAnchorTenant = expectedBillingFlags.contains(ANCHOR_TENANT); // Set up the creation cost. boolean isDomainPremium = isDomainPremium(getUniqueIdFromCommand(), clock.nowUtc()); - BigDecimal createCost = isDomainPremium ? BigDecimal.valueOf(200) : BigDecimal.valueOf(24); - if (isAnchorTenant) { - createCost = BigDecimal.ZERO; - } - if (expectedBillingFlags.contains(SUNRISE)) { - createCost = - createCost.multiply( - BigDecimal.valueOf(1 - RegistryConfig.getSunriseDomainCreateDiscount())); - } - if (allocationToken != null) { - if (allocationToken - .getRegistrationBehavior() - .equals(RegistrationBehavior.NONPREMIUM_CREATE)) { - createCost = - createCost.subtract( - BigDecimal.valueOf(isDomainPremium ? 87 : 0)); // premium is 100, standard 13 - } - if (allocationToken.getRenewalPriceBehavior().equals(NONPREMIUM)) { - createCost = - createCost.subtract( - BigDecimal.valueOf(isDomainPremium ? 89 : 0)); // premium is 100, standard 11 - } - if (allocationToken.getRenewalPriceBehavior().equals(SPECIFIED)) { - createCost = - createCost - .subtract(BigDecimal.valueOf(isDomainPremium ? 100 : 11)) - .add(allocationToken.getRenewalPrice().get().getAmount()); - } - } - FeesAndCredits feesAndCredits = - new FeesAndCredits.Builder() - .setCurrency(USD) - .addFeeOrCredit( - Fee.create( - createCost, - FeeType.CREATE, - isDomainPremium(getUniqueIdFromCommand(), clock.nowUtc()))) - .build(); + Money eapFee = Money.of( Tld.get(domainTld).getCurrency(), @@ -362,7 +346,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase t.createVKey()).orElse(null)) .build(); BillingRecurrence renewBillingEvent = @@ -391,8 +375,8 @@ class DomainCreateFlowTest extends ResourceFlowTestCase Money.of(USD, BigDecimal.valueOf(r))) .orElse(null)) .build(); @@ -480,7 +464,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase