device.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Device Mock Handlers
  3. * 设备相关的 mock 处理器
  4. */
  5. /**
  6. * 打开设备 - 成功场景
  7. *
  8. * @description 打开指定设备
  9. * @method POST
  10. * @url /api/v1/auth/device/open
  11. * @access 需要认证
  12. *
  13. * @param {Object} requestBody - 请求体
  14. * @param {string} requestBody.deviceUri - 设备URI
  15. *
  16. * @returns {Object} 成功响应
  17. *
  18. * @example
  19. * mockOpenDeviceSuccess();
  20. * cy.wait('@openDeviceSuccess');
  21. *
  22. * @see docs/DR.md - 章节28
  23. */
  24. export function mockOpenDeviceSuccess() {
  25. cy.intercept('POST', '/api/v1/auth/device/open', {
  26. statusCode: 200,
  27. body: {
  28. code: "0x000000",
  29. description: "Success",
  30. solution: "",
  31. data: {
  32. "@type": "type.googleapis.com/google.protobuf.Empty",
  33. value: {}
  34. }
  35. }
  36. }).as('openDeviceSuccess');
  37. }
  38. /**
  39. * 执行设备Get操作 - 成功场景
  40. *
  41. * @description 执行设备的Get操作,获取设备状态或参数
  42. * @method POST
  43. * @url /api/v1/auth/device/get
  44. * @access 需要认证
  45. *
  46. * @param {Object} requestBody - 请求体
  47. * @param {string} requestBody.deviceUri - 设备URI
  48. * @param {string} requestBody.reqName - 请求名称
  49. *
  50. * @returns {Object} data - 设备状态数据(JSON字符串)
  51. *
  52. * @example
  53. * mockDeviceGetSuccess();
  54. * cy.wait('@deviceGetSuccess');
  55. *
  56. * @see docs/DR.md - 章节29
  57. */
  58. export function mockDeviceGetSuccess() {
  59. cy.intercept('POST', '/api/v1/auth/device/get', {
  60. statusCode: 200,
  61. body: {
  62. code: "0x000000",
  63. description: "Success",
  64. solution: "",
  65. data: JSON.stringify({
  66. IsDemo: { Value: "1" },
  67. GENERATORSTATUS: { Value: "4" },
  68. KV: { Value: "70.0" },
  69. MA: { Value: "125.0" }
  70. })
  71. }
  72. }).as('deviceGetSuccess');
  73. }
  74. /**
  75. * 执行设备Action操作 - 成功场景
  76. *
  77. * @description 执行设备的Action操作,控制设备行为
  78. * @method POST
  79. * @url /api/v1/auth/device/action
  80. * @access 需要认证
  81. *
  82. * @param {Object} requestBody - 请求体
  83. * @param {string} requestBody.deviceUri - 设备URI
  84. * @param {string} requestBody.reqName - 请求名称
  85. * @param {string} requestBody.reqParam - 请求参数
  86. *
  87. * @returns {Object} 成功响应
  88. *
  89. * @example
  90. * mockDeviceActionSuccess();
  91. * cy.wait('@deviceActionSuccess');
  92. *
  93. * @see docs/DR.md - 章节30
  94. */
  95. export function mockDeviceActionSuccess() {
  96. cy.intercept('POST', '/api/v1/auth/device/action', {
  97. statusCode: 200,
  98. body: {
  99. code: "0x000000",
  100. description: "Success",
  101. solution: "",
  102. data: {
  103. "@type": "type.googleapis.com/google.protobuf.Empty",
  104. value: {}
  105. }
  106. }
  107. }).as('deviceActionSuccess');
  108. }