package main import ( "testing" "time" "github.com/stretchr/testify/require" ) func TestWhatsAppBatchText(t *testing.T) { at := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC) testCases := []struct { name string batch WhatsAppBatch text string }{ { name: "a private chat with a message of another person starts a turn", batch: WhatsAppBatch{ Chat: whatsappTestChat, Messages: []WhatsAppMessage{ { Sender: "Ana Souza", Time: at, Text: "Are you at home?", }, { Time: at.Add(3 * time.Minute), Text: "Yes", Mine: true, }, }, }, text: "[WhatsApp] Ana Souza, private chat 15550002222@s.whatsapp.net, Thursday 2026-01-01\n12:00 Ana Souza: Are you at home?\n12:03 You: Yes\n" + whatsappBatchEmptyReply, }, { name: "a private chat with messages of the user only starts no turn", batch: WhatsAppBatch{ Chat: whatsappTestChat, Messages: []WhatsAppMessage{ { Time: at, Text: "On my way.", Mine: true, }, }, }, text: "[WhatsApp] Ana Souza, private chat 15550002222@s.whatsapp.net, Thursday 2026-01-01\n12:00 You: On my way.", }, { name: "a group with no mention of the user starts no turn", batch: WhatsAppBatch{ Chat: whatsappTestGroup, Messages: []WhatsAppMessage{ { Sender: "Bruno Lima", Time: at, Text: "Who brings the cake?", }, }, }, text: "[WhatsApp] Family, group 120363000000000001@g.us, Thursday 2026-01-01\n12:00 Bruno Lima: Who brings the cake?", }, { name: "a group with a mention of the user starts a turn", batch: WhatsAppBatch{ Chat: whatsappTestGroup, Messages: []WhatsAppMessage{ { Sender: "Bruno Lima", Time: at, Text: "@you can you bring the cake?", Mention: true, }, }, }, text: "[WhatsApp] Family, group 120363000000000001@g.us, Thursday 2026-01-01\n12:00 Bruno Lima (mentions you): @you can you bring the cake?\n" + whatsappBatchEmptyReply, }, { name: "a group with a reply to the user starts a turn", batch: WhatsAppBatch{ Chat: whatsappTestGroup, Messages: []WhatsAppMessage{ { Sender: "Bruno Lima", Time: at, Text: "Thanks!", Reply: true, }, }, }, text: "[WhatsApp] Family, group 120363000000000001@g.us, Thursday 2026-01-01\n12:00 Bruno Lima (replies to you): Thanks!\n" + whatsappBatchEmptyReply, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { require.Equal(t, tc.text, tc.batch.Text(time.UTC)) }) } }