feat(notifications): send product notifications with a rights check right before each send
This commit is contained in:
1 parent
a856066316
commit
623d41b969
59 files changed
+4125
-1126
No files matched your search
@@ -258,3 +258,43 @@ func TestLoadFromEnvRejectsMailSettings(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFromEnvServiceReserveDefaultsToAFifthOfEachLimit(t *testing.T) {
|
||||
settings, err := LoadFromEnv(mailEnvironment(map[string]string{"EMAIL_PROVIDER": "resend", "RESEND_API_KEY": testResendAPIKey}))
|
||||
if err != nil {
|
||||
t.Fatalf("LoadFromEnv() error = %v", err)
|
||||
}
|
||||
if settings.EmailServiceReserveDaily != 20 || settings.EmailServiceReserveMonthly != 600 {
|
||||
t.Fatalf("service reserve = %d a day and %d a month, want 20 and 600 for the Resend Free limits", settings.EmailServiceReserveDaily, settings.EmailServiceReserveMonthly)
|
||||
}
|
||||
|
||||
// Zero is a stated reserve, not an unset one: the notifications may then use
|
||||
// the whole window.
|
||||
settings, err = LoadFromEnv(mailEnvironment(map[string]string{
|
||||
"EMAIL_PROVIDER": "resend", "RESEND_API_KEY": testResendAPIKey,
|
||||
"EMAIL_SERVICE_RESERVE_DAILY": "5", "EMAIL_SERVICE_RESERVE_MONTHLY": "0",
|
||||
}))
|
||||
if err != nil {
|
||||
t.Fatalf("LoadFromEnv() with a stated reserve error = %v", err)
|
||||
}
|
||||
if settings.EmailServiceReserveDaily != 5 || settings.EmailServiceReserveMonthly != 0 {
|
||||
t.Fatalf("service reserve = %d a day and %d a month, want 5 and 0", settings.EmailServiceReserveDaily, settings.EmailServiceReserveMonthly)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFromEnvRejectsAServiceReserveThatLeavesNoRoom(t *testing.T) {
|
||||
for name, value := range map[string]map[string]string{
|
||||
"daily reserve equal to the daily limit": {"EMAIL_SERVICE_RESERVE_DAILY": "100"},
|
||||
"monthly reserve above the monthly limit": {"EMAIL_SERVICE_RESERVE_MONTHLY": "3001"},
|
||||
"negative reserve": {"EMAIL_SERVICE_RESERVE_DAILY": "-1"},
|
||||
} {
|
||||
values := map[string]string{"EMAIL_PROVIDER": "resend", "RESEND_API_KEY": testResendAPIKey}
|
||||
for key, reserve := range value {
|
||||
values[key] = reserve
|
||||
}
|
||||
_, err := LoadFromEnv(mailEnvironment(values))
|
||||
if err == nil || !strings.Contains(err.Error(), "EMAIL_SERVICE_RESERVE") {
|
||||
t.Fatalf("%s: LoadFromEnv() error = %v, want a refusal that names the reserve", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user