934091b3d5
客户口径(2026-11-25):「上限=同时在架商品数,下架 10 个就能再上架 10 个换着卖」+
「管理员下的普通员工总和也不能超过这个上限」。
后端
- 计数正本从 biz_jd_product 占有行数迁到 biz_jd_publish_item:发布成功(SUCCESS)
且未标记下架(delisted_at IS NULL)的去重商品数(DISTINCT product_id,同商品跨任务
重复发布只占一位)。旧 JdProductMapper#countByUserIds 整条删除——口径源只能一份。
- V216 给发布明细加 delisted_at(NULL=在架);V217 把普通账号存量默认 5000 清 0
(0=未分配,分配闸上线的前置清账)。
- JdPublishQuotaService:quotaOf 读数换正本;assertWithinQuota 改收勾选商品集,
批内已在架的不双计(重复上架不重复占位)。
- 新增 JdPublishOnShelfService+/api/jd-publish/on-shelf(团队在架分页+余量,读数与
建单闸同一正本)与 /api/jd-publish/items/{itemId}/delisted(标记/撤销按商品整组回写,
跨团队 403;京麦下架执行链自动回流记欠账)。
- AdminUserService 新增分配闸:Σ(直接下属非零额度,被编辑账号取新值) ≤ 锚点额度;
站超管/锚点 0=不限放行;旧 400「只能为管理员设置额度」废止。新增
/api/admin/user/{uid}/jd-quota 只读快照(编辑弹窗展示「当前在架 X/上限 Y」)。
后管
- 编辑弹窗额度项改为「京东侧+操作者写权」即出(普通账号也可分配),带当前在架读数
(读不到只显一句失败话,不挡保存);列表「上架上限」列 0 按档显「不限」/「未分配」;
普通账号回填缺省 0(避免「打开就保存」凭空分配额度)。展示规则单出口 user-edit-model。
用户端
- 新增在架商品面板(JdOnShelfPanel):余量读数、空态、满额提醒、标记已下架确认与回执
文案单出口 jd-on-shelf.ts;endpoints 快照同步 onShelf/markDelisted。
判据
- 后端:JdPublishQuotaServiceTest 11、JdPublishOnShelfServiceTest 8、
JdPublishOnShelfSqlTest 3(三条 SQL 谓词逐字钉:SUCCESS+delisted_at IS NULL+DISTINCT)、
AdminUserServiceCompanySuperAdminTest +5(Σ 闸四态)、JdSchemaContractTest 钉 V216/V217、
两条 SQL 台账(XML_SELECT_TOTAL 109→111、XML_STATEMENT_TOTAL 156→158)逐条点名。
- 后管:jd-publish-quota-edit.test.ts 3(含 0 语义分档与「绝不拼/0」)、
platform-account-pages 源码钉子改钉新形状、source-pin 台账 cases 1867→1868 逐条点名。
- 用户端:jd-on-shelf.test.ts 纯函数+mount 面板判据;catch-silence 台账 blocks 336→338 点名。
141 lines
5.0 KiB
TypeScript
141 lines
5.0 KiB
TypeScript
import { beforeEach, expect, it, vi } from 'vitest'
|
||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||
import JdOnShelfPanel from '@/pages/jd/JdOnShelfPanel.vue'
|
||
|
||
/**
|
||
* 在架商品面板 mount 判据(2026-11-25 额度改口径):余量读数、展开取数、
|
||
* 标记已下架走确认框两臂+成功回执+重取列表。api 模块整体 mock——
|
||
* 面板必须经 fetchJdOnShelf/markJdItemDelisted 出口(裸 URL 回退当场红)。
|
||
*/
|
||
|
||
const api = vi.hoisted(() => ({
|
||
onShelf: vi.fn(),
|
||
markDelisted: vi.fn(),
|
||
confirm: vi.fn(),
|
||
success: vi.fn(),
|
||
error: vi.fn(),
|
||
}))
|
||
|
||
vi.mock('@/shared/api/types/modules/jd-publish', () => ({
|
||
fetchJdOnShelf: api.onShelf,
|
||
markJdItemDelisted: api.markDelisted,
|
||
}))
|
||
vi.mock('element-plus', async (importOriginal) => ({
|
||
...await importOriginal<typeof import('element-plus')>(),
|
||
ElMessage: { success: api.success, error: api.error },
|
||
ElMessageBox: { confirm: api.confirm },
|
||
}))
|
||
|
||
function pageVo(overrides: Record<string, unknown> = {}) {
|
||
return {
|
||
used: 2, limit: 5000, unlimited: false, total: 2,
|
||
items: [
|
||
{ itemId: 100, productId: 7, productCode: '100365361600', title: '收纳盒A', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:30:04' },
|
||
{ itemId: 101, productId: 8, productCode: '100365355826', title: '纸巾盒B', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:21:29' },
|
||
],
|
||
...overrides,
|
||
}
|
||
}
|
||
|
||
let wrapper: VueWrapper | undefined
|
||
|
||
beforeEach(() => {
|
||
vi.clearAllMocks()
|
||
wrapper?.unmount()
|
||
wrapper = undefined
|
||
})
|
||
|
||
async function mountPanel() {
|
||
// 替身注册法与 jd-publish-dispatch.mount.test.ts 同族:分页替身+loading 指令空实现
|
||
wrapper = mount(JdOnShelfPanel, {
|
||
global: {
|
||
stubs: { ElPagination: { emits: ['current-change'], template: '<div />' } },
|
||
directives: { loading: () => undefined },
|
||
},
|
||
})
|
||
await flushPromises()
|
||
return wrapper
|
||
}
|
||
|
||
it('默认收起不取数;展开后拉第一页并显余量读数', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
const w = await mountPanel()
|
||
expect(api.onShelf).not.toHaveBeenCalled()
|
||
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||
expect(api.onShelf.mock.calls[0][0]).toBe(1)
|
||
expect(api.onShelf.mock.calls[0][1]).toBe(20)
|
||
expect(w.text()).toContain('当前在架 2/5000')
|
||
expect(w.findAll('.on-shelf-row')).toHaveLength(2)
|
||
expect(w.text()).toContain('收纳盒A')
|
||
})
|
||
|
||
it('不限档显「不限」,绝不显「/0」坏数', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo({ used: 0, limit: 0, unlimited: true, total: 0, items: [] }))
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
expect(w.text()).toContain('当前在架 0/不限')
|
||
expect(w.text()).not.toContain('/0')
|
||
expect(w.text()).toContain('上架成功后的商品会出现在这里')
|
||
})
|
||
|
||
it('额度到顶出琥珀提醒句', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo({ used: 5000, total: 5000 }))
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
expect(w.find('.on-shelf-warn').text()).toContain('额度已满')
|
||
expect(w.find('.on-shelf-warn').text()).toContain('标记已下架')
|
||
})
|
||
|
||
it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重取列表', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockResolvedValue(true)
|
||
api.markDelisted.mockResolvedValue(null)
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.markDelisted).toHaveBeenCalledWith(100, true)
|
||
expect(api.success).toHaveBeenCalledTimes(1)
|
||
expect(String(api.success.mock.calls[0][0])).toContain('100365361600')
|
||
// 标记成功后重取(腾额度读数当场回跳)
|
||
expect(api.onShelf).toHaveBeenCalledTimes(2)
|
||
})
|
||
|
||
it('确认框取消(reject 臂)不发起标记', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockRejectedValue('cancel')
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
await w.findAll('.on-shelf-mark')[1].trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.markDelisted).not.toHaveBeenCalled()
|
||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||
})
|
||
|
||
it('标记失败透出服务端原文(跨团队 403 等)', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockResolvedValue(true)
|
||
api.markDelisted.mockRejectedValue(new Error('只能标记本团队(管理员及其名下员工)的上架商品'))
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.error).toHaveBeenCalledTimes(1)
|
||
expect(String(api.error.mock.calls[0][0])).toContain('本团队')
|
||
})
|