From f6acc4763ed0158473e0046ac9fb86597d5a516e Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sun, 23 Oct 2022 21:53:11 +0800 Subject: test(db): add missing tests (#7208) --- internal/db/two_factors_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'internal/db/two_factors_test.go') diff --git a/internal/db/two_factors_test.go b/internal/db/two_factors_test.go index 36e4eeca..ddff3fce 100644 --- a/internal/db/two_factors_test.go +++ b/internal/db/two_factors_test.go @@ -29,7 +29,9 @@ func TestTwoFactor_BeforeCreate(t *testing.T) { } t.Run("CreatedUnix has been set", func(t *testing.T) { - tf := &TwoFactor{CreatedUnix: 1} + tf := &TwoFactor{ + CreatedUnix: 1, + } _ = tf.BeforeCreate(db) assert.Equal(t, int64(1), tf.CreatedUnix) }) @@ -41,6 +43,24 @@ func TestTwoFactor_BeforeCreate(t *testing.T) { }) } +func TestTwoFactor_AfterFind(t *testing.T) { + now := time.Now() + db := &gorm.DB{ + Config: &gorm.Config{ + SkipDefaultTransaction: true, + NowFunc: func() time.Time { + return now + }, + }, + } + + tf := &TwoFactor{ + CreatedUnix: now.Unix(), + } + _ = tf.AfterFind(db) + assert.Equal(t, tf.CreatedUnix, tf.Created.Unix()) +} + func TestTwoFactors(t *testing.T) { if testing.Short() { t.Skip() -- cgit v1.2.3