Skip to content

Commit

Permalink
feat: test extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazan Amer authored and m-adawi committed Oct 7, 2023
1 parent c8bbf02 commit 0470f7b
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/test/java/org/otherband/email/smtp/SMTPEmailServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,48 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.ArgumentCaptor;
import org.otherband.email.VerificationLinkEmailRequest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

class SMTPEmailServiceTest {
private static final String EXPECTED_ID = "LETTER_ID";
public static final String EXPECTED_EMAIL = "[email protected]";
public static final String TOKEN_ID = "TOKEN_ID";
public static final String SECRET = "SECRET";
private SMTPEmailService service;
private String mailUserName;
private final static String SENDER_EMAIL = "[email protected]";
private JavaMailSender mailSender;

@BeforeEach
void setup() {
mailUserName = "test";
mailSender = mock(JavaMailSender.class);
service = new SMTPEmailService(mailUserName, mailSender);
service = new SMTPEmailService(SENDER_EMAIL, mailSender);
}

@Test
void testSendVerificationEmail() {
VerificationLinkEmailRequest verificationLinkEmailRequest = new VerificationLinkEmailRequest();
VerificationLinkEmailRequest verificationLinkEmailRequest = buildRequest();
service.sendLetterVerificationLink(verificationLinkEmailRequest);
verify(mailSender).send(Mockito.any(SimpleMailMessage.class));
ArgumentCaptor<SimpleMailMessage> argumentCaptor = ArgumentCaptor.forClass(SimpleMailMessage.class);
verify(mailSender).send(argumentCaptor.capture());
SimpleMailMessage sentMessage = argumentCaptor.getValue();
assertArrayEquals(new String[]{EXPECTED_EMAIL}, sentMessage.getTo());
assertEquals("Recommendation letter verification link", sentMessage.getSubject());
assertTrue(sentMessage.getText().contains("/api/v1/recommendation-letter/verify/LETTER_ID/TOKEN_ID/SECRET"));
}

private static VerificationLinkEmailRequest buildRequest() {
VerificationLinkEmailRequest request = new VerificationLinkEmailRequest();
request.setLetterId(EXPECTED_ID);
request.setTokenId(TOKEN_ID);
request.setSecretToken(SECRET);
request.setReceiverEmail(EXPECTED_EMAIL);
return request;
}
}

0 comments on commit 0470f7b

Please sign in to comment.