Files
wordpress-theme-aksrt/tests/widget-system/sales-volume-float-contract.test.cjs
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

57 lines
3.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 = file => fs.readFileSync(path.join(root, file), 'utf8')
const pay = read('inc/helpers/jio-pay.php')
const resource = read('inc/helpers/jio-resource.php')
const list = read('src/Admin/Native/PostListEnhance.php')
const domain = read('src/Core/DomainModel.php')
test('sales count has a single read path that adds the 销量浮动', () => {
// 展示销量只有一个口径:真实订单 + 后台「销量浮动」(pay_count)。
// 此前各调用点各自拼 virtual_sales / sales_volume,pay_count 写进去却没人读。
assert.match(pay, /function jio_get_content_sales_count\(/)
assert.match(pay, /RESOURCE_SALES_VOLUME_KEY/)
assert.match(pay, /\$pay_meta\['pay_count'\]/)
// 两部分都必须下限为 0,避免负的浮动把销量拉成负数。
assert.match(pay, /max\(0, \$real \+ \$float\)/)
})
test('every sales_count producer goes through that read path', () => {
// 内容帖、资源帖、付费墙、付费盒四处不得再各自拼装销量。
assert.match(pay, /'sales_count'\s*=>\s*\$show_sales \? jio_get_content_sales_count\(\$p, \$pay_meta\) : 0/)
assert.match(resource, /'sales_count'\s*=>\s*\$show_sales \? jio_get_content_sales_count\(\$p, \$pay_meta\) : 0/)
assert.match(pay, /\$sales = jio_get_content_sales_count\(\$post, \$meta\)/)
// 不得再出现按 virtual_sales 现拼销量的旧写法。
assert.doesNotMatch(pay, /\$sales\s*=\s*max\(0, \(int\) \(\$meta\['virtual_sales'\] \?\? 0\)\);/)
assert.doesNotMatch(pay, /\$virtual_sales \+ max\(0, \$sales_volume, \$download_count\)/)
assert.doesNotMatch(resource, /\$virtual_sales \+ max\(0, max\(\$download_count, \$legacy_download_count\)\)/)
})
test('pay_count is declared, sanitized and consumed end to end', () => {
// 删掉任何一段,这个字段就又变成「设了不生效」的摆设。
assert.match(domain, /'pay_count'\s*=>\s*0/, 'default value exists')
assert.match(domain, /\$meta\['pay_count'\]\s*=\s*\(int\)/, 'sanitize exists')
// 后台两个入口都写这个键:资源 metabox 与文章列表快捷/批量编辑。
assert.match(read('src/Core/ResourceMetaBox.php'), /'pay_count'/)
assert.match(list, /case 'pay_count':/)
// 快捷编辑按整数运算,与读取口径的 max(0,(int)) 一致。
const branch = list.slice(list.indexOf("case 'pay_count':"), list.indexOf('case \'price\':'))
assert.match(branch, /apply_operation/)
assert.match(branch, /max\(0, \(int\) \$new\)/)
})
test('the admin sales column shows 真实 + 浮动, not the raw meta', () => {
// 列表列与前台同一口径:真实订单 + pay_count,否则后台与前台数字不一致。
assert.match(list, /\$sales_volume = max\(\$real_sales, \$meta_sales\) \+ max\(0, \(int\) \(\$pay_meta\['pay_count'\] \?\? 0\)\)/)
// 真实销量取订单表统计,不能只有 meta 副本。
assert.match(list, /\$real_sales = \$this->real_sales_count\(\$post_id\)/)
})