[CLD-6536] Adjustments to cloud annual renewal announcement bar (#25927)

* Adjustments to cloud annual renewal announcement bar

* Add exclusion for trials

* Add more exceptions for when on trial during renewal period

* Add support for simulated_current_time_ms

* A few more changes to allow us to test this post-merge

* Fix tests, pipeline

* Final fix around emails

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Nick Misasi
2024-01-16 17:48:59 -05:00
коммит произвёл GitHub
родитель d1e37783cc
Коммит 7039176d31
8 изменённых файлов: 50 добавлений и 22 удалений

Просмотреть файл

@@ -5,8 +5,6 @@ package model
import (
"encoding/json"
"os"
"strconv"
"strings"
"time"
)
@@ -185,17 +183,16 @@ type Subscription struct {
BillingType string `json:"billing_type"`
CancelAt *int64 `json:"cancel_at"`
WillRenew string `json:"will_renew"`
SimulatedCurrentTimeMs *int64 `json:"simulated_current_time_ms"`
}
func (s *Subscription) DaysToExpiration() int64 {
now := time.Now().UnixMilli()
// Allows us to base the current time off of an environment variable for testing purposes
if GetServiceEnvironment() == ServiceEnvironmentTest {
if currTime, set := os.LookupEnv("CLOUD_MOCK_CURRENT_TIME"); set {
timeInt, err := strconv.ParseInt(currTime, 10, 64)
if err == nil {
now = time.Unix(timeInt, 0).UnixMilli()
}
// In the test environment we have test clocks. A test clock is a ms timestamp
// If it's not nil, we use it as the current time in all calculations
if s.SimulatedCurrentTimeMs != nil {
now = *s.SimulatedCurrentTimeMs
}
}
daysToExpiry := (s.EndAt - now) / (1000 * 60 * 60 * 24)