feat: mail service
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package idempotency
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"galaxy/mail/internal/domain/common"
|
||||
"galaxy/mail/internal/domain/delivery"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRecordValidate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
createdAt := time.Unix(1_775_121_700, 0).UTC()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
record Record
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid",
|
||||
record: Record{
|
||||
Source: delivery.SourceNotification,
|
||||
IdempotencyKey: common.IdempotencyKey("notification:delivery-123"),
|
||||
DeliveryID: common.DeliveryID("delivery-123"),
|
||||
RequestFingerprint: "sha256:abcdef",
|
||||
CreatedAt: createdAt,
|
||||
ExpiresAt: createdAt.Add(7 * 24 * time.Hour),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "expires at must be after created at",
|
||||
record: Record{
|
||||
Source: delivery.SourceNotification,
|
||||
IdempotencyKey: common.IdempotencyKey("notification:delivery-123"),
|
||||
DeliveryID: common.DeliveryID("delivery-123"),
|
||||
RequestFingerprint: "sha256:abcdef",
|
||||
CreatedAt: createdAt,
|
||||
ExpiresAt: createdAt,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "fingerprint required",
|
||||
record: Record{
|
||||
Source: delivery.SourceNotification,
|
||||
IdempotencyKey: common.IdempotencyKey("notification:delivery-123"),
|
||||
DeliveryID: common.DeliveryID("delivery-123"),
|
||||
CreatedAt: createdAt,
|
||||
ExpiresAt: createdAt.Add(time.Hour),
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := tt.record.Validate()
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user