How to unit test a bot in JavaScript that can receive attachments from users?

Zhu, Zihan 41 Reputation points
2021-02-22T11:59:11.57+00:00

Hi,

I am doing unit test for my bot written in node.js based on the Microsoft document https://learn.microsoft.com/en-us/azure/bot-service/unit-test-bots?view=azure-bot-service-4.0&tabs=javascript.

In the test, I can create a client object and make the client send text to the bot like

   const reply = await client.sendActivity('hi!');  
   assert.strictEqual(reply, expected_reply);  

But my bot was designed to also be able to receive attachments from users, how can I make the client send an attachment to the bot so that I can test how the bot would react?

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
749 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 46,986 Reputation points
    2021-02-22T23:15:31.267+00:00

    Hello,

    Thanks for reaching out to us. I think you are looking for the code sample for How to handle attachment in Node.js, please refer to below Repo with the code sample:

    https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/15.handling-attachments

    https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/15.handling-attachments/bots/attachmentsBot.js

    I hope above helps.

    Regards,
    Yutong