background-step4-a4sky-no-prefetch.test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const test = require('node:test');
  2. const assert = require('node:assert/strict');
  3. const fs = require('node:fs');
  4. const source = fs.readFileSync('background/steps/fetch-signup-code.js', 'utf8');
  5. const globalScope = {};
  6. const api = new Function('self', `${source}; return self.MultiPageBackgroundStep4;`)(globalScope);
  7. test('step 4 does not request a fresh code first for A4Sky mailbox', async () => {
  8. let capturedOptions = null;
  9. const executor = api.createStep4Executor({
  10. A4SKY_PROVIDER: 'a4sky',
  11. addLog: async () => {},
  12. chrome: { tabs: { update: async () => {} } },
  13. completeStepFromBackground: async () => {},
  14. confirmCustomVerificationStepBypass: async () => {},
  15. getMailConfig: () => ({
  16. provider: 'a4sky',
  17. label: 'A4Sky 邮箱(mail.phplife.net)',
  18. source: 'mail-phplife',
  19. url: 'https://mail.phplife.net/?_task=mail&_mbox=INBOX',
  20. navigateOnReuse: false,
  21. }),
  22. getTabId: async (sourceName) => (sourceName === 'signup-page' ? 1 : 2),
  23. HOTMAIL_PROVIDER: 'hotmail-api',
  24. isTabAlive: async () => true,
  25. LUCKMAIL_PROVIDER: 'luckmail-api',
  26. CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
  27. resolveVerificationStep: async (_step, _state, _mail, options) => {
  28. capturedOptions = options;
  29. },
  30. reuseOrCreateTab: async () => {},
  31. sendToContentScriptResilient: async () => ({ ready: true }),
  32. shouldUseCustomRegistrationEmail: () => false,
  33. STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS: 25000,
  34. throwIfStopped: () => {},
  35. });
  36. await executor.executeStep4({
  37. email: 'n20260419100609@edu.a4sky.com',
  38. password: 'Secret123!',
  39. });
  40. assert.equal(capturedOptions.requestFreshCodeFirst, false);
  41. assert.equal(capturedOptions.resendIntervalMs, 25000);
  42. });