Skip to content
Merged
2 changes: 1 addition & 1 deletion api/pkg/validators/phone_handler_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (validator *PhoneHandlerValidator) ValidateUpsert(ctx context.Context, user
},
"messages_per_minute": []string{
"min:0",
"max:60",
"max:30",
},
"max_send_attempts": []string{
"min:0",
Expand Down
31 changes: 31 additions & 0 deletions api/pkg/validators/phone_handler_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@ func TestPhoneHandlerValidatorAcceptsHTTPSNotificationURLOnUpsert(t *testing.T)
assert.Empty(t, errors)
}

func TestPhoneHandlerValidatorMessagesPerMinuteLimit(t *testing.T) {
tests := []struct {
name string
messagesPerMinute uint
valid bool
}{
{name: "zero", messagesPerMinute: 0, valid: true},
{name: "maximum", messagesPerMinute: 30, valid: true},
{name: "above maximum", messagesPerMinute: 31, valid: false},
{name: "previous maximum", messagesPerMinute: 60, valid: false},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
validator := newPhoneHandlerValidator()
errors := validator.ValidateUpsert(context.Background(), "", requests.PhoneUpsert{
PhoneNumber: "+18005550199",
SIM: entities.SIM1.String(),
MessageExpirationSeconds: 60,
MessagesPerMinute: test.messagesPerMinute,
})

if test.valid {
assert.Empty(t, errors)
} else {
assert.NotEmpty(t, errors["messages_per_minute"])
}
})
}
}

