MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordPostScan

Function TestRecordPostScan

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

Source from the content-addressed store, hash-verified

68}
69
70func TestRecordPostScan(t *testing.T) {
71 t.Parallel()
72
73 collection := core.NewBaseCollection("test_collection")
74 collection.Fields.Add(&core.TextField{Name: "test"})
75
76 m := core.NewRecord(collection)
77
78 // calling PostScan without id
79 err := m.PostScan()
80 if err == nil {
81 t.Fatal("Expected PostScan id error, got nil")
82 }
83
84 m.Id = "test_id"
85 m.Set("test", "abc")
86
87 if v := m.IsNew(); v != true {
88 t.Fatalf("[before PostScan] Expected IsNew %v, got %v", true, v)
89 }
90 if v := m.Original().PK(); v != "" {
91 t.Fatalf("[before PostScan] Expected the original PK to be empty string, got %v", v)
92 }
93 if v := m.Original().Get("test"); v != "" {
94 t.Fatalf("[before PostScan] Expected the original 'test' field to be empty string, got %v", v)
95 }
96
97 err = m.PostScan()
98 if err != nil {
99 t.Fatalf("Expected PostScan nil error, got %v", err)
100 }
101
102 if v := m.IsNew(); v != false {
103 t.Fatalf("[after PostScan] Expected IsNew %v, got %v", false, v)
104 }
105 if v := m.Original().PK(); v != "test_id" {
106 t.Fatalf("[after PostScan] Expected the original PK to be %q, got %v", "test_id", v)
107 }
108 if v := m.Original().Get("test"); v != "abc" {
109 t.Fatalf("[after PostScan] Expected the original 'test' field to be %q, got %v", "abc", v)
110 }
111}
112
113func TestRecordHookTags(t *testing.T) {
114 t.Parallel()

Callers

nothing calls this directly

Calls 9

PostScanMethod · 0.95
SetMethod · 0.95
OriginalMethod · 0.95
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
IsNewMethod · 0.65
PKMethod · 0.65
GetMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…