MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordUpsertSubmitFailure

Function TestRecordUpsertSubmitFailure

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

Source from the content-addressed store, hash-verified

762}
763
764func TestRecordUpsertSubmitFailure(t *testing.T) {
765 testApp, _ := tests.NewTestApp()
766 defer testApp.Cleanup()
767
768 col, err := testApp.FindCollectionByNameOrId("demo1")
769 if err != nil {
770 t.Fatal(err)
771 }
772
773 record, err := testApp.FindRecordById(col, "imy661ixudk5izi")
774 if err != nil {
775 t.Fatal(err)
776 }
777
778 file, err := filesystem.NewFileFromBytes([]byte("test"), "test.txt")
779 if err != nil {
780 t.Fatal(err)
781 }
782
783 form := forms.NewRecordUpsert(testApp, record)
784 form.Load(map[string]any{
785 "text": "test_update",
786 "file_one": file,
787 "select_one": "invalid",
788 })
789
790 validateCalls := 0
791 testApp.OnRecordValidate(col.Name).BindFunc(func(e *core.RecordEvent) error {
792 validateCalls++
793 return e.Next()
794 })
795
796 result := form.Submit()
797
798 if result == nil {
799 t.Fatal("Expected Submit error, got nil")
800 }
801
802 if validateCalls != 1 {
803 t.Fatalf("Expected validateCalls %d, got %d", 1, validateCalls)
804 }
805
806 // refresh the record to ensure that the changes weren't persisted
807 record, err = testApp.FindRecordById(col, record.Id)
808 if err != nil {
809 t.Fatal(err)
810 }
811
812 if v := record.GetString("text"); v == "test_update" {
813 t.Fatalf("Expected record.text to remain the same, got %q", v)
814 }
815
816 if v := record.GetString("select_one"); v != "" {
817 t.Fatalf("Expected record.select_one to remain the same, got %q", v)
818 }
819
820 if v := record.GetString("file_one"); v != "" {
821 t.Fatalf("Expected record.file_one to remain the same, got %q", v)

Callers

nothing calls this directly

Calls 13

CleanupMethod · 0.95
LoadMethod · 0.95
SubmitMethod · 0.95
NewTestAppFunction · 0.92
NewFileFromBytesFunction · 0.92
NewRecordUpsertFunction · 0.92
testFilesCountFunction · 0.85
GetStringMethod · 0.80
FindRecordByIdMethod · 0.65
OnRecordValidateMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…