(t *testing.T)
| 1659 | } |
| 1660 | |
| 1661 | func TestRecordModelEventSync(t *testing.T) { |
| 1662 | t.Parallel() |
| 1663 | |
| 1664 | app, _ := tests.NewTestApp() |
| 1665 | defer app.Cleanup() |
| 1666 | |
| 1667 | col, err := app.FindCollectionByNameOrId("demo3") |
| 1668 | if err != nil { |
| 1669 | t.Fatal(err) |
| 1670 | } |
| 1671 | |
| 1672 | testRecords := make([]*core.Record, 4) |
| 1673 | for i := 0; i < 4; i++ { |
| 1674 | testRecords[i] = core.NewRecord(col) |
| 1675 | testRecords[i].Set("title", "sync_test_"+strconv.Itoa(i)) |
| 1676 | if err := app.Save(testRecords[i]); err != nil { |
| 1677 | t.Fatal(err) |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | createModelEvent := func() *core.ModelEvent { |
| 1682 | event := new(core.ModelEvent) |
| 1683 | event.App = app |
| 1684 | event.Context = context.Background() |
| 1685 | event.Type = "test_a" |
| 1686 | event.Model = testRecords[0] |
| 1687 | return event |
| 1688 | } |
| 1689 | |
| 1690 | createModelErrorEvent := func() *core.ModelErrorEvent { |
| 1691 | event := new(core.ModelErrorEvent) |
| 1692 | event.ModelEvent = *createModelEvent() |
| 1693 | event.Error = errors.New("error_a") |
| 1694 | return event |
| 1695 | } |
| 1696 | |
| 1697 | changeRecordEventBefore := func(e *core.RecordEvent) { |
| 1698 | e.Type = "test_b" |
| 1699 | //nolint:staticcheck |
| 1700 | e.Context = context.WithValue(context.Background(), "test", 123) |
| 1701 | e.Record = testRecords[1] |
| 1702 | } |
| 1703 | |
| 1704 | modelEventFinalizerChange := func(e *core.ModelEvent) { |
| 1705 | e.Type = "test_c" |
| 1706 | //nolint:staticcheck |
| 1707 | e.Context = context.WithValue(context.Background(), "test", 456) |
| 1708 | e.Model = testRecords[2] |
| 1709 | } |
| 1710 | |
| 1711 | changeRecordEventAfter := func(e *core.RecordEvent) { |
| 1712 | e.Type = "test_d" |
| 1713 | //nolint:staticcheck |
| 1714 | e.Context = context.WithValue(context.Background(), "test", 789) |
| 1715 | e.Record = testRecords[3] |
| 1716 | } |
| 1717 | |
| 1718 | expectedBeforeModelEventHandlerChecks := func(t *testing.T, e *core.ModelEvent) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…