2023-01-07 22:25:56 +02:00
|
|
|
package models_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pocketbase/pocketbase/models"
|
|
|
|
)
|
|
|
|
|
2023-07-17 22:13:39 +02:00
|
|
|
func TestRequestInfoHasModifierDataKeys(t *testing.T) {
|
2024-01-03 10:58:25 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
2023-01-07 22:25:56 +02:00
|
|
|
scenarios := []struct {
|
|
|
|
name string
|
2023-07-17 22:13:39 +02:00
|
|
|
requestInfo *models.RequestInfo
|
2023-01-07 22:25:56 +02:00
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"empty",
|
2023-07-17 22:13:39 +02:00
|
|
|
&models.RequestInfo{},
|
2023-01-07 22:25:56 +02:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Data with regular fields",
|
2023-07-17 22:13:39 +02:00
|
|
|
&models.RequestInfo{
|
2023-01-07 22:25:56 +02:00
|
|
|
Query: map[string]any{"data+": "demo"}, // should be ignored
|
|
|
|
Data: map[string]any{"a": 123, "b": "test", "c.d": false},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Data with +modifier fields",
|
2023-07-17 22:13:39 +02:00
|
|
|
&models.RequestInfo{
|
2023-01-07 22:25:56 +02:00
|
|
|
Data: map[string]any{"a+": 123, "b": "test", "c.d": false},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Data with -modifier fields",
|
2023-07-17 22:13:39 +02:00
|
|
|
&models.RequestInfo{
|
2023-01-07 22:25:56 +02:00
|
|
|
Data: map[string]any{"a": 123, "b-": "test", "c.d": false},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Data with mixed modifier fields",
|
2023-07-17 22:13:39 +02:00
|
|
|
&models.RequestInfo{
|
2023-01-07 22:25:56 +02:00
|
|
|
Data: map[string]any{"a": 123, "b-": "test", "c.d+": false},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range scenarios {
|
2023-07-17 22:13:39 +02:00
|
|
|
result := s.requestInfo.HasModifierDataKeys()
|
2023-01-07 22:25:56 +02:00
|
|
|
|
|
|
|
if result != s.expected {
|
|
|
|
t.Fatalf("[%s] Expected %v, got %v", s.name, s.expected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|