activation-utils.test.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 uses native click 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: 'click' }
  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 uses native click 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: 'click' }
  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('认证失败: timeout of 30000ms exceeded'),
  67. true
  68. );
  69. assert.equal(
  70. isRecoverableStep9AuthFailure('回调 URL 提交失败: oauth flow is not pending'),
  71. true
  72. );
  73. assert.equal(
  74. isRecoverableStep9AuthFailure('认证成功!'),
  75. false
  76. );
  77. assert.equal(
  78. isRecoverableStep9AuthFailure('等待中'),
  79. false
  80. );
  81. });