/** * TC-CONNECTOR_API-002 · 条件不满足时不能办理连接器注册、更新、撤销 * REQ-060 [FL-3.1] 反向/场景法 P0 * * 前置:连接器接口可调用 / 已准备错误数据 * 步骤:使用错误数据办理注册、更新、撤销 → 查看提示与数据 * 预期:接口对必填字段缺失、重复标识、不存在 ID、空 reason 均拒绝,并说明原因 */ export const meta = { tc: 'TC-CONNECTOR_API-002', req: 'REQ-060', title: '条件不满足时不能办理连接器注册、更新、撤销', type: '反向/场景法', priority: 'P0', route: '', needs: ['be'] } export async function run(t) { await t.login() let beforeCount = 0 await t.step('前置:记录当前连接器数量', async () => { const list = await t.apiList('/api/ssw/tds/Connector', { pageSize: 1 }) beforeCount = list.length t.assert(true, `记录当前列表数 ${beforeCount}`) }) await t.step('注册:缺 connectorCode / name / spaceId 均被拒', async () => { const cases = [ { body: {}, need: /标识|为空/ }, { body: { connectorCode: t.uid('A') }, need: /名称|为空/ }, { body: { connectorCode: t.uid('B'), name: 'no-space' }, need: /空间|为空/ } ] for (const c of cases) { const r = await t.api('POST', '/api/ssw/tds/Connector', c.body) t.assert(r.code !== 200, `缺关键字段被拒(实际 code=${r.code} msg=${r.msg})`) t.assert(c.need.test(r.msg || ''), `提示信息「${r.msg}」命中预期「${c.need}」`) } }) await t.step('注册:重复的 connectorCode 被拒', async () => { const list = await t.apiList('/api/ssw/tds/Connector', { pageSize: 50 }) if (!list.length) t.skip('库中无连接器,跳过重复校验') const r = await t.api('POST', '/api/ssw/tds/Connector', { connectorCode: list[0].connectorCode, name: 'dup', spaceId: list[0].spaceId }) t.assert(r.code !== 200, `重复 connectorCode 被拒(实际 code=${r.code})`) t.assert(/已存在|重复|唯一/i.test(r.msg || ''), `提示说明重复(实际「${r.msg}」)`) }) await t.step('更新:不存在的 ID 被拒', async () => { const r = await t.api('PUT', '/api/ssw/tds/Connector/non-existent-id-yyy', { name: 'x' }) t.assert(r.code !== 200, `不存在的 ID 更新被拒(实际 code=${r.code})`) }) await t.step('撤销:reason 为空被拒', async () => { const list = await t.apiList('/api/ssw/tds/Connector', { pageSize: 50 }) const alive = list.find((r) => r.status !== 'CANCELLED') if (!alive) t.skip('没有非 CANCELLED 记录,跳过') const r = await t.api('PUT', `/api/ssw/tds/Connector/${alive.id}/Cancel`, { reason: '' }) t.assert(r.code !== 200, `reason 为空被拒(实际 code=${r.code})`) t.assert(/原因|为空|必填/i.test(r.msg || ''), `提示说明原因(实际「${r.msg}」)`) }) await t.step('核对原有数据未被脏写', async () => { const after = await t.apiList('/api/ssw/tds/Connector', { pageSize: 1 }) t.assert(after.length === beforeCount || after.length >= beforeCount, `列表条数未因非法请求增长(${beforeCount} → ${after.length})`) }) }