-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VKT(Backend): OPHVKTKEH-180 backend test for setting refund
- Loading branch information
Showing
3 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
backend/vkt/src/test/java/fi/oph/vkt/service/ClerkPaymentServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package fi.oph.vkt.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import fi.oph.vkt.Factory; | ||
import fi.oph.vkt.api.dto.clerk.ClerkPaymentDTO; | ||
import fi.oph.vkt.audit.AuditService; | ||
import fi.oph.vkt.audit.VktOperation; | ||
import fi.oph.vkt.audit.dto.ClerkPaymentAuditDTO; | ||
import fi.oph.vkt.model.Enrollment; | ||
import fi.oph.vkt.model.ExamEvent; | ||
import fi.oph.vkt.model.Payment; | ||
import fi.oph.vkt.model.Person; | ||
import fi.oph.vkt.repository.PaymentRepository; | ||
import fi.oph.vkt.util.ClerkPaymentUtil; | ||
import fi.oph.vkt.util.UUIDSource; | ||
import jakarta.annotation.Resource; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
|
||
@WithMockUser | ||
@DataJpaTest | ||
public class ClerkPaymentServiceTest { | ||
|
||
@Resource | ||
private PaymentRepository paymentRepository; | ||
|
||
@MockBean | ||
private AuditService auditService; | ||
|
||
private ClerkPaymentService clerkPaymentService; | ||
|
||
@Resource | ||
private TestEntityManager entityManager; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
final Environment environment = mock(Environment.class); | ||
when(environment.getRequiredProperty("app.base-url.api")).thenReturn("http://localhost"); | ||
|
||
final UUIDSource uuidSource = mock(UUIDSource.class); | ||
when(uuidSource.getRandomNonce()).thenReturn("269a2da4-58bb-45eb-b125-522b77e9167c"); | ||
|
||
clerkPaymentService = new ClerkPaymentService(paymentRepository, auditService); | ||
} | ||
|
||
@Test | ||
public void testSetRefunded() { | ||
final ExamEvent examEvent = Factory.examEvent(); | ||
final Person person = Factory.person(); | ||
final Enrollment enrollment = Factory.enrollment(examEvent, person); | ||
final Payment payment1 = Factory.payment(enrollment); | ||
final Payment payment2 = Factory.payment(enrollment); | ||
|
||
entityManager.persist(examEvent); | ||
entityManager.persist(person); | ||
entityManager.persist(enrollment); | ||
entityManager.persist(payment1); | ||
entityManager.persist(payment2); | ||
|
||
final ClerkPaymentAuditDTO oldAuditDto = ClerkPaymentUtil.createClerkPaymentAuditDTO(payment1); | ||
final ClerkPaymentDTO responseDTO = clerkPaymentService.setRefunded(payment1.getId()); | ||
final ClerkPaymentAuditDTO newAuditDto = ClerkPaymentUtil.createClerkPaymentAuditDTO(payment1); | ||
|
||
assertEquals(payment1.getId(), responseDTO.id()); | ||
assertNotNull(responseDTO.refundedAt()); | ||
assertNull(payment2.getRefundedAt()); | ||
|
||
verify(auditService).logUpdate(VktOperation.REFUND_PAYMENT, payment1.getId(), oldAuditDto, newAuditDto); | ||
} | ||
} |