(t *testing.T)
| 287 | } |
| 288 | |
| 289 | func TestRecordUpsertDrySubmitCreateSuccess(t *testing.T) { |
| 290 | runTest := func(t *testing.T, testApp core.App) { |
| 291 | col, err := testApp.FindCollectionByNameOrId("demo1") |
| 292 | if err != nil { |
| 293 | t.Fatal(err) |
| 294 | } |
| 295 | |
| 296 | record := core.NewRecord(col) |
| 297 | |
| 298 | file, err := filesystem.NewFileFromBytes([]byte("test"), "test.txt") |
| 299 | if err != nil { |
| 300 | t.Fatal(err) |
| 301 | } |
| 302 | |
| 303 | form := forms.NewRecordUpsert(testApp, record) |
| 304 | form.Load(map[string]any{ |
| 305 | "id": "test", |
| 306 | "text": "test_update", |
| 307 | "file_one": file, |
| 308 | "select_one": "!invalid", // should be allowed even if invalid since validations are not executed |
| 309 | }) |
| 310 | |
| 311 | calls := "" |
| 312 | testApp.OnRecordValidate(col.Name).BindFunc(func(e *core.RecordEvent) error { |
| 313 | calls += "a" // shouldn't be called |
| 314 | return e.Next() |
| 315 | }) |
| 316 | |
| 317 | result := form.DrySubmit(func(txApp core.App, drySavedRecord *core.Record) error { |
| 318 | calls += "b" |
| 319 | return nil |
| 320 | }) |
| 321 | |
| 322 | if result != nil { |
| 323 | t.Fatalf("Expected DrySubmit success, got error: %v", result) |
| 324 | } |
| 325 | |
| 326 | if calls != "b" { |
| 327 | t.Fatalf("Expected calls %q, got %q", "ab", calls) |
| 328 | } |
| 329 | |
| 330 | // refresh the record to ensure that the changes weren't persisted |
| 331 | _, err = testApp.FindRecordById(col, record.Id) |
| 332 | if err == nil { |
| 333 | t.Fatal("Expected the created record to be deleted") |
| 334 | } |
| 335 | |
| 336 | testFilesCount(t, testApp, record, 0) |
| 337 | } |
| 338 | |
| 339 | t.Run("without parent transaction", func(t *testing.T) { |
| 340 | testApp, _ := tests.NewTestApp() |
| 341 | defer testApp.Cleanup() |
| 342 | |
| 343 | runTest(t, testApp) |
| 344 | }) |
| 345 | |
| 346 | t.Run("with parent transaction", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…