MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestGetEffectiveDate

Function TestGetEffectiveDate

model/transaction_test.go:287–325  ·  view source on GitHub ↗

TestGetEffectiveDate tests the GetEffectiveDate helper method

(t *testing.T)

Source from the content-addressed store, hash-verified

285
286// TestGetEffectiveDate tests the GetEffectiveDate helper method
287func TestGetEffectiveDate(t *testing.T) {
288 now := time.Now()
289 yesterday := now.Add(-24 * time.Hour)
290
291 tests := []struct {
292 name string
293 transaction Transaction
294 expectedTime time.Time
295 description string
296 }{
297 {
298 name: "EffectiveDate is set - should return EffectiveDate",
299 transaction: Transaction{
300 CreatedAt: now,
301 EffectiveDate: &yesterday,
302 },
303 expectedTime: yesterday,
304 description: "When EffectiveDate is explicitly set, it should be returned",
305 },
306 {
307 name: "EffectiveDate is nil - should return CreatedAt",
308 transaction: Transaction{
309 CreatedAt: now,
310 EffectiveDate: nil,
311 },
312 expectedTime: now,
313 description: "When EffectiveDate is nil, CreatedAt should be returned as fallback",
314 },
315 }
316
317 for _, tt := range tests {
318 t.Run(tt.name, func(t *testing.T) {
319 result := tt.transaction.GetEffectiveDate()
320 if !result.Equal(tt.expectedTime) {
321 t.Errorf("GetEffectiveDate() = %v, want %v. %s", result, tt.expectedTime, tt.description)
322 }
323 })
324 }
325}

Callers

nothing calls this directly

Calls 1

GetEffectiveDateMethod · 0.80

Tested by

no test coverage detected