Create a separate billing event when EAP is applied

When EAP is involed we current have one billing event for domain create that
has the create fee and EAP fee lumped together. Change it to record two
separate billing events for each.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132335349
This commit is contained in:
jianglai
2016-09-07 12:00:28 -04:00
committed by Ben McIlwain
parent 969d9483ae
commit 6641f105b7
12 changed files with 196 additions and 72 deletions
@@ -169,9 +169,6 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
? Money.of(USD, 200)
: Money.of(USD, 26);
Money eapFee = Registry.get(domainTld).getEapFeeFor(clock.nowUtc()).getCost();
if (!eapFee.isZero()) {
cost = Money.total(cost, eapFee);
}
DateTime billingTime = isAnchorTenant
? clock.nowUtc().plus(Registry.get(domainTld).getAnchorTenantAddGracePeriodLength())
@@ -186,20 +183,21 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_CREATE).and()
.hasPeriodYears(2);
// There should be a bill for the create and a recurring autorenew event.
BillingEvent.OneTime createBillingEvent = new BillingEvent.OneTime.Builder()
.setReason(Reason.CREATE)
.setTargetId(getUniqueIdFromCommand())
.setClientId("TheRegistrar")
.setCost(cost)
.setPeriodYears(2)
.setEventTime(clock.nowUtc())
.setBillingTime(billingTime)
.setFlags(billingFlags)
.setParent(historyEntry)
.build();
assertBillingEvents(
createBillingEvent,
// There should be one bill for the create and one for the recurring autorenew event.
BillingEvent.OneTime createBillingEvent =
new BillingEvent.OneTime.Builder()
.setReason(Reason.CREATE)
.setTargetId(getUniqueIdFromCommand())
.setClientId("TheRegistrar")
.setCost(cost)
.setPeriodYears(2)
.setEventTime(clock.nowUtc())
.setBillingTime(billingTime)
.setFlags(billingFlags)
.setParent(historyEntry)
.build();
BillingEvent.Recurring renewBillingEvent =
new BillingEvent.Recurring.Builder()
.setReason(Reason.RENEW)
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
@@ -208,7 +206,36 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setEventTime(domain.getRegistrationExpirationTime())
.setRecurrenceEndTime(END_OF_TIME)
.setParent(historyEntry)
.build());
.build();
ImmutableSet<BillingEvent> billingEvents = ImmutableSet.of(
createBillingEvent, renewBillingEvent);
// If EAP is applied, a billing event for EAP should be present.
if (!eapFee.isZero()) {
ImmutableSet<BillingEvent.Flag> eapFlags =
isAnchorTenant
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT, BillingEvent.Flag.EAP)
: ImmutableSet.of(BillingEvent.Flag.EAP);
BillingEvent.OneTime eapBillingEvent =
new BillingEvent.OneTime.Builder()
.setReason(Reason.CREATE)
.setTargetId(getUniqueIdFromCommand())
.setClientId("TheRegistrar")
.setCost(eapFee)
.setPeriodYears(2)
.setEventTime(clock.nowUtc())
.setBillingTime(billingTime)
.setFlags(eapFlags)
.setParent(historyEntry)
.build();
billingEvents = ImmutableSet.<BillingEvent>builder()
.addAll(billingEvents)
.add(eapBillingEvent)
.build();
}
assertBillingEvents(billingEvents);
assertGracePeriods(
domain.getGracePeriods(),
ImmutableMap.of(
@@ -24,6 +24,7 @@ enum google.registry.model.billing.BillingEvent$Flag {
ALLOCATION;
ANCHOR_TENANT;
AUTO_RENEW;
EAP;
LANDRUSH;
SUNRISE;
SYNTHETIC;
@@ -22,6 +22,7 @@ import static org.joda.money.CurrencyUnit.USD;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMap;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Fee;
import google.registry.model.ofy.Ofy;
import google.registry.model.registry.Registry;
@@ -88,18 +89,18 @@ public class TldSpecificLogicProxyTest {
assertThat(createPrice.getTotalCost()).isEqualTo(basicCreateCost.plus(Money.of(USD, 100)));
assertThat(createPrice.getCurrency()).isEqualTo(USD);
assertThat(createPrice.getFees().get(0))
.isEqualTo(Fee.create(basicCreateCost.getAmount(), "create"));
.isEqualTo(Fee.create(basicCreateCost.getAmount(), FeeType.CREATE));
assertThat(createPrice.getFees().get(1))
.isEqualTo(
Fee.create(
Money.of(USD, 100).getAmount(),
"Early Access Period, fee expires: " + clock.nowUtc().plusDays(1)));
Money.of(USD, 100).getAmount(), FeeType.EAP, clock.nowUtc().plusDays(1)));
assertThat(createPrice.getFees())
.isEqualTo(
ImmutableList.of(
Fee.create(basicCreateCost.getAmount(), "create"),
Fee.create(basicCreateCost.getAmount(), FeeType.CREATE),
Fee.create(
Money.of(USD, 100).getAmount(),
"Early Access Period, fee expires: " + clock.nowUtc().plusDays(1))));
FeeType.EAP,
clock.nowUtc().plusDays(1))));
}
}
@@ -608,6 +608,13 @@ public class DatastoreHelper {
FluentIterable.from(asList(expected)).transform(BILLING_EVENT_ID_STRIPPER));
}
/** Assert that the expected billing events set is exactly the one found in the fake datastore. */
public static void assertBillingEvents(ImmutableSet<BillingEvent> expected) throws Exception {
assertThat(FluentIterable.from(getBillingEvents()).transform(BILLING_EVENT_ID_STRIPPER))
.containsExactlyElementsIn(
FluentIterable.from(expected.asList()).transform(BILLING_EVENT_ID_STRIPPER));
}
/**
* Assert that the expected billing events are exactly the ones found for the given EppResource.
*/