test: add new handler test files for analytics, auth, kobo, library, progress, and sidecar
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseLimit_Valid(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected int32
|
||||
}{
|
||||
{"string number", "10", 10},
|
||||
{"zero", "0", 0},
|
||||
{"large number", "1000", 1000},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result, err := parseLimit(tt.input)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLimit_Invalid(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
}{
|
||||
{"non-numeric", "abc"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := parseLimit(tt.input)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatUUID(t *testing.T) {
|
||||
uuidBytes := [16]byte{
|
||||
0xf4, 0x7a, 0xc1, 0x0b,
|
||||
0x58, 0xcc,
|
||||
0x43, 0x72,
|
||||
0xa5, 0x67,
|
||||
0x0e, 0x02, 0xb2, 0xc3, 0xd4, 0x79,
|
||||
}
|
||||
pgUUID := pgtype.UUID{Bytes: uuidBytes, Valid: true}
|
||||
|
||||
result := formatUUID(pgUUID)
|
||||
assert.Equal(t, "f47ac10b-58cc-4372-a567-0e02b2c3d479", result)
|
||||
}
|
||||
|
||||
func TestFormatUUID_Null(t *testing.T) {
|
||||
pgUUID := pgtype.UUID{Valid: false}
|
||||
|
||||
result := formatUUID(pgUUID)
|
||||
assert.Equal(t, "", result)
|
||||
}
|
||||
Reference in New Issue
Block a user