# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
  id: email-confirmation
  name: 'Email: Confirmation'
  description: Send an order confirmation email
  trigger:
    type: http
    httpRequest:
      url: ${env:EMAIL_SERVICE_ADDR}/send_order_confirmation
      method: POST
      headers:
      - key: Content-Type
        value: application/json
      body: |
        {
          "email": "google@example.com",
          "order": {
            "order_id": "505",
            "shipping_tracking_id": "dead-beef",
            "shipping_cost": {
              "currency_code": "USD",
              "units": 17,
              "nanos": 980000000
            },
            "shipping_address": {
              "street_address_1": "1600 Amphitheatre Parkway",
              "city": "Mountain View",
              "state": "California",
              "country": "United States",
              "zip_code": "94043"
            },
            "items": [
              {
                "item": {
                  "product_id": "1YMWWN1N4O",
                  "quantity": 5
                },
                "cost": {
                  "currency_code": "USD",
                  "units": 100,
                  "nanos": 0
                }
              }
            ]
          }
        }
  specs:
  - name: It should be called successfully
    selector: span[tracetest.span.type="http" name="POST /send_order_confirmation" http.method="POST"]
    assertions:
    - attr:http.status_code = 200
  - name: It should render a email to send
    selector: span[tracetest.span.type="general" name="sinatra.render_template"]
    assertions:
    - attr:name = "sinatra.render_template"
  - name: It should send an email
    selector: span[tracetest.span.type="general" name="send_email"]
    assertions:
    - attr:name = "send_email"