Files
wordpress-theme-aksrt/tests/widget-system/referral-policy-contract.test.cjs
T
kate522andClaude Opus 5 35bb96e82f refactor: rename the theme brand and every identifier from AKSRT to Jio
Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.

Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
  cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
  window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)

Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
  so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
  (dropped 3 stale entries, added the 17 missing ones)

Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
  get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
  when it is empty

Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.

Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-01 20:05:04 +08:00

106 lines
5.8 KiB
JavaScript

const test = require('node:test')
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const root = path.resolve(__dirname, '..', '..')
const read = (...segments) => fs.readFileSync(path.join(root, ...segments), 'utf8')
test('referral attribution model is a single runtime source with schema surface', () => {
const runtime = read('src', 'Settings', 'CreditsRuntime.php')
const attribution = read('src', 'Payment', 'ReferralAttribution.php')
const phpSchema = read('src', 'Admin', 'Schema', 'SchemaPayment.php')
const jsSchema = read('assets', 'admin', 'src', 'schema', 'sections', 'payment', 'affiliate.js')
// 运行时:唯一枚举与默认值。
assert.match(runtime, /referral_attribution_model/)
assert.match(runtime, /\['first_touch', 'last_touch'\]/)
assert.match(runtime, /'attribution_model' => \$attribution/)
// 归因行为:capture 末触覆盖、首触保持;注册仲裁按模式取优先方。
assert.match(attribution, /\$this->attribution_model\(\) !== 'last_touch'/)
assert.match(attribution, /!?\(\$last_touch && \$submitted_valid\)/)
assert.match(attribution, /已按最近访问的推广关系绑定/)
assert.match(attribution, /已按首次访问的推广关系绑定/)
// 管理端双 schema 同步暴露该字段。
for (const schema of [phpSchema, jsSchema]) {
assert.match(schema, /referral_attribution_model/)
assert.match(schema, /first_touch/)
assert.match(schema, /last_touch/)
}
})
test('disabled-code stop-commission switch is wired end to end', () => {
const runtime = read('src', 'Settings', 'PaymentRuntime.php')
const ledger = read('src', 'Payment', 'CommissionLedger.php')
const attribution = read('src', 'Payment', 'ReferralAttribution.php')
const phpSchema = read('src', 'Admin', 'Schema', 'SchemaPayment.php')
const jsSchema = read('assets', 'admin', 'src', 'schema', 'sections', 'payment', 'affiliate.js')
assert.match(runtime, /'disabled_code_stops_commission' => !empty\(\$settings\['affiliate_disabled_code_stops_commission'\]\)/)
// 记账入口必须在 resolve 推广人之后、写 ledger 之前校验推广码状态。
assert.match(ledger, /ReferralAttribution::get_instance\(\)->resolve\(\$buyer\)/)
assert.match(ledger, /is_promoter_code_active\(\$promoter\)/)
assert.ok(
ledger.indexOf('is_promoter_code_active($promoter)') < ledger.indexOf('$wpdb->insert($table'),
'disabled-code gate must run before the ledger insert'
)
assert.match(attribution, /public function is_promoter_code_active\(int \$promoter_id\): bool/)
for (const schema of [phpSchema, jsSchema]) {
assert.match(schema, /affiliate_disabled_code_stops_commission/)
}
})
test('commission base is the discounted payable amount, not the list price', () => {
// 下单侧:content 订单金额取优惠链(推广让利 + 优惠券)后的应付净额。
const payOrders = read('src', 'Content', 'PayOrders.php')
assert.match(payOrders, /\$amount_minor = max\(0, \(int\) \(\$discounted\['payable_minor'\] \?\? 0\)\)/)
// 记账侧:佣金基数直接取订单实付金额。
const ledger = read('src', 'Payment', 'CommissionLedger.php')
assert.match(ledger, /AssetAmount::balance\(is_string\(\$order\['amount'\] \?\? null\) \? \$order\['amount'\] : ''\)/)
})
test('commission is credited immediately with no settlement freeze', () => {
const ledger = read('src', 'Payment', 'CommissionLedger.php')
const attribution = read('src', 'Payment', 'ReferralAttribution.php')
// 懒结算兜底已移除:读路径不得顺带写库(收益页打开慢的主因)。
assert.doesNotMatch(ledger, /lazy_settle_due|\$lazy_settled/)
assert.doesNotMatch(ledger, /\$this->lazy_settle_due\(\)/)
assert.doesNotMatch(attribution, /lazy_settle_due/)
assert.doesNotMatch(attribution, /->stats\(/)
// 即时入账模型:不再有结算冻结期 / 结算 cron / settle_due 方法。
assert.doesNotMatch(ledger, /jio_affiliate_settle_due'?, \[\$this, 'settle_due'\]/)
assert.doesNotMatch(ledger, /wp_schedule_event\([^)]*jio_affiliate_settle_due/)
assert.doesNotMatch(ledger, /function settle_due|function settle_one/)
assert.doesNotMatch(ledger, /available_at|settled_at/)
// 遗留结算 cron 需在 init() 主动清理。
assert.match(ledger, /wp_unschedule_event\([^)]*jio_affiliate_settle_due/)
// 下单支付即把佣金 credit 到 COMMISSION 资金池。
assert.match(ledger, /AssetType::COMMISSION/)
assert.match(ledger, /private function credit_commission/)
// 佣金明细行状态为 credited(非 pending 冻结)。
assert.match(ledger, /'status'\s*=>\s*'credited'/)
})
test('referral codes are self-serve: no admin ops page, granted at registration', () => {
const service = read('src', 'Payment', 'ReferralAttribution.php')
// 管理端代码已清理:无 /revenue/codes 路由、无后台增删改接口、无管理列表。
assert.doesNotMatch(service, /revenue\/codes/)
assert.doesNotMatch(service, /rest_mutate_code|rest_codes|can_manage_codes|private function list_codes/)
// 注册即得唯一推广码:bind_registered_user 内调用 generate_code,不依赖归因开关。
assert.match(service, /public function bind_registered_user\(int \$invitee_id\): void \{\s*\n\s*\/\/ 每个新用户注册即拥有唯一推广码[\s\S]*?\$this->generate_code\(\$invitee_id, false\)/)
// 用户菜单不再挂"推广码运营"页,trait 文件已删除。
const menus = read('src', 'Admin', 'Native', 'UsersMenus.php')
assert.doesNotMatch(menus, /UsersMenusReferral|jio_referral_codes|render_referral_codes_page/)
assert.equal(fs.existsSync(path.join(root, 'src', 'Admin', 'Native', 'UsersMenusReferral.php')), false)
// admin SPA 不再保留跳转路由。
const router = read('assets', 'admin', 'src', 'router', 'index.js')
assert.doesNotMatch(router, /referral-codes/)
})