47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package v1
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"lincodex/backend/internal/domain"
|
|
"lincodex/backend/internal/port/outbound"
|
|
)
|
|
|
|
func TestConsentCursorTimeBounds(t *testing.T) {
|
|
subjectID := uuid.New()
|
|
positionID := uuid.New()
|
|
for _, grantedAt := range []time.Time{
|
|
time.Unix(0, minConsentCursorNanos).UTC(),
|
|
time.Unix(0, -1).UTC(),
|
|
time.Unix(0, 0).UTC(),
|
|
time.Unix(0, maxConsentCursorNanos).UTC(),
|
|
} {
|
|
t.Run(grantedAt.String(), func(t *testing.T) {
|
|
cursor, err := encodeConsentCursor(subjectID, domain.ConsentStateActive, outbound.ConsentListPosition{
|
|
GrantedAt: grantedAt, ID: positionID,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("encode cursor at %s: %v", grantedAt, err)
|
|
}
|
|
position, state, err := decodeConsentCursor(cursor, subjectID)
|
|
if err != nil || !position.GrantedAt.Equal(grantedAt) || position.ID != positionID || state != domain.ConsentStateActive {
|
|
t.Fatalf("decode cursor = %#v, %q, %v; want time %s and matching position", position, state, err, grantedAt)
|
|
}
|
|
})
|
|
}
|
|
|
|
for _, grantedAt := range []time.Time{
|
|
time.Unix(0, minConsentCursorNanos).Add(-time.Nanosecond),
|
|
time.Unix(0, maxConsentCursorNanos).Add(time.Nanosecond),
|
|
} {
|
|
if _, err := encodeConsentCursor(subjectID, domain.ConsentStateActive, outbound.ConsentListPosition{
|
|
GrantedAt: grantedAt, ID: positionID,
|
|
}); err == nil {
|
|
t.Fatalf("encode cursor outside Unix-nanosecond range at %s: got nil error", grantedAt)
|
|
}
|
|
}
|
|
}
|