(t *testing.T)
| 236 | } |
| 237 | |
| 238 | func TestAutodateFieldIntercept(t *testing.T) { |
| 239 | app, _ := tests.NewTestApp() |
| 240 | defer app.Cleanup() |
| 241 | |
| 242 | initialDate, err := types.ParseDateTime("2024-01-02 03:04:05.789Z") |
| 243 | if err != nil { |
| 244 | t.Fatal(err) |
| 245 | } |
| 246 | |
| 247 | collection := core.NewBaseCollection("test_collection") |
| 248 | |
| 249 | scenarios := []struct { |
| 250 | name string |
| 251 | actionName string |
| 252 | field *core.AutodateField |
| 253 | record func() *core.Record |
| 254 | expected string |
| 255 | }{ |
| 256 | { |
| 257 | "non-matching action", |
| 258 | "test", |
| 259 | &core.AutodateField{Name: "test", OnCreate: true, OnUpdate: true}, |
| 260 | func() *core.Record { |
| 261 | return core.NewRecord(collection) |
| 262 | }, |
| 263 | "", |
| 264 | }, |
| 265 | { |
| 266 | "create with zero value (disabled onCreate)", |
| 267 | core.InterceptorActionCreateExecute, |
| 268 | &core.AutodateField{Name: "test", OnCreate: false, OnUpdate: true}, |
| 269 | func() *core.Record { |
| 270 | return core.NewRecord(collection) |
| 271 | }, |
| 272 | "", |
| 273 | }, |
| 274 | { |
| 275 | "create with zero value", |
| 276 | core.InterceptorActionCreateExecute, |
| 277 | &core.AutodateField{Name: "test", OnCreate: true, OnUpdate: true}, |
| 278 | func() *core.Record { |
| 279 | return core.NewRecord(collection) |
| 280 | }, |
| 281 | "{NOW}", |
| 282 | }, |
| 283 | { |
| 284 | "create with non-zero value", |
| 285 | core.InterceptorActionCreateExecute, |
| 286 | &core.AutodateField{Name: "test", OnCreate: true, OnUpdate: true}, |
| 287 | func() *core.Record { |
| 288 | record := core.NewRecord(collection) |
| 289 | record.SetRaw("test", initialDate) |
| 290 | return record |
| 291 | }, |
| 292 | initialDate.String(), |
| 293 | }, |
| 294 | { |
| 295 | "update with zero value (disabled onUpdate)", |
nothing calls this directly
no test coverage detected
searching dependent graphs…