Move get or create true up review status into the app interface, adds a function to execute checks for being within true up review widnow (and tests), adds a job for sending true up telemetry.
Этот коммит содержится в:
@@ -37,6 +37,8 @@ var LicenseValidator LicenseValidatorIface
|
||||
|
||||
const trueUpReviewDueDay = 15
|
||||
const businessQuarterStep = 3
|
||||
const day = time.Hour * 24
|
||||
const week = day * 7
|
||||
|
||||
func init() {
|
||||
if LicenseValidator == nil {
|
||||
@@ -245,3 +247,13 @@ func GetNextTrueUpReviewDueDate(now time.Time) time.Time {
|
||||
|
||||
return time.Date(now.Year(), nextQuarterEndMonth, trueUpReviewDueDay, 0, 0, 0, 0, now.Location())
|
||||
}
|
||||
|
||||
func IsTrueUpReviewDueDateWithinTheNextTwoWeeks(now time.Time, dueDate time.Time) bool {
|
||||
dueDateWindow := dueDate.Add(-(week * 2))
|
||||
|
||||
if now.Before(dueDateWindow) || now.After(dueDate) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -154,3 +154,52 @@ func TestGetNextTrueUpReviewDueDate(t *testing.T) {
|
||||
assert.Equal(t, 2023, due.Year())
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsTrueUpReviewDueDateWithinTheNextTwoWeeks(t *testing.T) {
|
||||
t.Run("Ensure a date within two weeks before the due date returns true", func(t *testing.T) {
|
||||
// 1 Day before the due date
|
||||
now := time.Date(2022, time.December, 14, 0, 0, 0, 0, time.Local)
|
||||
// Due date is December 15th, 2022
|
||||
due := GetNextTrueUpReviewDueDate(now)
|
||||
|
||||
res := IsTrueUpReviewDueDateWithinTheNextTwoWeeks(now, due)
|
||||
assert.True(t, res)
|
||||
})
|
||||
|
||||
t.Run("Ensure a date that is more than two weeks before the due date returns false", func(t *testing.T) {
|
||||
// 15 Days before the due date
|
||||
now := time.Date(2022, time.November, 30, 0, 0, 0, 0, time.Local)
|
||||
// Due date is December 15th, 2022
|
||||
due := GetNextTrueUpReviewDueDate(now)
|
||||
|
||||
res := IsTrueUpReviewDueDateWithinTheNextTwoWeeks(now, due)
|
||||
assert.False(t, res)
|
||||
})
|
||||
|
||||
t.Run("Ensure a date that past the due date returns false", func(t *testing.T) {
|
||||
now := time.Date(2022, time.December, 16, 0, 0, 0, 0, time.Local)
|
||||
|
||||
// Due date is December 15th, 2022
|
||||
dueNow := time.Date(2022, time.December, 15, 0, 0, 0, 0, time.Local)
|
||||
due := GetNextTrueUpReviewDueDate(dueNow)
|
||||
|
||||
res := IsTrueUpReviewDueDateWithinTheNextTwoWeeks(now, due)
|
||||
assert.False(t, res)
|
||||
})
|
||||
|
||||
t.Run("Ensure a date that is on the due date returns true", func(t *testing.T) {
|
||||
now := time.Date(2022, time.December, 15, 0, 0, 0, 0, time.Local)
|
||||
due := GetNextTrueUpReviewDueDate(now)
|
||||
|
||||
res := IsTrueUpReviewDueDateWithinTheNextTwoWeeks(now, due)
|
||||
assert.True(t, res)
|
||||
})
|
||||
|
||||
t.Run("Ensure a date that is on the first day of the due date window returns true", func(t *testing.T) {
|
||||
now := time.Date(2022, time.December, 1, 0, 0, 0, 0, time.Local)
|
||||
due := GetNextTrueUpReviewDueDate(now)
|
||||
|
||||
res := IsTrueUpReviewDueDateWithinTheNextTwoWeeks(now, due)
|
||||
assert.True(t, res)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user