2025-06-30 12:37:33 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
|
|
func TestBuildNtfyMessage(t *testing.T) {
|
|
|
|
|
rsvp := &Rsvp{
|
|
|
|
|
Id: 1,
|
|
|
|
|
Attending: false,
|
|
|
|
|
PartySize: 1,
|
|
|
|
|
PartyMembers: []Member{
|
|
|
|
|
{Name: "test", Child: false, DietaryPreferences: ""},
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-09-02 16:48:44 +02:00
|
|
|
msg := BuildRsvpMessage("test", rsvp)
|
2025-06-30 12:37:33 +02:00
|
|
|
|
|
|
|
|
if msg.Topic != "test" {
|
|
|
|
|
t.Fatal("message topic is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if msg.Title != "Someone can't make it" {
|
|
|
|
|
t.Fatal("message title is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if msg.Message != "test\ncan't make it" {
|
|
|
|
|
t.Fatal("message message is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if len(msg.Tags) != 1 || msg.Tags[0] != "x" {
|
|
|
|
|
t.Fatal("message tags are incorrect")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rsvp = &Rsvp{
|
|
|
|
|
Id: 1,
|
|
|
|
|
Attending: true,
|
|
|
|
|
PartySize: 1,
|
|
|
|
|
PartyMembers: []Member{
|
|
|
|
|
{Name: "test", Child: false, DietaryPreferences: ""},
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-09-02 16:48:44 +02:00
|
|
|
msg = BuildRsvpMessage("test", rsvp)
|
2025-06-30 12:37:33 +02:00
|
|
|
|
|
|
|
|
if msg.Topic != "test" {
|
|
|
|
|
t.Fatal("message topic is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if msg.Title != "1 person confirmed!" {
|
|
|
|
|
t.Fatal("message title is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if msg.Message != "Here's who is coming 👇\n- 🧓 test, n/a" {
|
|
|
|
|
t.Fatalf("message message is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if len(msg.Tags) != 2 || msg.Tags[0] != "white_check_mark" || msg.Tags[1] != "one" {
|
|
|
|
|
t.Fatal("message tags are incorrect")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rsvp = &Rsvp{
|
|
|
|
|
Id: 1,
|
|
|
|
|
Attending: true,
|
|
|
|
|
PartySize: 2,
|
|
|
|
|
PartyMembers: []Member{
|
|
|
|
|
{Name: "test1", Child: false, DietaryPreferences: ""},
|
|
|
|
|
{Name: "test2", Child: true, DietaryPreferences: "no tobacco"},
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-09-02 16:48:44 +02:00
|
|
|
msg = BuildRsvpMessage("test", rsvp)
|
2025-06-30 12:37:33 +02:00
|
|
|
|
|
|
|
|
if msg.Topic != "test" {
|
|
|
|
|
t.Fatal("message topic is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if msg.Title != "2 people confirmed!" {
|
|
|
|
|
t.Fatal("message title is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if msg.Message != "Here's who is coming 👇\n- 🧓 test1, n/a\n- 👶 test2, no tobacco" {
|
|
|
|
|
t.Fatalf("message message is incorrect")
|
|
|
|
|
}
|
|
|
|
|
if len(msg.Tags) != 2 || msg.Tags[0] != "white_check_mark" || msg.Tags[1] != "two" {
|
|
|
|
|
t.Fatal("message tags are incorrect")
|
|
|
|
|
}
|
|
|
|
|
}
|