README.md

# CarlaTestHelper

## Description
This repo contains a testing library used in Carla end-to-end tests. It provides a library to describe and test conversations.

## Requirements
* Elixir - The language
* Mix - Elixir run tool (included with Elixir)
* Hex - Elixir package manage (included with Elixir)

## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `carla_test_helper` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:carla_test_helper, "~> 0.1.0"}
  ]
end
```

You'll then need to update your config.exs so it contains the following configs

### V2
```elixir
config :carla_test_helper,
  bot_version: "v2",
  directline_token: "my_token"
```

### V1
```elixir
config :carla_test_helper,
  bot_version: "v1",
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/carla_test_helper](https://hexdocs.pm/carla_test_helper).

## Example Test Case
If we want to write a test case for the "Request Detail - request details for optima" scenario, our file would look like this:
```elixir
defmodule BotTestsTest do
  use CarlaTestHelper.Case, async: true
  import CarlaTestHelper

  describe "request.detail" do

    carlatest "should provide details on optima", do: [
      # write conversation tests here 
      # message("optima", "request.details.optima")
    ]
    
  end

end
```

## Helper Functions 

### message

Parameters:
* message - Message to send.
* expected_action - Resulting response's action. 

Sends `message` for the asserts the response is the `expected_action`.

```elixir
message("optima", "request.details.optima")
```

### quick_reply

Parameters:
* label - Label of the button you want to *click*. 
* expected_action - Resulting response's action. 

Uses quick reply button using `label` and asserts the response is the `expected_action`.

```elixir
quick_reply("Build & Price", "build:_optima")
```

### button_action

Parameters:
* label - Label of the button you want to *click*. 
* expected_action - Resulting response's action. 

Similar to quick reply, finds button using `label` and asserts the response is `expected_action`. 

```elixir
button_action("Ok", "hello_2")
```

### button_linkout

Parameters:
* label - Label of the button you want to *click*. 
* uri - Linkout button payload value 

Similar to quick reply, finds button using `label` and asserts the button payload is `value`. 

```elixir
button_linkout("Features & Specs", "https://kia.com/us/en/vehicle/optima/2018/features")
```

### button_linkout

Parameters:
* label - Label of the button you want to *click*. 
* uri - Linkout button payload value 
* params - Params of the uri 

Similar to quick reply, finds button using `label`, asserts the button payload is `value` and contains the list of `params`.

```elixir
button_linkout("See Offers", "https://kia.com/us/en/offers/2018/10036", ["series=optima", "offers=3,2,1"])
```

### gallery_card_button_action

Parameters:
* index - Index of the gallery card to test
* label - Label of the button you want to *click*
* expected_action - Resulting response's action

Uses gallery card item at `index`, finds a button using `label` and then asserts the button payload is `value` and asserts the response is `expected_action`.

Note: Indexing starts at 0

```elixir
gallery_card_button_action(2, "See Offers", "request.offers") # Targets the 3rd gallery card
```

### gallery_card_button_linkout

Parameters:
* index - Index of the gallery card to test
* label - Label of the button you want to *click*
* uri - Linkout button payload value

Uses gallery card item at `index`, finds a button using `label`, asserts the button payload is `uri`.

Note: Indexing starts at 0

```elixir
gallery_card_button_linkout(0, "See Offers", "http://example.com") # Targets the 1st gallery card
```

### gallery_card_button_linkout

Parameters:
* index - Index of the gallery card to test
* label - Label of the button you want to *click*
* uri - Linkout button payload value 
* params - Params of the uri 

Uses gallery card item at `index`, finds a button using `label`, asserts the button payload is `uri` and contains the list of `params`.

Note: Indexing starts at 0

```elixir
gallery_card_button_linkout(0, "See Offers", "http://example.com") # Targets the 1st gallery card
```

### debug_last_response

Prints out JSON of last response in the console

```elixir
debug_last_response()
```