additional_paths: []
category: tutorial-internal
commands:
- command: script
  id: ff7d8bac166c11eeb43b9606c285d82a
  kwargs:
    code: |
      # 事前確認など
      preperation_completed = True

      response = {
          "code": 202 if preperation_completed else 500,
          "body": {
              "xid": xid,
              "xname": xname,
          }
      }

      context.session.set_status(response["code"])
      context.session.finish(response["body"])
  label: Response
- command: script
  id: c55394c4165f11eeac26ce9e3c5e954e
  kwargs:
    code: |
      # Test LocalCreateEmployee
      r = await callout(
          url="http://scenario:9000/local/employees",
          method="POST",
          body={
              "employee": {
                  "name": "Employee-01",
                  "position": "manager",
              }
          })

      assert r.code == 202, "[LocalCreateEmployee] Invalid response code %r" % r.code
      local_employee_id = json.loads(r.body)["employee"]["id"]

      # LocalCreateEmployeeのSleep完了を待機
      await asyncio.sleep(10)

      # Test LocalGetEmployee
      r = await callout(
          url=f"http://scenario:9000/local/employees/{local_employee_id}",
          method="GET")

      assert r.code == 200, "[LocalGetEmployee] Invalid response code %r" % r.code

      # Test LocalUpdateEmployee
      r = await callout(
          url=f"http://scenario:9000/local/employees/{local_employee_id}",
          method="PATCH",
          body={
              "employee": {
                  "name": "Employee-Updated-01",
              }
          })

      assert r.code == 202, "[LocalUpdateEmployee] Invalid response code %r" % r.code

      # LocalUpdateEmployeeのSleep完了を待機
      await asyncio.sleep(10)

      # Test LocalDeleteEmployee
      r = await callout(
          url=f"http://scenario:9000/local/employees/{local_employee_id}",
          method="DELETE")

      assert r.code == 202, "[LocalDeleteEmployee] Invalid response code %r" % r.code

      # LocalDeleteEmployeeのSleep完了を待機
      await asyncio.sleep(10)
  label: ExecuteTest
connect_timeout: 60
global_variables: {}
method: POST
name: ScenarioTestInternal
request_timeout: 60
routing_auto_generation_mode: true
routing_options:
  scope: local
spec:
  response:
    normal:
      codes:
      - 200
transaction:
  async: true
  auto_response: false
  enable: true
  xname: ''
update: '2023-07-11T23:35:30.186386+09:00'
uri: /test/internal/scenario/local/employees
variable_groups: []
version: 3
