|
2 | 2 |
|
3 | 3 | import com.objectcomputing.checkins.services.TestContainersSuite; |
4 | 4 | import com.objectcomputing.checkins.services.feedback_request.FeedbackRequest; |
5 | | -import com.objectcomputing.checkins.services.feedback_request.FeedbackRequestRepository; |
6 | | -import com.objectcomputing.checkins.services.feedback_request.FeedbackRequestServicesImpl; |
| 5 | +import com.objectcomputing.checkins.services.feedback_template.FeedbackTemplate; |
| 6 | +import com.objectcomputing.checkins.services.fixture.FeedbackRequestFixture; |
| 7 | +import com.objectcomputing.checkins.services.fixture.FeedbackTemplateFixture; |
7 | 8 | import com.objectcomputing.checkins.services.pulse.PulseServices; |
8 | 9 | import com.objectcomputing.checkins.services.reviews.ReviewPeriodServices; |
| 10 | +import com.objectcomputing.checkins.notifications.email.MailJetFactory; |
| 11 | +import com.objectcomputing.checkins.services.MailJetFactoryReplacement; |
| 12 | +import com.objectcomputing.checkins.services.fixture.MemberProfileFixture; |
| 13 | +import com.objectcomputing.checkins.services.memberprofile.MemberProfile; |
9 | 14 | import org.junit.jupiter.api.AfterEach; |
10 | 15 | import org.junit.jupiter.api.BeforeEach; |
11 | 16 | import org.junit.jupiter.api.Test; |
12 | 17 | import org.junit.jupiter.api.condition.DisabledInNativeImage; |
13 | | -import org.mockito.InjectMocks; |
14 | | -import org.mockito.Mock; |
15 | | -import org.mockito.MockitoAnnotations; |
| 18 | + |
| 19 | +import io.micronaut.context.annotation.Property; |
| 20 | +import io.micronaut.core.util.StringUtils; |
| 21 | +import jakarta.inject.Inject; |
| 22 | +import jakarta.inject.Named; |
16 | 23 |
|
17 | 24 | import java.util.Collections; |
18 | 25 | import java.util.List; |
19 | 26 |
|
20 | | -import static org.mockito.ArgumentMatchers.any; |
21 | | -import static org.mockito.ArgumentMatchers.eq; |
22 | | -import static org.mockito.Mockito.verify; |
23 | | -import static org.mockito.Mockito.when; |
24 | | - |
25 | | -// Disabled in nativeTest, as we get an exception from Mockito |
26 | | -// => java.lang.NoClassDefFoundError: Could not initialize class org.mockito.internal.configuration.plugins.Plugins |
27 | | -@DisabledInNativeImage |
28 | | -class CheckServicesImplTest extends TestContainersSuite { |
29 | | - |
30 | | - @Mock |
31 | | - private FeedbackRequestServicesImpl feedbackRequestServices; |
| 27 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
32 | 28 |
|
33 | | - @Mock |
34 | | - private FeedbackRequestRepository feedbackRequestRepository; |
| 29 | +@Property(name = "replace.mailjet.factory", value = StringUtils.TRUE) |
| 30 | +class CheckServicesImplTest extends TestContainersSuite |
| 31 | + implements FeedbackTemplateFixture, FeedbackRequestFixture, MemberProfileFixture { |
35 | 32 |
|
36 | | - @Mock |
37 | | - private PulseServices pulseServices; |
| 33 | + @Inject |
| 34 | + @Named(MailJetFactory.MJML_FORMAT) |
| 35 | + private MailJetFactoryReplacement.MockEmailSender emailSender; |
38 | 36 |
|
39 | | - @Mock |
40 | | - private ReviewPeriodServices reviewPeriodServices; |
41 | | - |
42 | | - @InjectMocks |
| 37 | + @Inject |
43 | 38 | private CheckServicesImpl checkServices; |
44 | 39 |
|
45 | | - AutoCloseable openMocks; |
46 | | - |
47 | 40 | @BeforeEach |
48 | | - void initMocks() { |
49 | | - openMocks = MockitoAnnotations.openMocks(this); |
50 | | - } |
51 | | - |
52 | | - @AfterEach |
53 | | - void resetMocks() throws Exception { |
54 | | - openMocks.close(); |
| 41 | + void resetTest() { |
| 42 | + emailSender.reset(); |
55 | 43 | } |
56 | 44 |
|
57 | 45 | @Test |
58 | 46 | void sendScheduledEmails() { |
59 | | - FeedbackRequest retrievedRequest = new FeedbackRequest(); |
60 | | - retrievedRequest.setStatus("pending"); |
61 | | - List<FeedbackRequest> list = Collections.singletonList(retrievedRequest); |
62 | | - when(feedbackRequestRepository.findBySendDateNotAfterAndStatusEqual(any(),eq("pending"))).thenReturn(list); |
| 47 | + // Create a pending feedback request. |
| 48 | + MemberProfile pdlMemberProfile = createADefaultMemberProfile(); |
| 49 | + MemberProfile employeeMemberProfile = createADefaultMemberProfileForPdl(pdlMemberProfile); |
| 50 | + MemberProfile recipient = createADefaultRecipient(); |
| 51 | + |
| 52 | + FeedbackTemplate template = createFeedbackTemplate(pdlMemberProfile.getId()); |
| 53 | + getFeedbackTemplateRepository().save(template); |
| 54 | + FeedbackRequest retrievedRequest = |
| 55 | + saveSampleFeedbackRequest(pdlMemberProfile, |
| 56 | + employeeMemberProfile, |
| 57 | + recipient, template.getId()); |
| 58 | + |
| 59 | + // Send emails for today |
63 | 60 | checkServices.sendScheduledEmails(); |
64 | | - verify(feedbackRequestServices).sendNewRequestEmail(retrievedRequest); |
65 | | - retrievedRequest.setStatus("sent"); |
66 | | - verify(feedbackRequestRepository).update(retrievedRequest); |
| 61 | + |
| 62 | + // One for the feedback request and one for the pulse email. |
| 63 | + assertEquals(2, emailSender.events.size()); |
| 64 | + assertEquals(pdlMemberProfile.getWorkEmail(), |
| 65 | + emailSender.events.get(0).get(2)); |
| 66 | + assertEquals("Feedback request", |
| 67 | + emailSender.events.get(0).get(3)); |
| 68 | + System.out.println(emailSender.events.get(0)); |
67 | 69 | } |
68 | 70 | } |
0 commit comments