- 新表 user_coupons(快照面额/门槛/类目/有效期)+ orders.user_coupon_id - 仓储:getCouponsWithClaimed/claimCoupon/getUserCoupons/resolveUserCoupon/consumeUserCoupon/releaseUserCouponByOrder - 接口:POST /api/marketing/coupons/:id/claim(同券仅一次、受总量限制)、GET /api/marketing/my-coupons(自动标记过期)、券中心带 claimed 标识 - 下单:createOrder 支持 userCouponId(校验归属/门槛/类目/有效期,服务端算抵扣,与订单同事务占用) - 回退:买家取消/大神拒单/超时退款/仲裁退款 均把券退回为 UNUSED - 小程序:新增 pages/user/coupons(券中心+我的券)、个人中心入口(可用张数)、下单改为选择"我的券"并传 userCouponId - 回归 94 套件/666 用例全绿;冒烟 9/9(领取/重复领取409/不存在404/下单抵扣100-10=90/取消回退)
47 行
2.2 KiB
TypeScript
47 行
2.2 KiB
TypeScript
// 已读取AGENTS.md
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
/**
|
|
* 第七十八批:优惠券中心(领取)+ 我的券 + 下单核销/回退。
|
|
*/
|
|
describe('第七十八批优惠券中心闸门', () => {
|
|
const root = path.resolve(__dirname, '../../');
|
|
const indexCode = fs.readFileSync(path.join(root, 'server/src/index.ts'), 'utf-8');
|
|
const repo = fs.readFileSync(path.join(root, 'server/src/db/repository.ts'), 'utf-8');
|
|
const mysql = fs.readFileSync(path.join(root, 'server/src/db/mysql.ts'), 'utf-8');
|
|
const api = fs.readFileSync(path.join(root, 'pwuniapp/common/api.js'), 'utf-8');
|
|
const pagesJson = fs.readFileSync(path.join(root, 'pwuniapp/pages.json'), 'utf-8');
|
|
const userPage = fs.readFileSync(path.join(root, 'pwuniapp/pages/user/index.vue'), 'utf-8');
|
|
const createPage = fs.readFileSync(path.join(root, 'pwuniapp/pages/order/create.vue'), 'utf-8');
|
|
|
|
it('建表与仓储具备用户券能力', () => {
|
|
expect(mysql).toContain('CREATE TABLE IF NOT EXISTS user_coupons');
|
|
expect(mysql).toContain('ALTER TABLE orders ADD COLUMN user_coupon_id');
|
|
expect(repo).toContain('async claimCoupon(');
|
|
expect(repo).toContain('async getUserCoupons(');
|
|
expect(repo).toContain('async resolveUserCoupon(');
|
|
expect(repo).toContain('async releaseCouponWithConn(');
|
|
});
|
|
|
|
it('领取/我的券接口就绪,券中心带已领取标记', () => {
|
|
expect(indexCode).toContain("app.post('/api/marketing/coupons/:id/claim'");
|
|
expect(indexCode).toContain("app.get('/api/marketing/my-coupons'");
|
|
expect(indexCode).toContain('getCouponsWithClaimed');
|
|
});
|
|
|
|
it('下单支持"我的券"并占用,退款/取消回退', () => {
|
|
expect(repo).toContain('resolveUserCoupon(String(data.userCouponId)');
|
|
expect(repo).toContain("WHERE id = ? AND status = 'UNUSED'");
|
|
expect((repo.match(/releaseCouponWithConn\(/g) || []).length).toBeGreaterThanOrEqual(4);
|
|
});
|
|
|
|
it('小程序具备券中心页面与下单用券', () => {
|
|
expect(pagesJson).toContain('pages/user/coupons');
|
|
expect(api).toContain('export async function claimCoupon(');
|
|
expect(api).toContain('export async function getMyCoupons(');
|
|
expect(userPage).toContain('openCoupons');
|
|
expect(createPage).toContain('userCouponId');
|
|
});
|
|
});
|