MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordReplaceModifiers

Function TestRecordReplaceModifiers

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

Source from the content-addressed store, hash-verified

1575}
1576
1577func TestRecordReplaceModifiers(t *testing.T) {
1578 t.Parallel()
1579
1580 collection := core.NewBaseCollection("test")
1581 collection.Fields.Add(
1582 &mockField{core.TextField{Name: "mock"}},
1583 &core.NumberField{Name: "number"},
1584 )
1585
1586 originalData := map[string]any{
1587 "mock": "a",
1588 "number": 2.1,
1589 }
1590
1591 record := core.NewRecord(collection)
1592 for k, v := range originalData {
1593 record.Set(k, v)
1594 }
1595
1596 result := record.ReplaceModifiers(map[string]any{
1597 "mock:test": "b",
1598 "number+": 3,
1599 })
1600
1601 expected := map[string]any{
1602 "mock": "modifier_set",
1603 "number": 5.1,
1604 }
1605
1606 if len(result) != len(expected) {
1607 t.Fatalf("Expected\n%v\ngot\n%v", expected, result)
1608 }
1609
1610 for k, v := range expected {
1611 if result[k] != v {
1612 t.Errorf("Expected %q %#v, got %#v", k, v, result[k])
1613 }
1614 }
1615
1616 // ensure that the original data hasn't changed
1617 for k, v := range originalData {
1618 rv := record.Get(k)
1619 if rv != v {
1620 t.Errorf("Expected original %q %#v, got %#v", k, v, rv)
1621 }
1622 }
1623}
1624
1625func TestRecordValidate(t *testing.T) {
1626 t.Parallel()

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
ReplaceModifiersMethod · 0.95
GetMethod · 0.95
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…