MCPcopy
hub / github.com/pocketbase/pocketbase / TestDateFieldPrepareValue

Function TestDateFieldPrepareValue

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

Source from the content-addressed store, hash-verified

29}
30
31func TestDateFieldPrepareValue(t *testing.T) {
32 app, _ := tests.NewTestApp()
33 defer app.Cleanup()
34
35 f := &core.DateField{}
36 record := core.NewRecord(core.NewBaseCollection("test"))
37
38 scenarios := []struct {
39 raw any
40 expected string
41 }{
42 {"", ""},
43 {"invalid", ""},
44 {"2024-01-01 00:11:22.345Z", "2024-01-01 00:11:22.345Z"},
45 {time.Date(2024, 1, 2, 3, 4, 5, 0, time.UTC), "2024-01-02 03:04:05.000Z"},
46 }
47
48 for i, s := range scenarios {
49 t.Run(fmt.Sprintf("%d_%#v", i, s.raw), func(t *testing.T) {
50 v, err := f.PrepareValue(record, s.raw)
51 if err != nil {
52 t.Fatal(err)
53 }
54
55 vDate, ok := v.(types.DateTime)
56 if !ok {
57 t.Fatalf("Expected types.DateTime instance, got %T", v)
58 }
59
60 if vDate.String() != s.expected {
61 t.Fatalf("Expected %v, got %v", s.expected, v)
62 }
63 })
64 }
65}
66
67func TestDateFieldValidateValue(t *testing.T) {
68 app, _ := tests.NewTestApp()

Callers

nothing calls this directly

Calls 7

CleanupMethod · 0.95
PrepareValueMethod · 0.95
NewTestAppFunction · 0.92
NewRecordFunction · 0.92
NewBaseCollectionFunction · 0.92
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…