Debian Codegraph @

internal/events/recipient_test.go

raw symbols SCIP
1 package events
2
3 import (
4 "testing"
5
6 "launchpad.net/email-reminder/internal/util"
7 )
8
9 func TestRecipientToEmailRecipient(t *testing.T) {
10 tests := []struct {
11 name string
12 recipient Recipient
13 want util.EmailRecipient
14 }{
15 {
16 name: "recipient with first and last name",
17 recipient: Recipient{
18 Name: "John Doe",
19 Email: "[email protected]",
20 },
21 want: util.EmailRecipient{
22 Email: "[email protected]",
23 FirstName: "John",
24 LastName: "Doe",
25 },
26 },
27 {
28 name: "recipient with three-part name",
29 recipient: Recipient{
30 Name: "John Doe Smith",
31 Email: "[email protected]",
32 },
33 want: util.EmailRecipient{
34 Email: "[email protected]",
35 FirstName: "John",
36 LastName: "Doe Smith",
37 },
38 },
39 {
40 name: "recipient with single name",
41 recipient: Recipient{
42 Name: "John",
43 Email: "[email protected]",
44 },
45 want: util.EmailRecipient{
46 Email: "[email protected]",
47 FirstName: "John",
48 LastName: "",
49 },
50 },
51 {
52 name: "recipient with email only",
53 recipient: Recipient{
54 Name: "",
55 Email: "[email protected]",
56 },
57 want: util.EmailRecipient{
58 Email: "[email protected]",
59 FirstName: "",
60 LastName: "",
61 },
62 },
63 {
64 name: "recipient with invalid email",
65 recipient: Recipient{
66 Name: "John Doe",
67 Email: "john@",
68 },
69 want: util.EmailRecipient{
70 Email: "",
71 FirstName: "John",
72 LastName: "Doe",
73 },
74 },
75 {
76 name: "recipient with whitespace in name",
77 recipient: Recipient{
78 Name: " John Doe ",
79 Email: " [email protected] ",
80 },
81 want: util.EmailRecipient{
82 Email: "[email protected]",
83 FirstName: "John",
84 LastName: "Doe",
85 },
86 },
87 {
88 name: "recipient with whitespace-only name",
89 recipient: Recipient{
90 Name: " ",
91 Email: "[email protected]",
92 },
93 want: util.EmailRecipient{
94 Email: "[email protected]",
95 FirstName: "",
96 LastName: "",
97 },
98 },
99 {
100 name: "recipient with multiple spaces between names",
101 recipient: Recipient{
102 Name: "John Doe Smith",
103 Email: "[email protected]",
104 },
105 want: util.EmailRecipient{
106 Email: "[email protected]",
107 FirstName: "John",
108 LastName: "Doe Smith",
109 },
110 },
111 }
112
113 for _, tt := range tests {
114 t.Run(tt.name, func(t *testing.T) {
115 got := tt.recipient.ToEmailRecipient()
116 if got.Email != tt.want.Email {
117 t.Errorf("ToEmailRecipient().Email = %q, want %q", got.Email, tt.want.Email)
118 }
119 if got.FirstName != tt.want.FirstName {
120 t.Errorf("ToEmailRecipient().FirstName = %q, want %q", got.FirstName, tt.want.FirstName)
121 }
122 if got.LastName != tt.want.LastName {
123 t.Errorf("ToEmailRecipient().LastName = %q, want %q", got.LastName, tt.want.LastName)
124 }
125 })
126 }
127 }