-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from kartverket/skip1180
[SKIP-1180] - Add some tests
- Loading branch information
Showing
10 changed files
with
267 additions
and
28 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
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
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,13 @@ | ||
package config_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Config Suite") | ||
} |
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 |
---|---|---|
@@ -1,21 +1,20 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestSenderType_IsValid(t *testing.T) { | ||
var tests = []struct { | ||
name string | ||
input SenderType | ||
want bool | ||
}{ | ||
{"msgraph should be valid", 0, true}, | ||
{"Dummy should be valid", 1, true}, | ||
{"random should be invalid", 2, false}, | ||
} | ||
for _, tt := range tests { | ||
assert.Equal(t, SenderType.IsValid(tt.input), tt.want, tt.name) | ||
} | ||
} | ||
var _ = Describe("Config", func() { | ||
Context("Sender type is valid", func() { | ||
It("msgraph should return true", func() { | ||
Expect(SenderType.IsValid(MsGraph)).To(BeTrue()) | ||
}) | ||
It("dummy should return true", func() { | ||
Expect(SenderType.IsValid(Dummy)).To(BeTrue()) | ||
}) | ||
It("other should return false", func() { | ||
Expect(SenderType.IsValid(2)).ToNot(BeTrue()) | ||
}) | ||
}) | ||
}) |
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,73 @@ | ||
package sender | ||
|
||
import ( | ||
. "github.com/kartverket/skyline/pkg/email" | ||
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models" | ||
"github.com/mnako/letters" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"net/mail" | ||
"time" | ||
) | ||
|
||
var _ = Describe("Office365", func() { | ||
recipient := []*mail.Address{{Address: "skip@kartverket.no", Name: "SKIP"}} | ||
ccrecipient := []*mail.Address{{Address: "cc@kartverket.no", Name: "cc"}} | ||
bccrecipient := []*mail.Address{{Address: "bcc@kartverket.no", Name: "bcc"}} | ||
subject := "this is a subject" | ||
txtMsg := "This is a test message" | ||
date := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) | ||
htmlMsg := "<html><body>This is a test message</body></html>" | ||
skylineEmail := SkylineEmail{ | ||
Email: letters.Email{ | ||
Headers: letters.Headers{ | ||
ContentType: letters.ContentTypeHeader{ | ||
ContentType: "text/plain", | ||
}, | ||
To: recipient, | ||
Cc: ccrecipient, | ||
Bcc: bccrecipient, | ||
Date: date, | ||
Subject: subject, | ||
}, | ||
Text: txtMsg, | ||
}, | ||
} | ||
Context("when mapping", func() { | ||
It("should map basic email to graph email", func() { | ||
graphMail, err := mapToGraphMail(&skylineEmail) | ||
Expect(err).To(BeNil()) | ||
Expect(graphMail.GetMessage().GetSubject()).To(Equal(&subject)) | ||
Expect(graphMail.GetMessage().GetToRecipients()).To(Equal(toGraphRecipient(recipient...))) | ||
Expect(graphMail.GetMessage().GetCcRecipients()).To(Equal(toGraphRecipient(ccrecipient...))) | ||
Expect(graphMail.GetMessage().GetBccRecipients()).To(Equal(toGraphRecipient(bccrecipient...))) | ||
Expect(graphMail.GetMessage().GetSentDateTime()).To(Equal(&date)) | ||
contentType := graphmodels.TEXT_BODYTYPE | ||
Expect(graphMail.GetMessage().GetBody().GetContentType()).To(Equal(&contentType)) | ||
Expect(graphMail.GetMessage().GetBody().GetContent()).To(Equal(&txtMsg)) | ||
}) | ||
It("should map html email to graph email", func() { | ||
skylineEmail.Headers.ContentType.ContentType = "text/html" | ||
skylineEmail.HTML = htmlMsg | ||
graphMail, err := mapToGraphMail(&skylineEmail) | ||
Expect(err).To(BeNil()) | ||
contentType := graphmodels.HTML_BODYTYPE | ||
Expect(graphMail.GetMessage().GetBody().GetContentType()).To(Equal(&contentType)) | ||
Expect(graphMail.GetMessage().GetBody().GetContent()).To(Equal(&htmlMsg)) | ||
}) | ||
It("should error if not valid type", func() { | ||
skylineEmail.Headers.ContentType.ContentType = "err" | ||
_, err := mapToGraphMail(&skylineEmail) | ||
Expect(err).ToNot(BeNil()) | ||
}) | ||
It("should map MIME email to graph email, html type", func() { | ||
skylineEmail.Headers.ContentType.ContentType = "multipart/alternative" | ||
skylineEmail.HTML = htmlMsg | ||
graphMail, err := mapToGraphMail(&skylineEmail) | ||
Expect(err).To(BeNil()) | ||
contentType := graphmodels.HTML_BODYTYPE | ||
Expect(graphMail.GetMessage().GetBody().GetContentType()).To(Equal(&contentType)) | ||
Expect(graphMail.GetMessage().GetBody().GetContent()).To(Equal(&htmlMsg)) | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
package sender | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestSender(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Sender Suite") | ||
} |
Oops, something went wrong.