{
  "info": {
    "name": "W03 房间查询、新增、改名与删除",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "http://127.0.0.1:8080",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "01 查询当前家庭",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/api/rooms",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 200\", () => pm.response.to.have.status(200));",
              "pm.test(\"响应 OK\", () => pm.expect(pm.response.json().code).to.eql(\"OK\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "02 新增餐厅（上周功能）",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/api/rooms",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。",
        "body": {
          "mode": "raw",
          "raw": "{\"name\": \"餐厅\"}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 201\", () => pm.response.to.have.status(201));",
              "pm.test(\"响应 OK\", () => pm.expect(pm.response.json().code).to.eql(\"OK\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "03 书房改为工作室",
      "request": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/api/rooms/room-03",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。",
        "body": {
          "mode": "raw",
          "raw": "{\"name\": \" 工作室 \"}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 200\", () => pm.response.to.have.status(200));",
              "pm.test(\"响应 OK\", () => pm.expect(pm.response.json().code).to.eql(\"OK\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "04 原名不变也允许",
      "request": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/api/rooms/room-03",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。",
        "body": {
          "mode": "raw",
          "raw": "{\"name\": \"工作室\"}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 200\", () => pm.response.to.have.status(200));",
              "pm.test(\"响应 OK\", () => pm.expect(pm.response.json().code).to.eql(\"OK\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "05 重名不能修改",
      "request": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/api/rooms/room-03",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。",
        "body": {
          "mode": "raw",
          "raw": "{\"name\": \"客厅\"}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 409\", () => pm.response.to.have.status(409));",
              "pm.test(\"响应 ROOM_NAME_CONFLICT\", () => pm.expect(pm.response.json().code).to.eql(\"ROOM_NAME_CONFLICT\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "06 空名称不能修改",
      "request": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/api/rooms/room-03",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。",
        "body": {
          "mode": "raw",
          "raw": "{\"name\": \"  \"}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 400\", () => pm.response.to.have.status(400));",
              "pm.test(\"响应 INVALID_ROOM_NAME\", () => pm.expect(pm.response.json().code).to.eql(\"INVALID_ROOM_NAME\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "07 客厅有设备不能删除",
      "request": {
        "method": "DELETE",
        "header": [],
        "url": "{{baseUrl}}/api/rooms/room-01",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 409\", () => pm.response.to.have.status(409));",
              "pm.test(\"响应 ROOM_NOT_EMPTY\", () => pm.expect(pm.response.json().code).to.eql(\"ROOM_NOT_EMPTY\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "08 其他家庭房间不能改名",
      "request": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/api/rooms/room-99",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。",
        "body": {
          "mode": "raw",
          "raw": "{\"name\": \"误改名称\", \"householdId\": \"hh-04\"}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 404\", () => pm.response.to.have.status(404));",
              "pm.test(\"响应 ROOM_NOT_FOUND\", () => pm.expect(pm.response.json().code).to.eql(\"ROOM_NOT_FOUND\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "09 其他家庭房间不能删除",
      "request": {
        "method": "DELETE",
        "header": [],
        "url": "{{baseUrl}}/api/rooms/room-99",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 404\", () => pm.response.to.have.status(404));",
              "pm.test(\"响应 ROOM_NOT_FOUND\", () => pm.expect(pm.response.json().code).to.eql(\"ROOM_NOT_FOUND\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "10 不存在的房间",
      "request": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/api/rooms/missing",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。",
        "body": {
          "mode": "raw",
          "raw": "{\"name\": \"新名\"}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 404\", () => pm.response.to.have.status(404));",
              "pm.test(\"响应 ROOM_NOT_FOUND\", () => pm.expect(pm.response.json().code).to.eql(\"ROOM_NOT_FOUND\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "11 删除空的工作室",
      "request": {
        "method": "DELETE",
        "header": [],
        "url": "{{baseUrl}}/api/rooms/room-03",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 200\", () => pm.response.to.have.status(200));",
              "pm.test(\"响应 OK\", () => pm.expect(pm.response.json().code).to.eql(\"OK\"));"
            ]
          }
        }
      ]
    },
    {
      "name": "12 再次查询确认删除",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/api/rooms",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 200\", () => pm.response.to.have.status(200));",
              "pm.test(\"响应 OK\", () => pm.expect(pm.response.json().code).to.eql(\"OK\"));",
              "pm.test(\"列表不再含 room-03\", () => pm.expect(pm.response.json().data.some(room => room.id === \"room-03\")).to.eql(false));"
            ]
          }
        }
      ]
    },
    {
      "name": "13 重复删除返回404",
      "request": {
        "method": "DELETE",
        "header": [],
        "url": "{{baseUrl}}/api/rooms/room-03",
        "description": "按集合顺序操作。重复运行前重启自己的后端以恢复示例。"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"状态 404\", () => pm.response.to.have.status(404));",
              "pm.test(\"响应 ROOM_NOT_FOUND\", () => pm.expect(pm.response.json().code).to.eql(\"ROOM_NOT_FOUND\"));"
            ]
          }
        }
      ]
    }
  ]
}
