|
|
|
@ -41,6 +41,34 @@ class JdbcExperimentAttemptRepositoryTest {
|
|
|
|
assertEquals(second.getId(), repository.findCurrent(ExperimentModule.EXCHANGE, subject).get().getId());
|
|
|
|
assertEquals(second.getId(), repository.findCurrent(ExperimentModule.EXCHANGE, subject).get().getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void findLatestReturnsCompletedAttemptButCurrentDoesNot() {
|
|
|
|
|
|
|
|
ExperimentSubject subject = new ExperimentSubject("user-latest", 10L, 20L, "ORG-1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExperimentAttempt first = repository.create(ExperimentModule.EXCHANGE, subject);
|
|
|
|
|
|
|
|
first.complete(java.time.Instant.now());
|
|
|
|
|
|
|
|
repository.save(first);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(repository.findCurrent(ExperimentModule.EXCHANGE, subject).isPresent());
|
|
|
|
|
|
|
|
assertEquals(first.getId(), repository.findLatest(ExperimentModule.EXCHANGE, subject).get().getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void findLatestSkipsCancelledAttemptsAndPrefersTheNewestOne() {
|
|
|
|
|
|
|
|
ExperimentSubject subject = new ExperimentSubject("user-latest-2", 10L, 20L, "ORG-1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExperimentAttempt first = repository.create(ExperimentModule.EXCHANGE, subject);
|
|
|
|
|
|
|
|
first.complete(java.time.Instant.now());
|
|
|
|
|
|
|
|
repository.save(first);
|
|
|
|
|
|
|
|
ExperimentAttempt second = repository.create(ExperimentModule.EXCHANGE, subject);
|
|
|
|
|
|
|
|
assertEquals(second.getId(), repository.findLatest(ExperimentModule.EXCHANGE, subject).get().getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
second.cancel();
|
|
|
|
|
|
|
|
repository.save(second);
|
|
|
|
|
|
|
|
assertEquals(first.getId(), repository.findLatest(ExperimentModule.EXCHANGE, subject).get().getId());
|
|
|
|
|
|
|
|
assertFalse(repository.findLatest(ExperimentModule.PAYMENT, subject).isPresent());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void scopesAttemptReadsToUserSchoolClassAndOrganization() {
|
|
|
|
void scopesAttemptReadsToUserSchoolClassAndOrganization() {
|
|
|
|
ExperimentSubject owner = new ExperimentSubject("user-1", 10L, 20L, "ORG-1");
|
|
|
|
ExperimentSubject owner = new ExperimentSubject("user-1", 10L, 20L, "ORG-1");
|
|
|
|
|