From b86114fa3ad4e1876387e784bbda214907306bad Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Sun, 26 Apr 2026 05:25:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Plus=20Checkout=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=90=8E=E7=AD=89=E5=BE=85=2020=20=E7=A7=92?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=9B=B8=E5=BA=94=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background/steps/create-plus-checkout.js | 4 ++ tests/plus-checkout-create-wait.test.js | 55 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/plus-checkout-create-wait.test.js diff --git a/background/steps/create-plus-checkout.js b/background/steps/create-plus-checkout.js index f00bee4..fb995ab 100644 --- a/background/steps/create-plus-checkout.js +++ b/background/steps/create-plus-checkout.js @@ -4,6 +4,7 @@ const PLUS_CHECKOUT_SOURCE = 'plus-checkout'; const PLUS_CHECKOUT_ENTRY_URL = 'https://chatgpt.com/'; const PLUS_CHECKOUT_INJECT_FILES = ['content/utils.js', 'content/plus-checkout.js']; + const PLUS_CHECKOUT_POST_CREATE_WAIT_MS = 20000; function createPlusCheckoutCreateExecutor(deps = {}) { const { @@ -64,6 +65,9 @@ plusCheckoutCurrency: result.currency || 'EUR', }); + await addLog('步骤 6:Plus Checkout 页面已就绪,固定等待 20 秒后继续下一步。', 'info'); + await sleepWithStop(PLUS_CHECKOUT_POST_CREATE_WAIT_MS); + await completeStepFromBackground(6, { plusCheckoutCountry: result.country || 'DE', plusCheckoutCurrency: result.currency || 'EUR', diff --git a/tests/plus-checkout-create-wait.test.js b/tests/plus-checkout-create-wait.test.js new file mode 100644 index 0000000..8253d6c --- /dev/null +++ b/tests/plus-checkout-create-wait.test.js @@ -0,0 +1,55 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); + +const source = fs.readFileSync('background/steps/create-plus-checkout.js', 'utf8'); +const globalScope = {}; +const api = new Function('self', `${source}; return self.MultiPageBackgroundPlusCheckoutCreate;`)(globalScope); + +test('Plus checkout create waits 20 seconds before completing step 6', async () => { + const events = []; + const executor = api.createPlusCheckoutCreateExecutor({ + addLog: async (message, level = 'info') => { + events.push({ type: 'log', message, level }); + }, + chrome: { + tabs: { + update: async (tabId, payload) => { + events.push({ type: 'tab-update', tabId, payload }); + }, + }, + }, + completeStepFromBackground: async (step, payload) => { + events.push({ type: 'complete', step, payload }); + }, + ensureContentScriptReadyOnTabUntilStopped: async () => { + events.push({ type: 'ready' }); + }, + reuseOrCreateTab: async () => 42, + sendTabMessageUntilStopped: async () => ({ + checkoutUrl: 'https://checkout.stripe.com/c/pay/session', + country: 'US', + currency: 'USD', + }), + setState: async (payload) => { + events.push({ type: 'set-state', payload }); + }, + sleepWithStop: async (ms) => { + events.push({ type: 'sleep', ms }); + }, + waitForTabCompleteUntilStopped: async () => { + events.push({ type: 'tab-complete' }); + }, + }); + + await executor.executePlusCheckoutCreate(); + + const sleepEvents = events.filter((event) => event.type === 'sleep'); + assert.deepStrictEqual(sleepEvents.map((event) => event.ms), [1000, 1000, 20000]); + + const fixedWaitIndex = events.findIndex((event) => event.type === 'sleep' && event.ms === 20000); + const completeIndex = events.findIndex((event) => event.type === 'complete'); + assert.ok(fixedWaitIndex > -1); + assert.ok(completeIndex > fixedWaitIndex); + assert.equal(events.some((event) => event.type === 'log' && /固定等待 20 秒/.test(event.message)), true); +});