auth.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Auth Mock Handlers
  3. * 认证相关的 mock 处理器
  4. */
  5. /**
  6. * 修改密码 - 成功场景
  7. *
  8. * @description 修改当前用户自己的密码
  9. * @method POST
  10. * @url /api/v1/auth/settings/password
  11. * @access 需要认证
  12. *
  13. * @param {Object} requestBody - 请求体
  14. * @param {string} requestBody.old_password - 旧密码
  15. * @param {string} requestBody.new_password - 新密码
  16. * @param {string} requestBody.confirm_new_password - 确认密码
  17. *
  18. * @returns {Object} 成功响应
  19. *
  20. * @example
  21. * mockChangePasswordSuccess();
  22. * cy.get('[name="old_password"]').type('123456');
  23. * cy.get('[name="new_password"]').type('newPassword123');
  24. * cy.get('[name="confirm_new_password"]').type('newPassword123');
  25. * cy.get('[type="submit"]').click();
  26. * cy.wait('@changePasswordSuccess');
  27. *
  28. * @see docs/DR.md - 章节8
  29. */
  30. export function mockChangePasswordSuccess() {
  31. cy.intercept('POST', '/api/v1/auth/settings/password', {
  32. statusCode: 200,
  33. body: {
  34. code: "0x000000",
  35. description: "Success",
  36. solution: "",
  37. data: {}
  38. }
  39. }).as('changePasswordSuccess');
  40. }
  41. /**
  42. * 修改密码 - 旧密码错误
  43. *
  44. * @description 修改密码失败,旧密码不正确
  45. * @method POST
  46. * @url /api/v1/auth/settings/password
  47. * @access 需要认证
  48. *
  49. * @returns {Object} 错误响应
  50. * @returns {string} code - 错误码
  51. * @returns {string} description - 错误描述
  52. *
  53. * @example
  54. * mockChangePasswordWrongOldPassword();
  55. * cy.wait('@changePasswordWrongOldPassword');
  56. *
  57. * @see docs/DR.md - 章节8
  58. */
  59. export function mockChangePasswordWrongOldPassword() {
  60. cy.intercept('POST', '/api/v1/auth/settings/password', {
  61. statusCode: 200,
  62. body: {
  63. code: "0x000002",
  64. description: "Old password is incorrect",
  65. solution: "Please check your old password",
  66. data: {}
  67. }
  68. }).as('changePasswordWrongOldPassword');
  69. }
  70. /**
  71. * 修改密码 - 新密码不匹配
  72. *
  73. * @description 修改密码失败,新密码和确认密码不匹配
  74. * @method POST
  75. * @url /api/v1/auth/settings/password
  76. * @access 需要认证
  77. *
  78. * @returns {Object} 错误响应
  79. * @returns {string} code - 错误码
  80. * @returns {string} description - 错误描述
  81. *
  82. * @example
  83. * mockChangePasswordNotMatch();
  84. * cy.wait('@changePasswordNotMatch');
  85. *
  86. * @see docs/DR.md - 章节8
  87. */
  88. export function mockChangePasswordNotMatch() {
  89. cy.intercept('POST', '/api/v1/auth/settings/password', {
  90. statusCode: 200,
  91. body: {
  92. code: "0x000003",
  93. description: "New password and confirmation do not match",
  94. solution: "Please ensure both passwords are the same",
  95. data: {}
  96. }
  97. }).as('changePasswordNotMatch');
  98. }