test: add device token validation and text utility tests
This commit is contained in:
@@ -90,3 +90,21 @@ func TestEvaluateRule_CopyrightYear(t *testing.T) {
|
||||
result = handler.evaluateRule(item, "copyright_year", "less_than", "2000")
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user