suite: test telegram envs for deployments
templates:
  - engine/deployment.yaml
  - celery/deployment.yaml
  - telegram-polling/deployment.yaml
release:
  name: oncall
tests:
  - it: oncall.telegram.enabled=false -> Telegram integration disabled (default)
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: FEATURE_TELEGRAM_INTEGRATION_ENABLED
            value: "False"

  - it: oncall.telegram.enabled=true -> should enable Telegram integration
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
    set:
      oncall.telegram:
        enabled: true
        webhookUrl: http://example.com
        token: "abcd:123"
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: FEATURE_TELEGRAM_INTEGRATION_ENABLED
            value: "True"
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: TELEGRAM_WEBHOOK_HOST
            value: "http://example.com"
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: TELEGRAM_TOKEN
            value: "abcd:123"

  - it: oncall.telegram.existingSecret=some-secret -> should prefer existing secret over oncall.telegram.token
    templates:
      - engine/deployment.yaml
      - celery/deployment.yaml
    set:
      oncall.telegram:
        enabled: true
        token: "abcd:123"
        existingSecret: some-secret
        tokenKey: token
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: TELEGRAM_TOKEN
            valueFrom:
              secretKeyRef:
                name: some-secret
                key: token

  - it: telegramPolling.enabled=true -> should enable oncall.telegram.enabled too
    set:
      telegramPolling.enabled: true
    asserts:
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: FEATURE_TELEGRAM_INTEGRATION_ENABLED
            value: "True"
      - contains:
          path: spec.template.spec.containers[0].env
          content:
            name: FEATURE_TELEGRAM_LONG_POLLING_ENABLED
            value: "True"
