/** * M01-01 产品主数据 - API Mock 测试 * TDD: US-02 根据编码精确查询(自动带出) * * 覆盖场景 (每场景不低于5条): * - 有效编码返回产品信息 * - 编码不存在返回 null data * - 已下架编码返回 3100_crm_product_009 错误 */ import { describe, it, expect } from 'vitest' import { getByCode } from '@/api/product-master-data/product' describe('API - getByCode - US-02 有效编码查询 (5条+)', () => { it('有效编码 PROD-001 返回产品完整信息', async () => { const res = await getByCode('PROD-001') expect(res.code).toBe('200') expect(res.data).not.toBeNull() expect(res.data!.productCode).toBe('PROD-001') expect(res.data!.productName).toBe('5052铝板') expect(res.data!.category).toBe('铝加工材') }) it('有效编码 PROD-002 返回产品信息', async () => { const res = await getByCode('PROD-002') expect(res.code).toBe('200') expect(res.data).not.toBeNull() expect(res.data!.productCode).toBe('PROD-002') expect(res.data!.isActive).toBe(1) }) it('有效编码 PROD-003 返回铝加工制品', async () => { const res = await getByCode('PROD-003') expect(res.code).toBe('200') expect(res.data!.category).toBe('铝加工制品') expect(res.data!.stage).toBe('试产') }) it('有效编码 PROD-005 返回废铝类产品', async () => { const res = await getByCode('PROD-005') expect(res.code).toBe('200') expect(res.data!.category).toBe('废铝') expect(res.data!.minOrderQty).toBe(10000.0000) }) it('有效编码 PROD-006 返回标品', async () => { const res = await getByCode('PROD-006') expect(res.code).toBe('200') expect(res.data!.standardized).toBe('标品') expect(res.data!.productName).toBe('铝门框架-X1') }) }) describe('API - getByCode - US-02 编码不存在 (5条+)', () => { it('不存在的编码 "NONEXIST" 返回 null data', async () => { const res = await getByCode('NONEXIST') expect(res.code).toBe('200') expect(res.data).toBeNull() }) it('空字符串编码返回 null data', async () => { const res = await getByCode('') expect(res.code).toBe('200') expect(res.data).toBeNull() }) it('大小写不匹配的编码 "prod-001" 返回 null', async () => { const res = await getByCode('prod-001') expect(res.code).toBe('200') expect(res.data).toBeNull() }) it('编码 "UNKNOWN-PROD" 返回 null', async () => { const res = await getByCode('UNKNOWN-PROD') expect(res.code).toBe('200') expect(res.data).toBeNull() }) it('编码 "PROD-999" 不存在返回 null', async () => { const res = await getByCode('PROD-999') expect(res.code).toBe('200') expect(res.data).toBeNull() }) }) describe('API - getByCode - US-02 已下架编码 (5条+)', () => { it('已下架产品 PROD-004 返回错误码 3100_crm_product_009', async () => { const res = await getByCode('PROD-004') expect(res.code).toBe('3100_crm_product_009') expect(res.msg).toBe('该产品已下架,不可使用') expect(res.data).toBeNull() }) it('已下架产品 PROD-007 返回错误码 3100_crm_product_009', async () => { const res = await getByCode('PROD-007') expect(res.code).toBe('3100_crm_product_009') expect(res.data).toBeNull() }) it('已下架产品的错误信息不为空', async () => { const res = await getByCode('PROD-004') expect(res.msg).toBeTruthy() }) it('已下架产品不返回产品数据', async () => { const res = await getByCode('PROD-004') expect(res.data).toBeNull() }) it('PROD-007 验证 isActive=0 的产品返回已下架错误', async () => { const res = await getByCode('PROD-007') expect(res.code).toBe('3100_crm_product_009') }) })