Files
crawler-plugin/admin-frontend-vue/tests/jd-product-group.test.ts
T

42 lines
2.2 KiB
TypeScript
Raw 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.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
/** v1.4 AC-8 分组契约(蓝图 docs/ITERATION_PLAN.md §3.4 / §4 Phase 5)。
*
* 京东库专属分组(用户拍板):同公司内重名拒绝、删除分组不删商品(group_id 置 NULL)、
* 按公司隔离读写。Pending 期整组 skip;Phase 5 落地控制器与服务后去掉 skip 跑绿。
* 断言落点为源码绊线(与后端 JdIngestPayloadContractTest 同形):
* SQL 全落 XML(铁律 1)、归属读不出不得回填默认公司(铁律 30)。
*/
const BACKEND_JD = join(process.cwd(), '..', 'backend-java', 'src', 'main', 'java',
'com', 'nanri', 'aiimage', 'modules', 'jd')
const GROUP_SERVICE = join(BACKEND_JD, 'service', 'JdProductGroupService.java')
const GROUP_XML = join(process.cwd(), '..', 'backend-java', 'src', 'main', 'resources',
'mapper', 'jd', 'JdProductGroupMapper.xml')
function readIfExists(path: string, what: string): string {
assert.ok(existsSync(path), `${what} 尚未落地(蓝图 §4 Phase 5):${path}`)
return readFileSync(path, 'utf8')
}
test('分组服务钉住重名拒绝与删除不删商品', { skip: 'Pending Phase 5: 分组服务落地后激活' }, () => {
const service = readIfExists(GROUP_SERVICE, 'JdProductGroupService')
assert.ok(service.includes('DuplicateKeyException') || service.includes('重名'),
'同公司重名必须拒绝且不落库(AC-8)')
assert.ok(service.includes('group_id') && service.includes('null'),
'删除分组必须把商品 group_id 置 NULL 而不是删商品(AC-8)')
assert.ok(service.includes('readCompanyIdOrOwn'),
'分组读写必须走 DataReadScope.readCompanyIdOrOwn 公司隔离(铁律 30 配套)')
})
test('分组 SQL 全落 XML 且不做物理删商品', { skip: 'Pending Phase 5: 分组 Mapper 落地后激活' }, () => {
const xml = readIfExists(GROUP_XML, 'JdProductGroupMapper.xml')
assert.ok(!xml.toUpperCase().includes('DELETE FROM biz_jd_product'),
'分组删除不得物理删商品行')
assert.ok(xml.includes('uk_company_group_name') || xml.includes('company_id'),
'分组 SQL 必须按公司隔离')
})