MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordUpsertDrySubmitCreateSuccess

Function TestRecordUpsertDrySubmitCreateSuccess

forms/record_upsert_test.go:289–355  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

287}
288
289func 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) {

Callers

nothing calls this directly

Calls 15

LoadMethod · 0.95
DrySubmitMethod · 0.95
CleanupMethod · 0.95
NewRecordFunction · 0.92
NewFileFromBytesFunction · 0.92
NewRecordUpsertFunction · 0.92
NewTestAppFunction · 0.92
testFilesCountFunction · 0.85
OnRecordValidateMethod · 0.65
NextMethod · 0.65
FindRecordByIdMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…