diff --git a/internal/handlers/collections_test.go b/internal/handlers/collections_test.go index 84f77e3..5cf2b22 100644 --- a/internal/handlers/collections_test.go +++ b/internal/handlers/collections_test.go @@ -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) + }) + } +} diff --git a/internal/handlers/devices_test.go b/internal/handlers/devices_test.go index 52f9b4b..05cd364 100644 --- a/internal/handlers/devices_test.go +++ b/internal/handlers/devices_test.go @@ -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") +}