(t *testing.T)
| 323 | } |
| 324 | |
| 325 | func TestRecordClone(t *testing.T) { |
| 326 | t.Parallel() |
| 327 | |
| 328 | app, _ := tests.NewTestApp() |
| 329 | defer app.Cleanup() |
| 330 | |
| 331 | record, err := app.FindAuthRecordByEmail("users", "test@example.com") |
| 332 | if err != nil { |
| 333 | t.Fatal(err) |
| 334 | } |
| 335 | originalId := record.Id |
| 336 | |
| 337 | extraFieldsCheck := []string{`"email":`, `"custom":`} |
| 338 | |
| 339 | autodateTest := types.NowDateTime() |
| 340 | |
| 341 | // change the fields |
| 342 | record.Id = "changed" |
| 343 | record.Set("name", "name_new") |
| 344 | record.Set("custom", "test_custom") |
| 345 | record.SetRaw("created", autodateTest) |
| 346 | record.SetExpand(map[string]any{"test": 123}) |
| 347 | record.IgnoreEmailVisibility(true) |
| 348 | record.WithCustomData(true) |
| 349 | record.Unhide(record.Collection().Fields.FieldNames()...) |
| 350 | |
| 351 | // ensure that the email visibility and the custom data toggles are active |
| 352 | raw, err := record.MarshalJSON() |
| 353 | if err != nil { |
| 354 | t.Fatal(err) |
| 355 | } |
| 356 | rawStr := string(raw) |
| 357 | for _, f := range extraFieldsCheck { |
| 358 | if !strings.Contains(rawStr, f) { |
| 359 | t.Fatalf("Expected %s in\n%s", f, rawStr) |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // check changes |
| 364 | if v := record.GetString("name"); v != "name_new" { |
| 365 | t.Fatalf("Expected name to be %q, got %q", "name_new", v) |
| 366 | } |
| 367 | if v := record.GetDateTime("created").String(); v != autodateTest.String() { |
| 368 | t.Fatalf("Expected created to be %q, got %q", autodateTest.String(), v) |
| 369 | } |
| 370 | if v := record.GetString("custom"); v != "test_custom" { |
| 371 | t.Fatalf("Expected custom to be %q, got %q", "test_custom", v) |
| 372 | } |
| 373 | |
| 374 | // check clone |
| 375 | if v := record.Clone().LastSavedPK(); v != originalId { |
| 376 | t.Fatalf("Expected the clone LastSavedPK to be %q, got %q", originalId, v) |
| 377 | } |
| 378 | if v := record.Clone().PK(); v != record.Id { |
| 379 | t.Fatalf("Expected the clone PK to be %q, got %q", record.Id, v) |
| 380 | } |
| 381 | if v := record.Clone().Id; v != record.Id { |
| 382 | t.Fatalf("Expected the clone id to be %q, got %q", record.Id, v) |
nothing calls this directly
no test coverage detected
searching dependent graphs…