(t *testing.T)
| 2291 | } |
| 2292 | |
| 2293 | func TestRecordDeleteBatchProcessing(t *testing.T) { |
| 2294 | t.Parallel() |
| 2295 | |
| 2296 | app, _ := tests.NewTestApp() |
| 2297 | defer app.Cleanup() |
| 2298 | |
| 2299 | if err := createMockBatchProcessingData(app); err != nil { |
| 2300 | t.Fatal(err) |
| 2301 | } |
| 2302 | |
| 2303 | // find and delete the first c1 record to trigger cascade |
| 2304 | mainRecord, _ := app.FindRecordById("c1", "a") |
| 2305 | if err := app.Delete(mainRecord); err != nil { |
| 2306 | t.Fatal(err) |
| 2307 | } |
| 2308 | |
| 2309 | // check if the main record was deleted |
| 2310 | _, err := app.FindRecordById(mainRecord.Collection().Id, mainRecord.Id) |
| 2311 | if err == nil { |
| 2312 | t.Fatal("The main record wasn't deleted") |
| 2313 | } |
| 2314 | |
| 2315 | // check if the c1 b rel field were updated |
| 2316 | c1RecordB, err := app.FindRecordById("c1", "b") |
| 2317 | if err != nil || c1RecordB.GetString("rel") != "" { |
| 2318 | t.Fatalf("Expected c1RecordB.rel to be nil, got %v", c1RecordB.GetString("rel")) |
| 2319 | } |
| 2320 | |
| 2321 | // check if the c2 rel fields were updated |
| 2322 | c2Records, err := app.FindAllRecords("c2", nil) |
| 2323 | if err != nil || len(c2Records) == 0 { |
| 2324 | t.Fatalf("Failed to fetch c2 records: %v", err) |
| 2325 | } |
| 2326 | for _, r := range c2Records { |
| 2327 | ids := r.GetStringSlice("rel") |
| 2328 | if len(ids) != 1 || ids[0] != "b" { |
| 2329 | t.Fatalf("Expected only 'b' rel id, got %v", ids) |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | // check if all c3 relations were deleted |
| 2334 | c3Records, err := app.FindAllRecords("c3", nil) |
| 2335 | if err != nil { |
| 2336 | t.Fatalf("Failed to fetch c3 records: %v", err) |
| 2337 | } |
| 2338 | if total := len(c3Records); total != 0 { |
| 2339 | t.Fatalf("Expected c3 records to be deleted, found %d", total) |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | func createMockBatchProcessingData(app core.App) error { |
| 2344 | // create mock collection without relation |
nothing calls this directly
no test coverage detected
searching dependent graphs…