Files
go_bt/tests/gcp_restriction_combination.test.js
T

49 lines
1.8 KiB
JavaScript

const assert = require('assert');
const checkRestrictionsStep = require('../src/pipeline/steps/check_restrictions');
const { buildCustomPipelineDoneMessage } = require('../src/pipeline/custom_result');
(async () => {
const writes = [];
const messages = [];
const restrictedText = 'Access to a service or feature has been restricted';
const page = {
goto: async () => {},
waitForLoadState: async () => {},
waitForTimeout: async () => {},
screenshot: async () => {},
locator: () => ({ count: async () => 0 }),
evaluate: async () => restrictedText,
};
const ctx = {
page,
account: { email: 'restricted@example.com' },
log: () => {},
dbWrite: async (fn, args) => { writes.push({ fn, args }); },
updateMessage: async (email, message) => { messages.push({ email, message }); },
updateStatus: async () => {},
results: {},
};
await checkRestrictionsStep(ctx);
assert.strictEqual(ctx.results.checkRestrictions.restricted, true);
assert(writes.some(item => item.fn === 'updateAccountRestrictionStatus' && item.args[1] === 'restricted'));
assert(writes.some(item => item.fn === 'updateAccountAgStatus' && item.args[1] === 'GCP被限制'));
assert(writes.some(item => item.fn === 'updateAccountStatusReason' && item.args[1] === 'GCP_RESTRICTED'));
assert(messages.some(item => item.message === '🚫 GCP被限制'));
assert.strictEqual(
buildCustomPipelineDoneMessage('改2fa+查看gcp', ctx.results.checkRestrictions),
'🚫 GCP被限制;组合任务「改2fa+查看gcp」全部完成',
);
assert.strictEqual(
buildCustomPipelineDoneMessage('改2fa+查看gcp', { restricted: false }),
'✅ GCP未限制;组合任务「改2fa+查看gcp」全部完成',
);
console.log('gcp_restriction_combination.test.js: PASS');
})().catch(error => {
console.error(error);
process.exitCode = 1;
});