MCPcopy
hub / github.com/pocketbase/pocketbase / TestAutodateFieldIntercept

Function TestAutodateFieldIntercept

core/field_autodate_test.go:238–351  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

236}
237
238func TestAutodateFieldIntercept(t *testing.T) {
239 app, _ := tests.NewTestApp()
240 defer app.Cleanup()
241
242 initialDate, err := types.ParseDateTime("2024-01-02 03:04:05.789Z")
243 if err != nil {
244 t.Fatal(err)
245 }
246
247 collection := core.NewBaseCollection("test_collection")
248
249 scenarios := []struct {
250 name string
251 actionName string
252 field *core.AutodateField
253 record func() *core.Record
254 expected string
255 }{
256 {
257 "non-matching action",
258 "test",
259 &core.AutodateField{Name: "test", OnCreate: true, OnUpdate: true},
260 func() *core.Record {
261 return core.NewRecord(collection)
262 },
263 "",
264 },
265 {
266 "create with zero value (disabled onCreate)",
267 core.InterceptorActionCreateExecute,
268 &core.AutodateField{Name: "test", OnCreate: false, OnUpdate: true},
269 func() *core.Record {
270 return core.NewRecord(collection)
271 },
272 "",
273 },
274 {
275 "create with zero value",
276 core.InterceptorActionCreateExecute,
277 &core.AutodateField{Name: "test", OnCreate: true, OnUpdate: true},
278 func() *core.Record {
279 return core.NewRecord(collection)
280 },
281 "{NOW}",
282 },
283 {
284 "create with non-zero value",
285 core.InterceptorActionCreateExecute,
286 &core.AutodateField{Name: "test", OnCreate: true, OnUpdate: true},
287 func() *core.Record {
288 record := core.NewRecord(collection)
289 record.SetRaw("test", initialDate)
290 return record
291 },
292 initialDate.String(),
293 },
294 {
295 "update with zero value (disabled onUpdate)",

Callers

nothing calls this directly

Calls 13

CleanupMethod · 0.95
SetRawMethod · 0.95
GetStringMethod · 0.95
NewTestAppFunction · 0.92
ParseDateTimeFunction · 0.92
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
NowDateTimeFunction · 0.92
cutMillisecondsFunction · 0.85
InterceptMethod · 0.65
GetNameMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…