| 1 |
package signal |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/onsi/ginkgo/v2" |
| 5 |
"github.com/onsi/gomega" |
| 6 |
) |
| 7 |
|
| 8 |
var _ = ginkgo.Describe("recipients", func() { |
| 9 |
ginkgo.It("should parse valid phone numbers", func() { |
| 10 |
recipients, err := parseRecipients([]string{"+1234567890", "+0987654321"}) |
| 11 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 12 |
gomega.Expect(recipients).To(gomega.Equal([]string{"+1234567890", "+0987654321"})) |
| 13 |
}) |
| 14 |
|
| 15 |
ginkgo.It("should parse valid group IDs", func() { |
| 16 |
recipients, err := parseRecipients([]string{"group.testgroup", "group.abcdef123"}) |
| 17 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 18 |
gomega.Expect(recipients). |
| 19 |
To(gomega.Equal([]string{"group.testgroup", "group.abcdef123"})) |
| 20 |
}) |
| 21 |
|
| 22 |
ginkgo.It("should parse group IDs with base64 characters", func() { |
| 23 |
recipients, err := parseRecipients([]string{"group.ABCD/EFGH=", "group.xyz+abc"}) |
| 24 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 25 |
gomega.Expect(recipients). |
| 26 |
To(gomega.Equal([]string{"group.ABCD/EFGH=", "group.xyz+abc"})) |
| 27 |
}) |
| 28 |
|
| 29 |
ginkgo.It("should parse mixed phone numbers and group IDs", func() { |
| 30 |
recipients, err := parseRecipients( |
| 31 |
[]string{"+1234567890", "group.testgroup", "+0987654321"}, |
| 32 |
) |
| 33 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 34 |
gomega.Expect(recipients). |
| 35 |
To(gomega.Equal([]string{"+1234567890", "group.testgroup", "+0987654321"})) |
| 36 |
}) |
| 37 |
|
| 38 |
ginkgo.It("should parse usernames", func() { |
| 39 |
recipients, err := parseRecipients([]string{"u:someuser.123"}) |
| 40 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 41 |
gomega.Expect(recipients).To(gomega.Equal([]string{"u:someuser.123"})) |
| 42 |
}) |
| 43 |
|
| 44 |
ginkgo.It("should return error for invalid recipients", func() { |
| 45 |
_, err := parseRecipients([]string{"invalid-recipient"}) |
| 46 |
gomega.Expect(err).To(gomega.HaveOccurred()) |
| 47 |
gomega.Expect(err.Error()).To(gomega.ContainSubstring("invalid recipient")) |
| 48 |
}) |
| 49 |
|
| 50 |
ginkgo.It("should return error for mixed valid and invalid recipients", func() { |
| 51 |
_, err := parseRecipients([]string{"+1234567890", "invalid-recipient"}) |
| 52 |
gomega.Expect(err).To(gomega.HaveOccurred()) |
| 53 |
gomega.Expect(err.Error()).To(gomega.ContainSubstring("invalid recipient")) |
| 54 |
}) |
| 55 |
|
| 56 |
ginkgo.It("should return error for empty recipient list", func() { |
| 57 |
_, err := parseRecipients([]string{}) |
| 58 |
gomega.Expect(err).To(gomega.MatchError(ErrNoRecipients)) |
| 59 |
}) |
| 60 |
|
| 61 |
ginkgo.It("should handle group IDs split across path segments", func() { |
| 62 |
recipients, err := parseRecipients([]string{"group.ABCD", "EFGH="}) |
| 63 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 64 |
gomega.Expect(recipients).To(gomega.Equal([]string{"group.ABCD/EFGH="})) |
| 65 |
}) |
| 66 |
|
| 67 |
ginkgo.It("should batch mixed recipient types for separate sends", func() { |
| 68 |
batches := batchRecipients( |
| 69 |
[]string{"+1234567890", "u:someuser.123", "group.testgroup", "+0987654321"}, |
| 70 |
) |
| 71 |
gomega.Expect(batches).To(gomega.Equal([][]string{ |
| 72 |
{"+1234567890", "+0987654321"}, |
| 73 |
{"u:someuser.123"}, |
| 74 |
{"group.testgroup"}, |
| 75 |
})) |
| 76 |
}) |
| 77 |
}) |