MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordGetDateTime

Function TestRecordGetDateTime

core/record_model_test.go:938–973  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

936}
937
938func TestRecordGetDateTime(t *testing.T) {
939 t.Parallel()
940
941 nowTime := time.Now()
942 testTime, _ := time.Parse(types.DefaultDateLayout, "2022-01-01 08:00:40.000Z")
943
944 scenarios := []struct {
945 value any
946 expected time.Time
947 }{
948 {nil, time.Time{}},
949 {"", time.Time{}},
950 {false, time.Time{}},
951 {true, time.Time{}},
952 {"test", time.Time{}},
953 {[]string{"true"}, time.Time{}},
954 {map[string]int{"test": 1}, time.Time{}},
955 {1641024040, testTime},
956 {"2022-01-01 08:00:40.000", testTime},
957 {nowTime, nowTime},
958 }
959
960 collection := core.NewBaseCollection("test")
961 record := core.NewRecord(collection)
962
963 for i, s := range scenarios {
964 t.Run(fmt.Sprintf("%d_%#v", i, s.value), func(t *testing.T) {
965 record.Set("test", s.value)
966
967 result := record.GetDateTime("test")
968 if !result.Time().Equal(s.expected) {
969 t.Fatalf("Expected %v, got %v", s.expected, result)
970 }
971 })
972 }
973}
974
975func TestRecordGetStringSlice(t *testing.T) {
976 t.Parallel()

Callers

nothing calls this directly

Calls 8

SetMethod · 0.95
GetDateTimeMethod · 0.95
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
ParseMethod · 0.80
TimeMethod · 0.80
EqualMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…