Skip to main content

Test the bot

This is a part of the tutorial on creating a button-based bot that can order pizza.

  1. Selecting a delivery city
  2. Creating a dictionary
  3. Selecting a pizza
  4. Making an order
  5. Testing the bot script (you are here)

At the previous step we have finished creating the bot. Now, let’s test the bot before deploying it and make sure that we haven’t made any mistakes in the script.

Create a test.xml file in the test folder and paste the following:

<test>

<test-case id="ChooseCity">
<q>/start</q>
<responseData field="replies[1].buttons">[{text:"New York",transition:"/ChooseCity/RememberCity"},{text:"Washington",transition:"/ChooseCity/RememberCity"}]</responseData>
<a state="/ChooseCity"/>
<q>spb</q>
<a state=""/>
<a state="/ChooseCity"/>
</test-case>

<test-case id="CatchAll">
<q>/start</q>
<a state="/ChooseCity"/>
<q>New York</q>
<a state="/ChoosePizza"/>
<q>I want with mushrooms</q>
<a state="/CatchAll"/>
</test-case>

<test-case id="ReturnToMenu">
<q>/start</q>
<a state="/ChooseCity"/>
<q>New York</q>
<a state="/ChoosePizza"/>
<responseData field="replies[1].buttons">[ {text: "Margarita", transition: "/ChoosePizza/GetName"} ] </responseData>
<responseData field="replies[2].buttons">[ {text: "Pepperoni", transition: "/ChoosePizza/GetName"} ] </responseData>
<responseData field="replies[3].buttons">[ {text: "With mushrooms", transition: "/ChoosePizza/GetName"} ] </responseData>
<q>Margarita</q>
<a state="/ChooseVariant"/>
<q>Menu</q>
<a state="/ChoosePizza"/>
</test-case>

<test-case id="WholeScript">
<q>/start</q>
<a state="/ChooseCity"/>
<q>New York</q>
<a state="/ChoosePizza"/>
<responseData field="replies[1].buttons">[ {text: "Margarita", transition: "/ChoosePizza/GetName"} ] </responseData>
<q>Margarita</q>
<a state="/ChooseVariant"/>
<responseData field="replies[1].buttons"> [{ text:"Large thin-crust for 22 $",callback_data:1 }] </responseData>
<responseData field="replies[2].buttons"> [{ text:"Large thik-crust for 29 $. ",callback_data:2 }] </responseData>
<responseData field="replies[3].buttons"> [{ text:"Small thin-crust for 21 $.",callback_data:3 }] </responseData>
<responseData field="replies[4].buttons"> [{ text:"Small thick-crust for 24 $.",callback_data:4 }] </responseData>
<request>{type:"query",query:"1",event:"telegramCallbackQuery"}</request>
<a state="/ChooseQuantity"/>
<responseData field="replies[1].buttons"> [
{text:"1",transition:"/ChooseQuantity/GetQuantity"},
{text:"2",transition:"/ChooseQuantity/GetQuantity"},
{text:"3",transition:"/ChooseQuantity/GetQuantity"}]</responseData>
<q>2</q>
<a state="/ChooseQuantity/GetQuantity"/>
<responseData field="replies[1].buttons"> [{text:"Menu",transition:"/ChoosePizza"}]</responseData>
<responseData field="replies[2].buttons"> [{text:"Proceed to checkout",transition:"/Cart"}]</responseData>
<request>{query:"Proceed to checkout",rawRequest:{message:{message_id:1}}}</request>
<a state="/Cart"/>
<responseData field="replies[2].buttons"> [{ text:"Delete",callback_data:"Margarita" }] </responseData>
<request>{type:"query",event:"telegramSendContact",rawRequest:{message:{message_id:1, contact: {phone_number:"+7123123123"}}}}</request>
<a state="/GetPhoneNumber"/>
</test-case>