func TestPhoneHandlerValidatorAcceptsPrivateAndLoopbackNotificationHosts(t *testing.T) {
validator := newPhoneHandlerValidator()

Expand Down
6 changes: 3 additions & 3 deletions tests/adapter_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestAdapterGatewayOutgoingMessage(t *testing.T) {
ctx := context.Background()
phone := setupAdapterPhone(ctx, t, 60)
phone := setupAdapterPhone(ctx, t, 30)
contact := randomPhoneNumber()
content := "Adapter outgoing " + randomEncryptionKey()

Expand Down Expand Up @@ -42,7 +42,7 @@ func TestAdapterGatewayOutgoingMessage(t *testing.T) {

func TestAdapterGatewayIncomingMessage(t *testing.T) {
ctx := context.Background()
phone := setupAdapterPhone(ctx, t, 60)
phone := setupAdapterPhone(ctx, t, 30)
contact := randomPhoneNumber()
content := "Adapter incoming " + randomEncryptionKey()

Expand All @@ -57,7 +57,7 @@ func TestAdapterGatewayIncomingMessage(t *testing.T) {

func TestAdapterGatewayHeartbeatWakeUp(t *testing.T) {
ctx := context.Background()
phone := setupAdapterPhone(ctx, t, 60)
phone := setupAdapterPhone(ctx, t, 30)
monitorID := uuid.NewString()

dispatchInternalEvent(ctx, t, map[string]any{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func TestArchiveNewOutgoingMessageThreadsOnFirstRegistration(t *testing.T) {

func TestArchiveNewOutgoingMessageThreadsPerPhoneAndDirection(t *testing.T) {
ctx := context.Background()
enabledPhone := setupPhone(ctx, t, 60)
defaultPhone := setupPhone(ctx, t, 60)
enabledPhone := setupPhone(ctx, t, 30)
defaultPhone := setupPhone(ctx, t, 30)
require.NotEqual(t, enabledPhone.PhoneNumber, defaultPhone.PhoneNumber)

existingContact := randomPhoneNumber()
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestArchiveNewOutgoingMessageThreadsPerPhoneAndDirection(t *testing.T) {

func TestArchiveNewOutgoingMessageThreadsToggleAndPartialUpdates(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)

require.True(t, updatePhoneThreadSettings(ctx, t, phone, map[string]bool{"archive_new_outgoing_message_threads": true}).ArchiveNewOutgoingMessageThreads)
settings := updatePhoneThreadSettings(ctx, t, phone, map[string]bool{"unarchive_thread": true})
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestArchiveNewOutgoingMessageThreadsReplyRespectsUnarchiveSetting(t *testin
} {
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)
updatePhoneThreadSettings(ctx, t, phone, map[string]bool{
"archive_new_outgoing_message_threads": true,
"unarchive_thread": test.unarchive,
Expand Down
2 changes: 1 addition & 1 deletion tests/contacts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestContacts_CSVUpload(t *testing.T) {

func TestContacts_MessageThreadsIncludeContactDetails(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)
contactPhone := randomPhoneNumber()
marker := strings.ToLower(uuid.New().String())

Expand Down
12 changes: 6 additions & 6 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func TestSendSMS_Encrypted(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)

encryptionKey := randomEncryptionKey()
signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestSendSMS_Encrypted(t *testing.T) {

func TestReceiveSMS_Encrypted(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)

encryptionKey := randomEncryptionKey()
signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestRotateAPIKey_InvalidatesCache(t *testing.T) {

func TestSendSMS_OutstandingFlow(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)

signingKey, webhookPath := setupWebhook(ctx, t, phone.PhoneNumber, []string{
"message.phone.sent",
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestSendSMS_OutstandingFlow(t *testing.T) {

func TestHeartbeat_StoreAndIndex(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)

// Store a heartbeat via phone API key (retry to allow async phone-API-key association)
storePayload := map[string]interface{}{
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestHeartbeat_StoreAndIndex(t *testing.T) {

func TestBulkSMS_CSV(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)

// Build CSV content with 1 message
contact := randomPhoneNumber()
Expand Down Expand Up @@ -474,7 +474,7 @@ func TestBulkSMS_CSV(t *testing.T) {

func TestBulkSMS_Excel(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)

contact1 := randomPhoneNumber()
contact2 := randomPhoneNumber()
Expand Down
2 changes: 1 addition & 1 deletion tests/read_receipts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func clearMessageThreadUnreadCount(ctx context.Context, t *testing.T, threadID s

func TestMessageThreadUnreadCount(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)
contact := randomPhoneNumber()

requestJSON(
Expand Down
4 changes: 2 additions & 2 deletions tests/unarchive_thread_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func archiveThread(ctx context.Context, t *testing.T, threadID string) {

func TestUnarchiveThreadOnReceive_Enabled(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)
setUnarchiveThread(ctx, t, phone.PhoneNumber, true)

contact := randomPhoneNumber()
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestUnarchiveThreadOnReceive_Enabled(t *testing.T) {

func TestUnarchiveThreadOnReceive_Disabled(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60) // unarchive_thread defaults to false; do not enable it
phone := setupPhone(ctx, t, 30) // unarchive_thread defaults to false; do not enable it

contact := randomPhoneNumber()
content1 := "first inbound " + randomEncryptionKey()
Expand Down
6 changes: 3 additions & 3 deletions tests/unread_filter_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func fetchFilteredThreads(ctx context.Context, t *testing.T, owner string, archi

func TestMessageThreadUnreadFilter(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
otherPhone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)
otherPhone := setupPhone(ctx, t, 30)
require.NotEqual(t, phone.PhoneNumber, otherPhone.PhoneNumber)
unreadContact := randomPhoneNumber()
readContact := randomPhoneNumber()
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestMessageThreadUnreadFilterRejectsInvalidValue(t *testing.T) {

func TestMessageThreadPaginationReturnsRequestedPages(t *testing.T) {
ctx := context.Background()
phone := setupPhone(ctx, t, 60)
phone := setupPhone(ctx, t, 30)
timestamp := time.Now().Add(-time.Minute).Truncate(time.Second)
for index := 0; index < 20; index++ {
receiveInbound(ctx, t, phone.PhoneAPIKey, fmt.Sprintf("+1800554%04d", index), phone.PhoneNumber, "Pagination thread", timestamp)
Expand Down
Loading
Loading