171 lines
8.2 KiB
JavaScript
171 lines
8.2 KiB
JavaScript
/**
|
||
* P3-API - 教练端品牌定制 & 通知消息 & 违规记录 API 测试
|
||
* 流程:教练登录 → 获取品牌配置 → 获取Banner/通知 → 获取违规记录
|
||
*
|
||
* 使用 HTTP API(HMAC-SHA256 签名 + JWT Token)
|
||
* 前置条件:后端服务 http://192.168.110.64:8084 已启动
|
||
*/
|
||
const api = require('../helpers/api-helper');
|
||
|
||
const COACH_USERNAME = 'coach_zhang';
|
||
const COACH_PASSWORD = 'Test@123';
|
||
|
||
let authToken = null;
|
||
let coachId = null;
|
||
|
||
describe('P3-API - 教练端品牌定制 & 通知 & 违规记录', () => {
|
||
// ════════════════════════════════════════════════════
|
||
// 步骤0:教练登录
|
||
// ════════════════════════════════════════════════════
|
||
beforeAll(async () => {
|
||
console.log('════════════════════════════════════════════');
|
||
console.log('P3-API - 教练端品牌定制 & 通知 & 违规记录');
|
||
console.log('════════════════════════════════════════════');
|
||
|
||
const result = await api.coachLogin(COACH_USERNAME, COACH_PASSWORD);
|
||
expect(result).not.toBeNull();
|
||
expect(result.token).toBeDefined();
|
||
authToken = result.token;
|
||
coachId = result.userId;
|
||
console.log(`[P3-API] 教练登录成功: userId=${coachId}`);
|
||
}, 30000);
|
||
|
||
// ════════════════════════════════════════════════════
|
||
// 步骤1:品牌定制配置
|
||
// ════════════════════════════════════════════════════
|
||
describe('品牌定制配置', () => {
|
||
test('TC-COACH-BRAND-001: 获取品牌配置', async () => {
|
||
const res = await api.getBrandConfig(authToken);
|
||
console.log(`[TC-COACH-BRAND-001] status=${res.status}`);
|
||
|
||
if (api.isSuccess(res)) {
|
||
const brand = res.data?.data || res.data || {};
|
||
console.log(` 品牌名称: ${brand.brandName || '(未设置)'}`);
|
||
console.log(` 品牌口号: ${brand.slogan || '(未设置)'}`);
|
||
console.log(` 主色调: ${brand.primaryColor || '(默认)'}`);
|
||
console.log(` 辅助色: ${brand.secondaryColor || '(默认)'}`);
|
||
|
||
expect(brand).toBeDefined();
|
||
}
|
||
});
|
||
|
||
test('TC-COACH-BRAND-002: 品牌颜色为合法HEX值', async () => {
|
||
const res = await api.getBrandConfig(authToken);
|
||
if (!api.isSuccess(res)) {
|
||
console.warn('[TC-COACH-BRAND-002] 获取失败,跳过');
|
||
return;
|
||
}
|
||
|
||
const brand = res.data?.data || res.data || {};
|
||
if (brand.primaryColor) {
|
||
expect(/^#[0-9A-Fa-f]{6,8}$/.test(brand.primaryColor)).toBe(true);
|
||
console.log(` 主色调 HEX 合法: ${brand.primaryColor}`);
|
||
}
|
||
if (brand.secondaryColor) {
|
||
expect(/^#[0-9A-Fa-f]{6,8}$/.test(brand.secondaryColor)).toBe(true);
|
||
console.log(` 辅助色 HEX 合法: ${brand.secondaryColor}`);
|
||
}
|
||
});
|
||
});
|
||
|
||
// ════════════════════════════════════════════════════
|
||
// 步骤2:违规记录
|
||
// ════════════════════════════════════════════════════
|
||
describe('违规记录', () => {
|
||
test('TC-VIOLATION-001: 获取所有教练违规统计', async () => {
|
||
const res = await api.getViolationCounts(authToken);
|
||
console.log(`[TC-VIOLATION-001] status=${res.status}`);
|
||
|
||
if (api.isSuccess(res)) {
|
||
const counts = res.data?.data || res.data || [];
|
||
console.log(` 违规统计条目数: ${Array.isArray(counts) ? counts.length : 'N/A'}`);
|
||
|
||
if (Array.isArray(counts) && counts.length > 0) {
|
||
counts.slice(0, 3).forEach(c => {
|
||
console.log(` - coachName=${c.coachName || c.name}, violations=${c.violationCount || c.count}`);
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|
||
test('TC-VIOLATION-002: 获取当前教练违规记录', async () => {
|
||
const res = await api.getCoachViolations(coachId, authToken);
|
||
console.log(`[TC-VIOLATION-002] status=${res.status}`);
|
||
|
||
if (api.isSuccess(res)) {
|
||
const violations = res.data?.data || res.data || [];
|
||
const records = Array.isArray(violations) ? violations : (violations.content || violations.records || []);
|
||
console.log(` 教练 ${coachId} 违规记录数: ${records.length}`);
|
||
|
||
if (records.length > 0) {
|
||
records.slice(0, 3).forEach(v => {
|
||
console.log(` - type=${v.type || v.violationType}, time=${v.time || v.createTime}, desc=${(v.description || '').substring(0, 40)}`);
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|
||
test('TC-VIOLATION-003: 不存在教练ID应返回空', async () => {
|
||
const res = await api.getCoachViolations(99999, authToken);
|
||
console.log(`[TC-VIOLATION-003] 不存在教练: status=${res.status}`);
|
||
|
||
if (api.isSuccess(res)) {
|
||
const violations = res.data?.data || res.data || [];
|
||
const records = Array.isArray(violations) ? violations : [];
|
||
expect(records.length).toBe(0);
|
||
}
|
||
});
|
||
});
|
||
|
||
// ════════════════════════════════════════════════════
|
||
// 步骤3:Banner & 系统通知
|
||
// ════════════════════════════════════════════════════
|
||
describe('Banner & 系统通知', () => {
|
||
test('TC-COACH-NOTIFY-001: 获取活跃Banner', async () => {
|
||
const res = await api.getActiveBanners(authToken);
|
||
console.log(`[TC-COACH-NOTIFY-001] status=${res.status}`);
|
||
|
||
if (api.isSuccess(res)) {
|
||
const banners = res.data?.data || res.data || [];
|
||
const records = Array.isArray(banners) ? banners : (banners.records || []);
|
||
console.log(` 活跃Banner数量: ${records.length}`);
|
||
expect(records.length).toBeGreaterThanOrEqual(0);
|
||
}
|
||
});
|
||
|
||
test('TC-COACH-NOTIFY-002: 获取系统通知', async () => {
|
||
const res = await api.getSystemNotices(authToken);
|
||
console.log(`[TC-COACH-NOTIFY-002] status=${res.status}`);
|
||
|
||
if (api.isSuccess(res)) {
|
||
const notices = res.data?.data || res.data || [];
|
||
const records = Array.isArray(notices) ? notices : (notices.records || []);
|
||
console.log(` 系统通知数量: ${records.length}`);
|
||
}
|
||
});
|
||
});
|
||
|
||
// ════════════════════════════════════════════════════
|
||
// 步骤4:总结
|
||
// ════════════════════════════════════════════════════
|
||
describe('总结', () => {
|
||
test('TC-P3-COACH-SUMMARY: 教练端品牌/通知/违规测试汇总', () => {
|
||
console.log('');
|
||
console.log('════════════════════════════════════════════');
|
||
console.log('P3-API - 教练端品牌 & 通知 & 违规记录测试结束');
|
||
console.log('════════════════════════════════════════════');
|
||
console.log(' 已测试:');
|
||
console.log(' 1. 品牌配置 (名称/颜色)');
|
||
console.log(' 2. 所有教练违规统计');
|
||
console.log(' 3. 当前教练违规记录');
|
||
console.log(' 4. 不存在教练违规边界');
|
||
console.log(' 5. 活跃Banner列表');
|
||
console.log(' 6. 系统通知列表');
|
||
console.log('════════════════════════════════════════════');
|
||
|
||
expect(coachId).toBeDefined();
|
||
expect(authToken).toBeTruthy();
|
||
});
|
||
});
|
||
});
|