(t *testing.T)
| 826 | } |
| 827 | |
| 828 | func TestFileFieldIntercept(t *testing.T) { |
| 829 | testApp, _ := tests.NewTestApp() |
| 830 | defer testApp.Cleanup() |
| 831 | |
| 832 | demo1, err := testApp.FindCollectionByNameOrId("demo1") |
| 833 | if err != nil { |
| 834 | t.Fatal(err) |
| 835 | } |
| 836 | demo1.Fields.GetByName("text").(*core.TextField).Required = true // trigger validation error |
| 837 | |
| 838 | f1, err := filesystem.NewFileFromBytes([]byte("test"), "new1.txt") |
| 839 | if err != nil { |
| 840 | t.Fatal(err) |
| 841 | } |
| 842 | |
| 843 | f2, err := filesystem.NewFileFromBytes([]byte("test"), "new2.txt") |
| 844 | if err != nil { |
| 845 | t.Fatal(err) |
| 846 | } |
| 847 | |
| 848 | f3, err := filesystem.NewFileFromBytes([]byte("test"), "new3.txt") |
| 849 | if err != nil { |
| 850 | t.Fatal(err) |
| 851 | } |
| 852 | |
| 853 | f4, err := filesystem.NewFileFromBytes([]byte("test"), "new4.txt") |
| 854 | if err != nil { |
| 855 | t.Fatal(err) |
| 856 | } |
| 857 | |
| 858 | record := core.NewRecord(demo1) |
| 859 | |
| 860 | ok := t.Run("1. create - with validation error", func(t *testing.T) { |
| 861 | record.Set("file_many", []any{f1, f2}) |
| 862 | |
| 863 | err := testApp.Save(record) |
| 864 | |
| 865 | tests.TestValidationErrors(t, err, []string{"text"}) |
| 866 | |
| 867 | value, _ := record.GetRaw("file_many").([]any) |
| 868 | if len(value) != 2 { |
| 869 | t.Fatalf("Expected the file field value to be unchanged, got %v", value) |
| 870 | } |
| 871 | }) |
| 872 | if !ok { |
| 873 | return |
| 874 | } |
| 875 | |
| 876 | ok = t.Run("2. create - fixing the validation error", func(t *testing.T) { |
| 877 | record.Set("text", "abc") |
| 878 | |
| 879 | err := testApp.Save(record) |
| 880 | if err != nil { |
| 881 | t.Fatalf("Expected save to succeed, got %v", err) |
| 882 | } |
| 883 | |
| 884 | expectedKeys := []string{f1.Name, f2.Name} |
| 885 |
nothing calls this directly
no test coverage detected
searching dependent graphs…