(t *testing.T)
| 234 | } |
| 235 | |
| 236 | func TestRecordFresh(t *testing.T) { |
| 237 | t.Parallel() |
| 238 | |
| 239 | app, _ := tests.NewTestApp() |
| 240 | defer app.Cleanup() |
| 241 | |
| 242 | record, err := app.FindAuthRecordByEmail("users", "test@example.com") |
| 243 | if err != nil { |
| 244 | t.Fatal(err) |
| 245 | } |
| 246 | originalId := record.Id |
| 247 | |
| 248 | extraFieldsCheck := []string{`"email":`, `"custom":`} |
| 249 | |
| 250 | autodateTest := types.NowDateTime() |
| 251 | |
| 252 | // change the fields |
| 253 | record.Id = "changed" |
| 254 | record.Set("name", "name_new") |
| 255 | record.Set("custom", "test_custom") |
| 256 | record.SetRaw("created", autodateTest) |
| 257 | record.SetExpand(map[string]any{"test": 123}) |
| 258 | record.IgnoreEmailVisibility(true) |
| 259 | record.IgnoreUnchangedFields(true) |
| 260 | record.WithCustomData(true) |
| 261 | record.Unhide(record.Collection().Fields.FieldNames()...) |
| 262 | |
| 263 | // ensure that the email visibility and the custom data toggles are active |
| 264 | raw, err := record.MarshalJSON() |
| 265 | if err != nil { |
| 266 | t.Fatal(err) |
| 267 | } |
| 268 | rawStr := string(raw) |
| 269 | for _, f := range extraFieldsCheck { |
| 270 | if !strings.Contains(rawStr, f) { |
| 271 | t.Fatalf("Expected %s in\n%s", f, rawStr) |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | // check changes |
| 276 | if v := record.GetString("name"); v != "name_new" { |
| 277 | t.Fatalf("Expected name to be %q, got %q", "name_new", v) |
| 278 | } |
| 279 | if v := record.GetDateTime("created").String(); v != autodateTest.String() { |
| 280 | t.Fatalf("Expected created to be %q, got %q", autodateTest.String(), v) |
| 281 | } |
| 282 | if v := record.GetString("custom"); v != "test_custom" { |
| 283 | t.Fatalf("Expected custom to be %q, got %q", "test_custom", v) |
| 284 | } |
| 285 | |
| 286 | // check fresh |
| 287 | if v := record.Fresh().LastSavedPK(); v != originalId { |
| 288 | t.Fatalf("Expected the fresh LastSavedPK to be %q, got %q", originalId, v) |
| 289 | } |
| 290 | if v := record.Fresh().PK(); v != record.Id { |
| 291 | t.Fatalf("Expected the fresh PK to be %q, got %q", record.Id, v) |
| 292 | } |
| 293 | if v := record.Fresh().Id; v != record.Id { |
nothing calls this directly
no test coverage detected
searching dependent graphs…