62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package malformedcommand
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestEntryValidate(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
entry := Entry{
|
|
StreamEntryID: "1775121700000-0",
|
|
DeliveryID: "mail-123",
|
|
Source: "notification",
|
|
IdempotencyKey: "notification:mail-123",
|
|
FailureCode: FailureCodeInvalidPayload,
|
|
FailureMessage: "payload_json.subject is required",
|
|
RawFields: map[string]any{
|
|
"delivery_id": "mail-123",
|
|
"source": "notification",
|
|
"payload_mode": "rendered",
|
|
"idempotency_key": "notification:mail-123",
|
|
},
|
|
RecordedAt: time.Unix(1_775_121_700, 0).UTC(),
|
|
}
|
|
|
|
require.NoError(t, entry.Validate())
|
|
}
|
|
|
|
func TestEntryValidateRejectsInvalidValue(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
entry := Entry{
|
|
StreamEntryID: "1775121700000-0",
|
|
FailureCode: FailureCode("unsupported"),
|
|
FailureMessage: "failure",
|
|
RawFields: map[string]any{},
|
|
RecordedAt: time.Unix(1_775_121_700, 0).UTC(),
|
|
}
|
|
|
|
err := entry.Validate()
|
|
require.Error(t, err)
|
|
require.ErrorContains(t, err, "failure code")
|
|
}
|
|
|
|
func TestEntryValidateRejectsNilRawFields(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
entry := Entry{
|
|
StreamEntryID: "1775121700000-0",
|
|
FailureCode: FailureCodeInvalidCommand,
|
|
FailureMessage: "missing required fields",
|
|
RecordedAt: time.Unix(1_775_121_700, 0).UTC(),
|
|
}
|
|
|
|
err := entry.Validate()
|
|
require.Error(t, err)
|
|
require.ErrorContains(t, err, "raw fields")
|
|
}
|