generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbec524
commit acae562
Showing
3 changed files
with
58 additions
and
0 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
44 changes: 44 additions & 0 deletions
44
email-mailjet/src/test/groovy/io/micronaut/email/mailjet/MailjetEmailComposerSpec.groovy
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,44 @@ | ||
package io.micronaut.email.mailjet | ||
|
||
import com.fasterxml.jackson.databind.json.JsonMapper | ||
import com.mailjet.client.MailjetRequest | ||
import io.micronaut.email.Email | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import spock.lang.Specification | ||
|
||
@MicronautTest(startApplication = false) | ||
class MailjetEmailComposerSpec extends Specification { | ||
|
||
@Inject | ||
MailjetEmailComposer mailjetEmailComposer | ||
|
||
void "from, to, only the last reply to and subject are put to the request"() { | ||
given: | ||
String from = "sender@example.com" | ||
String to = "receiver@example.com" | ||
String replyTo1 = "sender.reply.to.one@example.com" | ||
String replyTo2 = "sender.reply.to.two@example.com" | ||
String subject = "Apple Music" | ||
String body = "Lore ipsum body" | ||
|
||
Email email = Email.builder() | ||
.from(from) | ||
.to(to) | ||
.replyTo(replyTo1) | ||
.replyTo(replyTo2) | ||
.subject(subject) | ||
.body(body) | ||
.build() | ||
when: | ||
MailjetRequest request = mailjetEmailComposer.compose(email) | ||
Map map = new JsonMapper().readValue(request.body, Map) | ||
|
||
then: | ||
map["Messages"][0]["ReplyTo"]["Email"] == replyTo2 | ||
map["Messages"][0]["TextPart"] == body | ||
map["Messages"][0]["From"]["Email"] == from | ||
map["Messages"][0]["To"][0]["Email"] == to | ||
map["Messages"][0]["Subject"] == subject | ||
} | ||
} |