feat(brandgating): 品牌Gating库并入店铺数据重复检查页
- 「店铺数据重复检查」新增「品牌Gating库」页签,承接原独立 Gating 网页后台的列表/筛选/统计、单条新增、批量导入、启停与删除。 - 复用既有 /api/admin/brand-gating 模块;接口权限键跟随宿主页 admin_shop_data_duplicate_check(V164 菜单已由 V166 删除)。 - 前端新增 brand-gating 模型/API 适配、BrandGatingPanel 与纯逻辑单测。
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
createBrandGatingFilter,
|
||||
createBrandGatingForm,
|
||||
parseBrandGatingAddResult,
|
||||
parseBrandGatingImportResult,
|
||||
parseBrandGatingPage,
|
||||
parseBrandGatingStats,
|
||||
toBrandGatingQuery,
|
||||
validateBrandGatingForm,
|
||||
} from '../src/pages/tasks/brand-gating-model.ts'
|
||||
|
||||
test('brand_gating_form_defaults_match_desktop', () => {
|
||||
const form = createBrandGatingForm()
|
||||
assert.equal(form.country, '全部')
|
||||
assert.equal(form.gatingType, '品牌gating')
|
||||
assert.equal(form.brand, '')
|
||||
assert.equal(validateBrandGatingForm(form), '请填写品牌')
|
||||
assert.equal(validateBrandGatingForm({ ...form, brand: ' tory burch ' }), '')
|
||||
})
|
||||
|
||||
test('brand_gating_query_omits_empty_and_all_sentinel', () => {
|
||||
const filter = createBrandGatingFilter()
|
||||
assert.deepEqual(toBrandGatingQuery(filter, 1, 10), { page: 1, size: 10 })
|
||||
|
||||
filter.country = '全部'
|
||||
filter.gatingType = '全部'
|
||||
filter.source = '全部'
|
||||
assert.deepEqual(toBrandGatingQuery(filter, 2, 20), { page: 2, size: 20 })
|
||||
|
||||
filter.keyword = ' tory '
|
||||
filter.country = '英国'
|
||||
filter.gatingType = '类目gating'
|
||||
filter.status = '1'
|
||||
filter.source = 'AUTO'
|
||||
assert.deepEqual(toBrandGatingQuery(filter, 3, 50), {
|
||||
page: 3,
|
||||
size: 50,
|
||||
keyword: 'tory',
|
||||
country: '英国',
|
||||
gatingType: '类目gating',
|
||||
status: '1',
|
||||
source: 'AUTO',
|
||||
})
|
||||
})
|
||||
|
||||
test('brand_gating_page_parses_camel_rows_and_skips_invalid', () => {
|
||||
const page = parseBrandGatingPage({
|
||||
total: 2,
|
||||
rows: [
|
||||
{
|
||||
id: 7,
|
||||
brand: 'tory burch',
|
||||
asin: 'B000000001',
|
||||
country: '英国',
|
||||
gatingType: '品牌gating',
|
||||
status: 1,
|
||||
source: 'MANUAL',
|
||||
shopName: 'ShopA',
|
||||
remark: '排查同步',
|
||||
createdAt: '2026-10-24 10:00:00',
|
||||
updatedAt: '2026-10-24 10:00:00',
|
||||
disabledAt: null,
|
||||
},
|
||||
{ brand: '缺 id' },
|
||||
],
|
||||
})
|
||||
assert.equal(page.total, 2)
|
||||
assert.equal(page.rows.length, 1)
|
||||
const row = page.rows[0]
|
||||
assert.equal(row.id, 7)
|
||||
assert.equal(row.gatingType, '品牌gating')
|
||||
assert.equal(row.status, 1)
|
||||
assert.equal(row.disabledAt, '')
|
||||
assert.equal(row.createdAt, '2026-10-24 10:00:00')
|
||||
})
|
||||
|
||||
test('brand_gating_stats_parses_groups_and_missing_fields', () => {
|
||||
const stats = parseBrandGatingStats({
|
||||
total: 9,
|
||||
active: 6,
|
||||
disabled: 3,
|
||||
brands: 5,
|
||||
byType: [
|
||||
{ name: '品牌gating', count: 4 },
|
||||
{ name: '', count: 99 },
|
||||
{ count: 1 },
|
||||
],
|
||||
byCountry: [{ name: '英国', count: 3 }],
|
||||
})
|
||||
assert.equal(stats.total, 9)
|
||||
assert.equal(stats.active, 6)
|
||||
assert.equal(stats.brands, 5)
|
||||
assert.deepEqual(stats.byType, [{ name: '品牌gating', count: 4 }])
|
||||
assert.deepEqual(stats.byCountry, [{ name: '英国', count: 3 }])
|
||||
assert.deepEqual(stats.bySource, [])
|
||||
|
||||
const empty = parseBrandGatingStats(null)
|
||||
assert.deepEqual(empty, {
|
||||
total: 0,
|
||||
active: 0,
|
||||
disabled: 0,
|
||||
brands: 0,
|
||||
byType: [],
|
||||
byCountry: [],
|
||||
bySource: [],
|
||||
})
|
||||
})
|
||||
|
||||
test('brand_gating_add_and_import_results', () => {
|
||||
assert.equal(parseBrandGatingAddResult({ added: 1 }), true)
|
||||
assert.equal(parseBrandGatingAddResult({ added: 0 }), false)
|
||||
assert.equal(parseBrandGatingAddResult(null), false)
|
||||
assert.deepEqual(parseBrandGatingImportResult({ added: 3, skipped: 2 }), { added: 3, skipped: 2 })
|
||||
assert.deepEqual(parseBrandGatingImportResult(null), { added: 0, skipped: 0 })
|
||||
})
|
||||
Reference in New Issue
Block a user