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

type: Test
spec:
  id: cart-add-item-to-cart
  name: 'Cart: add item to cart'
  description: Add one item to the shopping cart
  trigger:
    type: grpc
    grpc:
      protobufFile: ../../../pb/demo.proto
      address: ${env:CART_SERVICE_ADDR}
      method: oteldemo.CartService.AddItem
      request: |-
        {
            "userId": "1234",
            "item": {
              "productId": "OLJCESPC7Z",
              "quantity": 1
            }
          }
  specs:
  - name: It added an item correctly into the shopping cart
    selector: span[name="oteldemo.CartService/AddItem"]
    assertions:
    - attr:rpc.grpc.status_code = 0
  - name: It set the cart item correctly on the database
    selector: span[tracetest.span.type="database" name="HMSET" db.system="redis" db.redis.database_index="0"]
    assertions:
    - attr:db.statement = "HMSET 1234"
  - name: It returned an empty cart
    selector: span[tracetest.span.type="general" name="Tracetest trigger"]
    assertions:
    - "attr:tracetest.response.body = '{\n  \n}'"