]> git.giacomolli.uk - onechat/blobdiff - whatsapp_send_test.go
Submit root events through the local socket
[onechat] / whatsapp_send_test.go
index 85b7d15b6f82535f2909c950bb1b9f536848c272..977d06b08056a46510ed7c7bdd969bdc0e20b415 100644 (file)
@@ -147,35 +147,35 @@ func TestWhatsAppSendRefuses(t *testing.T) {
                err  string
        }{
                {
                err  string
        }{
                {
-                       name: "no id",
+                       name: "refuses no id",
                        id:   " ",
                        chat: whatsappTestAna.String(),
                        text: "hi",
                        err:  "the id must have 1 to 100 bytes",
                },
                {
                        id:   " ",
                        chat: whatsappTestAna.String(),
                        text: "hi",
                        err:  "the id must have 1 to 100 bytes",
                },
                {
-                       name: "no text",
+                       name: "refuses no text",
                        id:   "a",
                        chat: whatsappTestAna.String(),
                        text: "",
                        err:  "the text must have 1 to 65536 bytes",
                },
                {
                        id:   "a",
                        chat: whatsappTestAna.String(),
                        text: "",
                        err:  "the text must have 1 to 65536 bytes",
                },
                {
-                       name: "a name for a chat",
+                       name: "refuses a name for a chat",
                        id:   "a",
                        chat: "Ana Souza",
                        text: "hi",
                        err:  `"Ana Souza" is not the ID of a WhatsApp chat: find the ID with whatsapp_find`,
                },
                {
                        id:   "a",
                        chat: "Ana Souza",
                        text: "hi",
                        err:  `"Ana Souza" is not the ID of a WhatsApp chat: find the ID with whatsapp_find`,
                },
                {
-                       name: "a status broadcast",
+                       name: "refuses a status broadcast",
                        id:   "a",
                        chat: types.StatusBroadcastJID.String(),
                        text: "hi",
                        err:  `"status@broadcast" is not a private chat or a group`,
                },
                {
                        id:   "a",
                        chat: types.StatusBroadcastJID.String(),
                        text: "hi",
                        err:  `"status@broadcast" is not a private chat or a group`,
                },
                {
-                       name: "the chat of the user",
+                       name: "refuses the chat of the user",
                        id:   "a",
                        chat: whatsappTestOwn.String(),
                        text: "hi",
                        id:   "a",
                        chat: whatsappTestOwn.String(),
                        text: "hi",
@@ -190,7 +190,7 @@ func TestWhatsAppSendRefuses(t *testing.T) {
        for _, tc := range testCases {
                t.Run(tc.name, func(t *testing.T) {
                        _, err := whatsapp.Send(t.Context(), tc.id, tc.chat, tc.text, "")
        for _, tc := range testCases {
                t.Run(tc.name, func(t *testing.T) {
                        _, err := whatsapp.Send(t.Context(), tc.id, tc.chat, tc.text, "")
-                       require.EqualError(t, err, tc.err)
+                       require.EqualError(t, err, "check WhatsApp send: "+tc.err)
                })
        }
 
                })
        }
 
@@ -335,6 +335,7 @@ func TestWhatsAppImageFailureKeepsNoSecretsAndDoesNotRetry(t *testing.T) {
                },
                {name: "send failure stores a safe cause"},
        }
                },
                {name: "send failure stores a safe cause"},
        }
+
        for _, tc := range testCases {
                t.Run(tc.name, func(t *testing.T) {
                        whatsapp, fake := whatsappStartTestLinked(t)
        for _, tc := range testCases {
                t.Run(tc.name, func(t *testing.T) {
                        whatsapp, fake := whatsappStartTestLinked(t)
@@ -432,6 +433,7 @@ func TestTelegramReceivedPhotoCanBeShownAndSentToWhatsApp(t *testing.T) {
                        bot:   bot,
                },
        }
                        bot:   bot,
                },
        }
+
        require.NotContains(t, box.run(t.Context(), "image_show", `{"image":"`+names[0]+`","caption":"The plan."}`), "error:")
        require.Contains(t, box.run(t.Context(), "whatsapp_send", `{"id":"forward","chat":"15550002222@s.whatsapp.net","text":"The plan.","image":"`+names[0]+`"}`), "Sent to")
        require.Equal(t, [][]byte{picture}, fake.Uploads())
        require.NotContains(t, box.run(t.Context(), "image_show", `{"image":"`+names[0]+`","caption":"The plan."}`), "error:")
        require.Contains(t, box.run(t.Context(), "whatsapp_send", `{"id":"forward","chat":"15550002222@s.whatsapp.net","text":"The plan.","image":"`+names[0]+`"}`), "Sent to")
        require.Equal(t, [][]byte{picture}, fake.Uploads())