Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/emails/hermes_user_email_factory_test.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 3.1 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/emails/hermes_user_email_factory_test.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/api/pkg/emails/hermes_user_email_factory_test.go
-
curl -L -o hermes_user_email_factory_test.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/emails/hermes_user_email_factory_test.go
3.1 kB
| package emails | |
| import ( | |
| "testing" | |
| "time" | |
| "github.com/NdoleStudio/httpsms/pkg/entities" | |
| "github.com/stretchr/testify/assert" | |
| ) | |
| func testUserEmailFactory() UserEmailFactory { | |
| return NewHermesUserEmailFactory(&HermesGeneratorConfig{ | |
| AppURL: "https://httpsms.com", | |
| AppName: "httpSMS", | |
| AppLogoURL: "https://httpsms.com/logo.png", | |
| }) | |
| } | |
| func TestFormatBillingDate_RendersInProvidedTimezone(t *testing.T) { | |
| // 2026-06-19 02:00 UTC | |
| timestamp := time.Date(2026, 6, 19, 2, 0, 0, 0, time.UTC) | |
| // A timezone five hours behind UTC rolls back to the previous day. | |
| behind := time.FixedZone("UTC-5", -5*60*60) | |
| assert.Equal(t, "18 June 2026", formatBillingDate(timestamp, behind)) | |
| // A timezone ahead of UTC stays on the same day. | |
| ahead := time.FixedZone("UTC+10", 10*60*60) | |
| assert.Equal(t, "19 June 2026", formatBillingDate(timestamp, ahead)) | |
| // UTC renders the underlying date as-is. | |
| assert.Equal(t, "19 June 2026", formatBillingDate(timestamp, time.UTC)) | |
| } | |
| func TestUsageLimitExceeded_IncludesBreakdownAndBillingPeriod(t *testing.T) { | |
| factory := testUserEmailFactory() | |
| user := &entities.User{ | |
| Email: "name@email.com", | |
| Timezone: "UTC", | |
| SubscriptionName: entities.SubscriptionNameProMonthly, | |
| } | |
| usage := &entities.BillingUsage{ | |
| SentMessages: 3000, | |
| ReceivedMessages: 2000, | |
| StartTimestamp: time.Date(2026, 6, 19, 0, 0, 0, 0, time.UTC), | |
| EndTimestamp: time.Date(2026, 7, 18, 23, 59, 59, 0, time.UTC), | |
| } | |
| email, err := factory.UsageLimitExceeded(user, usage) | |
| assert.NoError(t, err) | |
| assert.Equal(t, "name@email.com", email.ToEmail) | |
| assert.Equal(t, "⚠️ You have exceeded your plan limit", email.Subject) | |
| assert.Contains(t, email.Text, "limit of 5,000 messages") | |
| assert.Contains(t, email.Text, "Between 19 June 2026 and 18 July 2026") | |
| assert.Contains(t, email.Text, "you sent 3,000 messages and received 2,000") | |
| assert.Contains(t, email.Text, "for a total of 5,000") | |
| assert.Contains(t, email.HTML, "you sent 3,000 messages and received 2,000") | |
| } | |
| func TestUsageLimitAlert_IncludesPercentBreakdownAndLimit(t *testing.T) { | |
| factory := testUserEmailFactory() | |
| user := &entities.User{ | |
| Email: "name@email.com", | |
| Timezone: "UTC", | |
| SubscriptionName: entities.SubscriptionName20KMonthly, | |
| } | |
| usage := &entities.BillingUsage{ | |
| SentMessages: 11_357, | |
| ReceivedMessages: 6_643, | |
| StartTimestamp: time.Date(2026, 6, 19, 0, 0, 0, 0, time.UTC), | |
| EndTimestamp: time.Date(2026, 7, 18, 23, 59, 59, 0, time.UTC), | |
| } | |
| email, err := factory.UsageLimitAlert(user, usage) | |
| assert.NoError(t, err) | |
| assert.Equal(t, "name@email.com", email.ToEmail) | |
| assert.Equal(t, "⚠️ 90% Usage Limit Alert", email.Subject) | |
| assert.Contains(t, email.Text, "used 90% of your monthly SMS limit") | |
| assert.Contains(t, email.Text, "Between 19 June 2026 and 18 July 2026") | |
| assert.Contains(t, email.Text, "you sent 11,357 messages and received 6,643") | |
| assert.Contains(t, email.Text, "for a total of 18,000 out of your 20,000 message limit") | |
| assert.Contains(t, email.HTML, "for a total of 18,000 out of your 20,000 message limit") | |
| } | |