test: add device token validation and text utility tests

This commit is contained in:
2026-02-14 21:38:00 -05:00
parent 4d15dba555
commit acd194c217
2 changed files with 39 additions and 0 deletions
+18
View File
@@ -90,3 +90,21 @@ func TestEvaluateRule_CopyrightYear(t *testing.T) {
result = handler.evaluateRule(item, "copyright_year", "less_than", "2000") result = handler.evaluateRule(item, "copyright_year", "less_than", "2000")
assert.False(t, result) assert.False(t, result)
} }
func TestTextToString(t *testing.T) {
tests := []struct {
name string
input pgtype.Text
expected string
}{
{"valid text", pgtype.Text{String: "hello", Valid: true}, "hello"},
{"null text", pgtype.Text{Valid: false}, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := textToString(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}
+21
View File
@@ -200,3 +200,24 @@ func TestDeviceUpdateRequest_Validation(t *testing.T) {
}) })
} }
} }
func TestValidateDeviceToken(t *testing.T) {
hashedToken := []byte("$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi")
plainToken := "password"
result := ValidateDeviceToken(string(hashedToken), plainToken)
assert.True(t, result, "Valid token should return true")
}
func TestValidateDeviceToken_Invalid(t *testing.T) {
hashedToken := []byte("$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi")
plainToken := "wrongpassword"
result := ValidateDeviceToken(string(hashedToken), plainToken)
assert.False(t, result, "Invalid token should return false")
}
func TestValidateDeviceToken_Empty(t *testing.T) {
result := ValidateDeviceToken("", "anypassword")
assert.False(t, result, "Empty hash should return false")
}