MCPcopy
hub / github.com/pocketbase/pocketbase / TestDateFieldValidateValue

Function TestDateFieldValidateValue

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

Source from the content-addressed store, hash-verified

65}
66
67func TestDateFieldValidateValue(t *testing.T) {
68 app, _ := tests.NewTestApp()
69 defer app.Cleanup()
70
71 collection := core.NewBaseCollection("test_collection")
72
73 scenarios := []struct {
74 name string
75 field *core.DateField
76 record func() *core.Record
77 expectError bool
78 }{
79 {
80 "invalid raw value",
81 &core.DateField{Name: "test"},
82 func() *core.Record {
83 record := core.NewRecord(collection)
84 record.SetRaw("test", 123)
85 return record
86 },
87 true,
88 },
89 {
90 "zero field value (not required)",
91 &core.DateField{Name: "test"},
92 func() *core.Record {
93 record := core.NewRecord(collection)
94 record.SetRaw("test", types.DateTime{})
95 return record
96 },
97 false,
98 },
99 {
100 "zero field value (required)",
101 &core.DateField{Name: "test", Required: true},
102 func() *core.Record {
103 record := core.NewRecord(collection)
104 record.SetRaw("test", types.DateTime{})
105 return record
106 },
107 true,
108 },
109 {
110 "non-zero field value (required)",
111 &core.DateField{Name: "test", Required: true},
112 func() *core.Record {
113 record := core.NewRecord(collection)
114 record.SetRaw("test", types.NowDateTime())
115 return record
116 },
117 false,
118 },
119 }
120
121 for _, s := range scenarios {
122 t.Run(s.name, func(t *testing.T) {
123 err := s.field.ValidateValue(context.Background(), app, s.record())
124

Callers

nothing calls this directly

Calls 8

CleanupMethod · 0.95
SetRawMethod · 0.95
NewTestAppFunction · 0.92
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
NowDateTimeFunction · 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…