123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- /**
- * Device Mock Handlers
- * 设备相关的 mock 处理器
- */
- /**
- * 打开设备 - 成功场景
- *
- * @description 打开指定设备
- * @method POST
- * @url /api/v1/auth/device/open
- * @access 需要认证
- *
- * @param {Object} requestBody - 请求体
- * @param {string} requestBody.deviceUri - 设备URI
- *
- * @returns {Object} 成功响应
- *
- * @example
- * mockOpenDeviceSuccess();
- * cy.wait('@openDeviceSuccess');
- *
- * @see docs/DR.md - 章节28
- */
- export function mockOpenDeviceSuccess() {
- cy.intercept('POST', '/api/v1/auth/device/open', {
- statusCode: 200,
- body: {
- code: "0x000000",
- description: "Success",
- solution: "",
- data: {
- "@type": "type.googleapis.com/google.protobuf.Empty",
- value: {}
- }
- }
- }).as('openDeviceSuccess');
- }
- /**
- * 执行设备Get操作 - 成功场景
- *
- * @description 执行设备的Get操作,获取设备状态或参数
- * @method POST
- * @url /api/v1/auth/device/get
- * @access 需要认证
- *
- * @param {Object} requestBody - 请求体
- * @param {string} requestBody.deviceUri - 设备URI
- * @param {string} requestBody.reqName - 请求名称
- *
- * @returns {Object} data - 设备状态数据(JSON字符串)
- *
- * @example
- * mockDeviceGetSuccess();
- * cy.wait('@deviceGetSuccess');
- *
- * @see docs/DR.md - 章节29
- */
- export function mockDeviceGetSuccess() {
- cy.intercept('POST', '/api/v1/auth/device/get', {
- statusCode: 200,
- body: {
- code: "0x000000",
- description: "Success",
- solution: "",
- data: JSON.stringify({
- IsDemo: { Value: "1" },
- GENERATORSTATUS: { Value: "4" },
- KV: { Value: "70.0" },
- MA: { Value: "125.0" }
- })
- }
- }).as('deviceGetSuccess');
- }
- /**
- * 执行设备Action操作 - 成功场景
- *
- * @description 执行设备的Action操作,控制设备行为
- * @method POST
- * @url /api/v1/auth/device/action
- * @access 需要认证
- *
- * @param {Object} requestBody - 请求体
- * @param {string} requestBody.deviceUri - 设备URI
- * @param {string} requestBody.reqName - 请求名称
- * @param {string} requestBody.reqParam - 请求参数
- *
- * @returns {Object} 成功响应
- *
- * @example
- * mockDeviceActionSuccess();
- * cy.wait('@deviceActionSuccess');
- *
- * @see docs/DR.md - 章节30
- */
- export function mockDeviceActionSuccess() {
- cy.intercept('POST', '/api/v1/auth/device/action', {
- statusCode: 200,
- body: {
- code: "0x000000",
- description: "Success",
- solution: "",
- data: {
- "@type": "type.googleapis.com/google.protobuf.Empty",
- value: {}
- }
- }
- }).as('deviceActionSuccess');
- }
- /**
- * 重置高压发生器 - 成功场景
- *
- * @description 重置高压发生器参数到初始状态
- * @method POST
- * @url /auth/device/action
- * @access 需要认证
- *
- * @param {Object} requestBody - 请求体
- * @param {string} requestBody.deviceUri - 设备URI (DIOS/DEVICE/Generator)
- * @param {string} requestBody.reqName - 请求名称 (RESET)
- *
- * @returns {Object} 成功响应
- *
- * @example
- * mockResetDeviceSuccess();
- * cy.wait('@resetDevice');
- */
- export function mockResetDeviceSuccess() {
- cy.intercept('POST', '*/auth/device/action', (req) => {
- if (req.body.reqName === 'RESET') {
- req.reply({
- statusCode: 200,
- body: {
- code: '0x000000',
- description: 'Success',
- data: {}
- }
- });
- }
- }).as('resetDevice');
- }
- /**
- * 重置高压发生器 - 失败场景
- *
- * @description 模拟设备重置失败
- * @method POST
- * @url /auth/device/action
- * @access 需要认证
- *
- * @param {string} errorCode - 错误码,默认为'0x010001'
- * @param {string} description - 错误描述,默认为'设备通信失败'
- *
- * @returns {Object} 失败响应
- *
- * @example
- * mockResetDeviceFail();
- * cy.wait('@resetDeviceFail');
- */
- export function mockResetDeviceFail(
- errorCode: string = '0x010001',
- description: string = '设备通信失败'
- ) {
- cy.intercept('POST', '/auth/device/action', {
- statusCode: 200,
- body: {
- code: errorCode,
- description: description,
- solution: '检查设备连接'
- }
- }).as('resetDeviceFail');
- }
- /**
- * 重置高压发生器 - 网络错误
- *
- * @description 模拟网络通信错误
- * @method POST
- * @url /auth/device/action
- * @access 需要认证
- *
- * @returns {Object} 网络错误
- *
- * @example
- * mockResetDeviceNetworkError();
- * cy.wait('@resetDeviceNetworkError');
- */
- export function mockResetDeviceNetworkError() {
- cy.intercept('POST', '/auth/device/action', (req) => {
- if (req.body.reqName === 'RESET') {
- req.reply({ forceNetworkError: true });
- }
- }).as('resetDeviceNetworkError');
- }
- /**
- * 重置高压发生器 - 延迟响应
- *
- * @description 模拟设备重置延迟响应(用于测试loading状态)
- * @method POST
- * @url /auth/device/action
- * @access 需要认证
- *
- * @param {number} delayMs - 延迟毫秒数
- *
- * @returns {Object} 延迟后的成功响应
- *
- * @example
- * mockResetDeviceDelay(2000); // 延迟2秒
- * cy.wait('@resetDeviceDelay');
- */
- export function mockResetDeviceDelay(delayMs: number) {
- cy.intercept('POST', '/auth/device/action', (req) => {
- if (req.body.reqName === 'RESET') {
- req.reply({
- statusCode: 200,
- body: {
- code: '0x000000',
- description: 'Success',
- data: {}
- },
- delay: delayMs
- });
- }
- }).as('resetDeviceDelay');
- }
|