Add cloneProjectedInTime() to ResaveAllEppResources mapreduce

We're planning on adding a cronjob to run this mapreduce monthly, so
we may as well also project the resources being re-saved to the present
time so as to handle pending transfers, grace periods, and such. This will
make the BigQuery exports more useful.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168831056
This commit is contained in:
mcilwain 2017-09-15 07:08:38 -07:00 committed by jianglai
parent 04a61794e0
commit 3a9d7f9b70
2 changed files with 32 additions and 4 deletions

View file

@ -17,8 +17,11 @@ package google.registry.tools.server;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistContactWithPendingTransfer;
import static org.joda.time.DateTimeZone.UTC;
import google.registry.model.contact.ContactResource;
import google.registry.model.transfer.TransferStatus;
import google.registry.testing.FakeResponse;
import google.registry.testing.mapreduce.MapreduceTestCase;
import org.joda.time.DateTime;
@ -55,4 +58,25 @@ public class ResaveAllEppResourcesActionTest
assertThat(ofy().load().entity(contact).now().getUpdateAutoTimestamp().getTimestamp())
.isGreaterThan(creationTime);
}
@Test
public void test_mapreduceResolvesPendingTransfer() throws Exception {
DateTime now = DateTime.now(UTC);
// Set up a contact with a transfer that implicitly completed five days ago.
ContactResource contact =
persistContactWithPendingTransfer(
persistActiveContact("meh789"),
now.minusDays(10),
now.minusDays(10),
now.minusDays(10));
assertThat(contact.getTransferData().getTransferStatus()).isEqualTo(TransferStatus.PENDING);
runMapreduce();
ofy().clearSessionCache();
// The transfer should be effective after the contact is re-saved, as it should've been
// projected to the current time.
ContactResource resavedContact = ofy().load().entity(contact).now();
assertThat(resavedContact.getTransferData().getTransferStatus())
.isEqualTo(TransferStatus.SERVER_APPROVED);
}
}