MCPcopy
hub / github.com/pocketbase/pocketbase / TestTextFieldValidateValue

Function TestTextFieldValidateValue

core/field_text_test.go:67–379  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

65}
66
67func TestTextFieldValidateValue(t *testing.T) {
68 app, _ := tests.NewTestApp()
69 defer app.Cleanup()
70
71 collection, err := app.FindCollectionByNameOrId("demo1")
72 if err != nil {
73 t.Fatal(err)
74 }
75
76 existingRecord, err := app.FindFirstRecordByFilter(collection, "id != ''")
77 if err != nil {
78 t.Fatal(err)
79 }
80
81 scenarios := []struct {
82 name string
83 field *core.TextField
84 record func() *core.Record
85 expectError bool
86 }{
87 {
88 "invalid raw value",
89 &core.TextField{Name: "test"},
90 func() *core.Record {
91 record := core.NewRecord(collection)
92 record.SetRaw("test", 123)
93 return record
94 },
95 true,
96 },
97 {
98 "zero field value (not required)",
99 &core.TextField{Name: "test", Pattern: `\d+`, Min: 10, Max: 100}, // other fields validators should be ignored
100 func() *core.Record {
101 record := core.NewRecord(collection)
102 record.SetRaw("test", "")
103 return record
104 },
105 false,
106 },
107 {
108 "zero field value (required)",
109 &core.TextField{Name: "test", Required: true},
110 func() *core.Record {
111 record := core.NewRecord(collection)
112 record.SetRaw("test", "")
113 return record
114 },
115 true,
116 },
117 {
118 "non-zero field value (required)",
119 &core.TextField{Name: "test", Required: true},
120 func() *core.Record {
121 record := core.NewRecord(collection)
122 record.SetRaw("test", "abc")
123 return record
124 },

Callers

nothing calls this directly

Calls 8

CleanupMethod · 0.95
SetRawMethod · 0.95
NewTestAppFunction · 0.92
NewRecordFunction · 0.92
ValidateValueMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…