<test-case id="ChooseSomePizzas">
<q>/start</q>
<a state="/ChooseCity"/>
<q>New York</q>
<a state="/ChoosePizza"/>
<q>Margarita</q>
<a state="/ChooseVariant"/>
<request>{type:"query", event:"telegramCallbackQuery", query:"1", rawRequest: {callback_query: {data: "1"}}}</request>
<a state="/ChooseQuantity"/>
<q>2</q>
<a state="/ChooseQuantity/GetQuantity"/>
<q>Menu</q>
<a state="/ChoosePizza"/>
<q>Pepperoni</q>
<a state="/ChooseVariant"/>
<request>{type:"query", event:"telegramCallbackQuery", query:"6", rawRequest: {callback_query: {data: "6"}}}</request>
<a state="/ChooseQuantity"/>
<q>1</q>
<a state="/ChooseQuantity/GetQuantity"/>
<request>{query:"Proceed to checkout", rawRequest:{message: {message_id: 1}}}</request>
<responseData field="answer">"Your cart:\n\n1. Margarita, a Large thin-crust\nPrice: 22 $\nNumber: 2\n\n2. Pepperoni, Large thick-crust\nPrice: 35 $\nNumber: 1\n\nTotal amount of the order: 57 $.\n\nIf everything is correct, send your phone number and our Manager will contact you."</responseData> -->
<a state="/Cart"/>
<responseData field="replies[2].buttons"> [{ text:"Remove",callback_data:"Margarita" }] </responseData>
<responseData field="replies[4].buttons"> [{ text:"Remove",callback_data:"Pepperoni" }] </responseData>
</test-case>

<test-case id="EditCart">
<q>/start</q>
<a state="/ChooseCity"/>
<q>Washington</q>
<a state="/ChoosePizza"/>
<q>Margarita</q>
<a state="/ChooseVariant"/>
<request>{type:"query",query:"1",event:"telegramCallbackQuery"}</request>
<a state="/ChooseQuantity"/>
<q>2</q>
<a state="/ChooseQuantity/GetQuantity"/>
<request>{query:"Proceed to checkout", rawRequest:{message: {message_id: 1}}}</request>
<a state="/Cart"/>
<responseData field="replies[2].buttons"> [{ text:"Remove",callback_data:"Margarita" }] </responseData>
<a state="/Cart"/>
<request>{type:"query", event:"telegramCallbackQuery", query:"Margarita", rawRequest:{callback_query: {data:"Margarita", message:{message_id: 1}}}}</request>
<responseData field="replies[0]"> {"type":"raw","body":{"text":"Removed","message_id":1,"reply_markup":{"resize_keyboard":false}},"method":"editMessageText"}</responseData>
<responseData field="replies[1]"> {"type":"raw","body":{"text":"Total order amount: 0 $.","message_id":4,"reply_markup":{"resize_keyboard":false}},"method":"editMessageText"}</responseData>
<a state="/Cart/Edit"/>
<a state="/ChoosePizza"/>
</test-case>

</test>

ChooseCity

Let’s check if we have added the buttons correctly:

<responseData field="replies[1].buttons">[ {text: "Margarita", transition: "/ChoosePizza/GetName"} ] </responseData>

CatchAll

Let’s check if the state CatchAll is triggered when the client enters a message instead of clickng the button:

<test-case id="CatchAll">
<q>/start</q>
<a state="/ChooseCity"/>
<q>New York</q>
<a state="/ChoosePizza"/>
<q>I want with mushrooms</q>
<a state="/CatchAll"/>
</test-case>

ReturnToMenu

Let’s check the presence of buttons in the ChoosePizza state:

<test-case id="ReturnToMenu">
<q>/start</q>
<a state="/ChooseCity"/>
<q>New York</q>
<a state="/ChoosePizza"/>
<responseData field="replies[1].buttons">[ {text: "Margarita", transition: "/ChoosePizza/GetName"} ]</responseData>
<responseData field="replies[2].buttons">[ {text: "Pepperoni", transition: "/ChoosePizza/GetName"} ] </responseData>
<responseData field="replies[3].buttons">[ {text: "With mushrooms", transition: "/ChoosePizza/GetName"} ] </responseData>
<q>Margarita</q>
<a state="/ChooseVariant"/>
<q>Menu</q>
<a state="/ChoosePizza"/>
</test-case>

WholeScript

The WholeScript test-case checks the script from the start to the end. To check the inline buttons, use the following string:

<responseData field="replies[1].buttons"> [{ text:"Large thin-crust for 22 $.",callback_data:1 }] </responseData>

ChooseSomePizzas

Let’s check the click on the inline button:

<request>{type:"query",query:"1",event:"telegramCallbackQuery"}</request>

Here, we send the value of the callback_data field as a query and call the telegramCallbackQuery event.

EditCart

The EditCart test-case checks the edited cart. To make sure that the Remove button is replaced with the text Removed, use the following string:

<responseData field="replies[0]"> {"type":"raw","body":{"text":"Removed","message_id":1,"reply_markup":{"resize_keyboard":false}},"method":"editMessageText"}</responseData>

To check that the total cost of the order is edited, use the following string:

<responseData field="replies[1]"> {"type":"raw","body":{"text":"Total order amount: 0 $.","message_id":4,"reply_markup":{"resize_keyboard":false}},"method":"editMessageText"}</responseData>