Skip to content

Commit 5a1ba39

Browse files
authored
test(events): add comprehensive marshal/unmarshal tests for event types (#98)
Add detailed tests for DeliveryEvent, OpenEvent, ClickEvent, BounceEvent, and SpamComplaintEvent to verify correct JSON marshaling and unmarshaling. These tests improve coverage and ensure event structs properly serialize and deserialize, preventing regressions in event data handling.
1 parent e942f18 commit 5a1ba39

File tree

7 files changed

+1243
-38
lines changed

7 files changed

+1243
-38
lines changed

email_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (s *PostmarkTestSuite) TestSendEmail() {
4545
responseJSON string
4646
wantErr bool
4747
expectedID string
48+
statusCode int
4849
}{
4950
{
5051
name: "successful email send",
@@ -57,6 +58,7 @@ func (s *PostmarkTestSuite) TestSendEmail() {
5758
}`,
5859
wantErr: false,
5960
expectedID: "0a129aee-e1cd-480d-b08d-4f48548ff48d",
61+
statusCode: http.StatusOK,
6062
},
6163
{
6264
name: "email send failure with error code",
@@ -67,13 +69,26 @@ func (s *PostmarkTestSuite) TestSendEmail() {
6769
"ErrorCode": 401,
6870
"Message": "Sender signature not confirmed"
6971
}`,
70-
wantErr: true,
72+
wantErr: true,
73+
statusCode: http.StatusOK,
74+
},
75+
{
76+
name: "email send HTTP error",
77+
responseJSON: `{
78+
"ErrorCode": 500,
79+
"Message": "Internal Server Error"
80+
}`,
81+
wantErr: true,
82+
statusCode: http.StatusInternalServerError,
7183
},
7284
}
7385

7486
for _, tt := range tests {
7587
s.Run(tt.name, func() {
7688
s.mux.Post("/email", func(w http.ResponseWriter, _ *http.Request) {
89+
if tt.statusCode != http.StatusOK {
90+
w.WriteHeader(tt.statusCode)
91+
}
7792
_, _ = w.Write([]byte(tt.responseJSON))
7893
})
7994

0 commit comments

Comments
 (0)