use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.
the class RefundDaoJpaIT method updateParityCheckStatus_shouldUpdateParityCheckColumnsOnRefundCorrectly.
@Test
public void updateParityCheckStatus_shouldUpdateParityCheckColumnsOnRefundCorrectly() {
RefundEntity refundEntity = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
refundEntity.setStatus(CREATED);
refundDao.persist(refundEntity);
Optional<RefundEntity> mayBeRefundEntityFromDB = refundDao.findByExternalId(refundEntity.getExternalId());
List<RefundHistory> refundHistoryList = refundDao.getRefundHistoryByRefundExternalId(refundEntity.getExternalId());
assertThat(mayBeRefundEntityFromDB.get().getParityCheckDate(), is(nullValue()));
assertThat(mayBeRefundEntityFromDB.get().getParityCheckStatus(), is(nullValue()));
assertThat(refundHistoryList.size(), is(1));
ZonedDateTime parityCheckDate = ZonedDateTime.now(UTC);
refundDao.updateParityCheckStatus(refundEntity.getExternalId(), parityCheckDate, MISSING_IN_LEDGER);
mayBeRefundEntityFromDB = refundDao.findByExternalId(refundEntity.getExternalId());
refundHistoryList = refundDao.getRefundHistoryByRefundExternalId(refundEntity.getExternalId());
assertThat(mayBeRefundEntityFromDB.get().getParityCheckDate().toLocalDateTime(), is(parityCheckDate.toLocalDateTime()));
assertThat(mayBeRefundEntityFromDB.get().getParityCheckStatus(), is(MISSING_IN_LEDGER));
assertThat(refundHistoryList.size(), is(1));
}
use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.
the class RefundDaoJpaIT method shouldSearchAllHistoryStatusTypesByChargeId.
@Test
public void shouldSearchAllHistoryStatusTypesByChargeId() {
RefundEntity refundEntity = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
refundEntity.setGatewayTransactionId(refundGatewayTransactionId);
refundEntity.setStatus(CREATED);
refundDao.persist(refundEntity);
refundEntity.setStatus(REFUND_SUBMITTED);
refundDao.merge(refundEntity);
List<RefundHistory> refundHistoryList = refundDao.searchAllHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
assertThat(refundHistoryList.size(), is(2));
}
use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.
the class RefundDaoJpaIT method persist_shouldSearchHistoryByChargeExternalId.
@Test
public void persist_shouldSearchHistoryByChargeExternalId() {
RefundEntity refundEntity = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
refundEntity.setStatus(REFUND_SUBMITTED);
refundEntity.setGatewayTransactionId(refundGatewayTransactionId);
refundDao.persist(refundEntity);
List<RefundHistory> refundHistoryList = refundDao.searchHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
assertThat(refundHistoryList.size(), is(1));
RefundHistory refundHistory = refundHistoryList.get(0);
assertThat(refundHistory.getId(), is(refundEntity.getId()));
assertThat(refundHistory.getExternalId(), is(refundEntity.getExternalId()));
assertThat(refundHistory.getAmount(), is(refundEntity.getAmount()));
assertThat(refundHistory.getStatus(), is(refundEntity.getStatus()));
assertThat(refundHistory.getUserEmail(), is(refundEntity.getUserEmail()));
assertThat(refundHistory.getCreatedDate(), is(refundEntity.getCreatedDate()));
assertThat(refundHistory.getVersion(), is(refundEntity.getVersion()));
assertThat(refundEntity.getUserExternalId(), is(userExternalId));
assertThat(refundEntity.getUserEmail(), is(refundEntity.getUserEmail()));
assertThat(refundHistory.getUserExternalId(), is(refundEntity.getUserExternalId()));
assertThat(refundHistory.getGatewayTransactionId(), is(refundEntity.getGatewayTransactionId()));
assertThat(refundHistory.getChargeExternalId(), is(chargeTestRecord.getExternalChargeId()));
}
use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.
the class RefundDaoJpaIT method expungeRefund_shouldExpungeRefundRelatedRecordsCorrectly.
@Test
public void expungeRefund_shouldExpungeRefundRelatedRecordsCorrectly() {
RefundEntity refundToExpunge = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
refundToExpunge.setStatus(REFUNDED);
refundDao.persist(refundToExpunge);
RefundEntity refundToNotBeExpunged = new RefundEntity(100L, userExternalId, userEmail, chargeTestRecord.getExternalChargeId());
refundToNotBeExpunged.setStatus(REFUND_ERROR);
refundDao.persist(refundToNotBeExpunged);
emittedEventDao.persist(anEmittedEventEntity().withResourceExternalId(refundToExpunge.getExternalId()).withResourceType("refund").withId(RandomUtils.nextLong()).build());
// assert data is as expected
Optional<RefundEntity> mayBeRefundEntity = refundDao.findByExternalId(refundToExpunge.getExternalId());
List<RefundHistory> refundHistoryList = refundDao.searchHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
boolean containsEmittedEventForRefundExternalId = databaseTestHelper.containsEmittedEventWithExternalId(refundToExpunge.getExternalId());
assertThat(containsEmittedEventForRefundExternalId, is(true));
assertThat(mayBeRefundEntity.isPresent(), Matchers.is(true));
assertThat(refundHistoryList.size(), Matchers.is(2));
// act
refundDao.expungeRefund(refundToExpunge.getExternalId());
mayBeRefundEntity = refundDao.findByExternalId(refundToExpunge.getExternalId());
refundHistoryList = refundDao.searchHistoryByChargeExternalId(chargeTestRecord.getExternalChargeId());
containsEmittedEventForRefundExternalId = databaseTestHelper.containsEmittedEventWithExternalId(refundToExpunge.getExternalId());
assertThat(mayBeRefundEntity.isPresent(), Matchers.is(false));
assertThat(refundHistoryList.size(), Matchers.is(1));
assertThat(containsEmittedEventForRefundExternalId, is(false));
}
use of uk.gov.pay.connector.refund.model.domain.RefundHistory in project pay-connector by alphagov.
the class EventFactoryTest method shouldCreateCorrectEventsFromRefundCreatedStateTransition.
@Test
public void shouldCreateCorrectEventsFromRefundCreatedStateTransition() throws Exception {
when(chargeService.findCharge(charge.getExternalId())).thenReturn(Optional.of(Charge.from(charge)));
RefundHistory refundCreatedHistory = RefundHistoryEntityFixture.aValidRefundHistoryEntity().withStatus(RefundStatus.CREATED.getValue()).withUserExternalId("user_external_id").withUserEmail("test@example.com").withChargeExternalId(charge.getExternalId()).withAmount(charge.getAmount()).build();
when(refundDao.getRefundHistoryByRefundExternalIdAndRefundStatus(refundCreatedHistory.getExternalId(), refundCreatedHistory.getStatus())).thenReturn(Optional.of(refundCreatedHistory));
StateTransition refundStateTransition = new RefundStateTransition(refundCreatedHistory.getExternalId(), refundCreatedHistory.getStatus(), RefundCreatedByUser.class);
List<Event> refundEvents = eventFactory.createEvents(refundStateTransition);
assertThat(refundEvents.size(), is(2));
RefundCreatedByUser refundCreatedByUser = (RefundCreatedByUser) refundEvents.stream().filter(e -> ResourceType.REFUND.equals(e.getResourceType())).findFirst().get();
RefundCreatedByUserEventDetails eventDetails = (RefundCreatedByUserEventDetails) refundCreatedByUser.getEventDetails();
assertThat(refundCreatedByUser.getParentResourceExternalId(), is(charge.getExternalId()));
assertThat(eventDetails.getRefundedBy(), is("user_external_id"));
assertThat(eventDetails.getUserEmail(), is("test@example.com"));
assertThat(refundCreatedByUser.getResourceType(), is(ResourceType.REFUND));
assertThat(refundCreatedByUser.getEventDetails(), is(instanceOf(RefundCreatedByUserEventDetails.class)));
RefundAvailabilityUpdated refundAvailabilityUpdated = (RefundAvailabilityUpdated) refundEvents.stream().filter(e -> ResourceType.PAYMENT.equals(e.getResourceType())).findFirst().get();
assertThat(refundAvailabilityUpdated.getResourceExternalId(), is(charge.getExternalId()));
assertThat(refundAvailabilityUpdated.getResourceType(), is(ResourceType.PAYMENT));
assertThat(refundAvailabilityUpdated.getEventDetails(), is(instanceOf(RefundAvailabilityUpdatedEventDetails.class)));
}
Aggregations