{
  "name": "매출 명세서 플로우",
  "description": "매출 목록 조회 → 매출 상세 → 명세서 생성 → 확정 → 발송 플로우 테스트",
  "version": "1.0",
  "config": {
    "baseUrl": "",
    "timeout": 30000,
    "stopOnFailure": true
  },
  "variables": {
    "user_id": "{{$env.FLOW_TESTER_USER_ID}}",
    "user_pwd": "{{$env.FLOW_TESTER_USER_PWD}}"
  },
  "steps": [
    {
      "id": "login",
      "name": "로그인",
      "method": "POST",
      "endpoint": "/api/v1/login",
      "body": {
        "user_id": "{{user_id}}",
        "user_pwd": "{{user_pwd}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.access_token": "@isString"
        }
      },
      "extract": {
        "token": "$.access_token"
      }
    },
    {
      "id": "list_sales",
      "name": "매출 목록 조회",
      "method": "GET",
      "endpoint": "/api/v1/sales",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "queryParams": {
        "page": 1,
        "per_page": 10
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "extract": {
        "first_sale_id": "$.data.data[0].id"
      }
    },
    {
      "id": "get_sale_detail",
      "name": "매출 상세 조회",
      "method": "GET",
      "endpoint": "/api/v1/sales/{{list_sales.first_sale_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true,
          "$.data.id": "@isNumber"
        }
      },
      "extract": {
        "sale_data": "$.data"
      },
      "continueOnFailure": true
    },
    {
      "id": "create_sale",
      "name": "매출 등록",
      "method": "POST",
      "endpoint": "/api/v1/sales",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "client_id": 1,
        "sale_date": "2025-01-15",
        "due_date": "2025-02-15",
        "items": [
          {
            "product_id": 1,
            "quantity": 10,
            "unit_price": 50000,
            "description": "테스트 상품"
          }
        ],
        "memo": "Flow 테스트용 매출"
      },
      "expect": {
        "status": [200, 201],
        "jsonPath": {
          "$.success": true
        }
      },
      "extract": {
        "new_sale_id": "$.data.id"
      },
      "continueOnFailure": true
    },
    {
      "id": "get_statement",
      "name": "매출 명세서 조회",
      "method": "GET",
      "endpoint": "/api/v1/sales/{{create_sale.new_sale_id}}/statement",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "confirm_sale",
      "name": "매출 확정",
      "method": "POST",
      "endpoint": "/api/v1/sales/{{create_sale.new_sale_id}}/confirm",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "confirmed_at": "2025-01-15T10:00:00Z"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "send_statement",
      "name": "명세서 발송",
      "method": "POST",
      "endpoint": "/api/v1/sales/{{create_sale.new_sale_id}}/send",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "send_type": "email",
        "recipient_email": "test@example.com",
        "message": "매출 명세서를 발송합니다."
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "update_sale",
      "name": "매출 수정",
      "method": "PUT",
      "endpoint": "/api/v1/sales/{{create_sale.new_sale_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "memo": "Flow 테스트 - 수정됨"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "delete_sale",
      "name": "매출 삭제",
      "method": "DELETE",
      "endpoint": "/api/v1/sales/{{create_sale.new_sale_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    }
  ]
}
