activation-utils.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const test = require('node:test');
  2. const assert = require('node:assert/strict');
  3. const {
  4. getActivationStrategy,
  5. isRecoverableStep9AuthFailure,
  6. } = require('../content/activation-utils.js');
  7. test('getActivationStrategy prefers requestSubmit for submit buttons inside forms', () => {
  8. assert.deepEqual(
  9. getActivationStrategy({
  10. tagName: 'button',
  11. type: 'submit',
  12. hasForm: true,
  13. pathname: '/email-verification',
  14. }),
  15. { method: 'requestSubmit' }
  16. );
  17. });
  18. test('getActivationStrategy uses native click for non-submit actions', () => {
  19. assert.deepEqual(
  20. getActivationStrategy({
  21. tagName: 'button',
  22. type: 'button',
  23. hasForm: true,
  24. }),
  25. { method: 'click' }
  26. );
  27. assert.deepEqual(
  28. getActivationStrategy({
  29. tagName: 'a',
  30. type: '',
  31. hasForm: false,
  32. }),
  33. { method: 'click' }
  34. );
  35. });
  36. test('getActivationStrategy only uses requestSubmit on email verification routes', () => {
  37. assert.deepEqual(
  38. getActivationStrategy({
  39. tagName: 'button',
  40. type: 'submit',
  41. hasForm: true,
  42. pathname: '/u/signup/details',
  43. }),
  44. { method: 'click' }
  45. );
  46. assert.deepEqual(
  47. getActivationStrategy({
  48. tagName: 'button',
  49. type: 'submit',
  50. hasForm: true,
  51. pathname: '/email-verification',
  52. }),
  53. { method: 'requestSubmit' }
  54. );
  55. });
  56. test('isRecoverableStep9AuthFailure matches timeout and CPA auth failure statuses', () => {
  57. assert.equal(
  58. isRecoverableStep9AuthFailure('认证失败: Timeout waiting for OAuth callback'),
  59. true
  60. );
  61. assert.equal(
  62. isRecoverableStep9AuthFailure('认证失败: Request failed with status code 502'),
  63. true
  64. );
  65. assert.equal(
  66. isRecoverableStep9AuthFailure('认证成功!'),
  67. false
  68. );
  69. assert.equal(
  70. isRecoverableStep9AuthFailure('等待中'),
  71. false
  72. );
  73. });