Files
gym-manage/gym-manage-uniapp/e2e/specs/member-brand-notify.spec.js
T

180 lines
8.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* P3-API - 会员端品牌定制 & 通知消息 API 测试
* 流程:会员登录 → 获取品牌配置 → 获取Banner/通知
*
* 使用 HTTP APIHMAC-SHA256 签名 + JWT Token
* 前置条件:后端服务 http://192.168.110.64:8084 已启动
*/
const api = require('../helpers/api-helper');
let authToken = null;
let memberId = null;
describe('P3-API - 会员端品牌定制 & 通知消息', () => {
// ════════════════════════════════════════════════════
// 步骤0:会员登录
// ════════════════════════════════════════════════════
beforeAll(async () => {
console.log('════════════════════════════════════════════');
console.log('P3-API - 品牌定制 & 通知消息测试');
console.log('════════════════════════════════════════════');
const result = await api.memberLogin();
expect(result).not.toBeNull();
authToken = result.accessToken;
memberId = result.memberId;
console.log(`[P3-API] 会员登录成功: memberId=${memberId}`);
}, 30000);
// ════════════════════════════════════════════════════
// 步骤1:品牌定制配置
// ════════════════════════════════════════════════════
describe('品牌定制配置', () => {
test('TC-BRAND-001: 获取品牌配置', async () => {
const res = await api.getBrandConfig(authToken);
console.log(`[TC-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 || '(默认)'}`);
console.log(` Logo URL: ${brand.logoUrl || '(默认)'}`);
console.log(` 背景URL: ${brand.backgroundUrl || '(默认)'}`);
// 品牌名称应存在(至少默认值)
expect(brand).toBeDefined();
}
});
test('TC-BRAND-002: 验证品牌颜色为合法HEX值', async () => {
const res = await api.getBrandConfig(authToken);
if (!api.isSuccess(res)) {
console.warn('[TC-BRAND-002] 获取品牌配置失败,跳过');
return;
}
const brand = res.data?.data || res.data || {};
const primaryColor = brand.primaryColor;
const secondaryColor = brand.secondaryColor;
if (primaryColor) {
// 验证是合法 HEX (#RRGGBB 或 #RRGGBBAA)
expect(/^#[0-9A-Fa-f]{6,8}$/.test(primaryColor)).toBe(true);
console.log(` 主色调 HEX 合法: ${primaryColor}`);
}
if (secondaryColor) {
expect(/^#[0-9A-Fa-f]{6,8}$/.test(secondaryColor)).toBe(true);
console.log(` 辅助色 HEX 合法: ${secondaryColor}`);
}
});
test('TC-BRAND-003: Logo URL 应为有效路径或默认占位符', async () => {
const res = await api.getBrandConfig(authToken);
if (!api.isSuccess(res)) {
console.warn('[TC-BRAND-003] 获取品牌配置失败,跳过');
return;
}
const brand = res.data?.data || res.data || {};
const logoUrl = brand.logoUrl;
if (logoUrl) {
// 可以是完整URL、相对路径、或base64
const isValid = typeof logoUrl === 'string' && logoUrl.length > 0;
expect(isValid).toBe(true);
console.log(` Logo URL: ${logoUrl.substring(0, 80)}...`);
} else {
console.log(' Logo URL 为空(使用默认值)');
}
});
});
// ════════════════════════════════════════════════════
// 步骤2Banner & 系统通知
// ════════════════════════════════════════════════════
describe('Banner & 系统通知', () => {
test('TC-NOTIFY-001: 获取活跃Banner列表', async () => {
const res = await api.getActiveBanners(authToken);
console.log(`[TC-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}`);
if (records.length > 0) {
const b = records[0];
console.log(` 首条Banner: title="${b.title}", imageUrl=${(b.imageUrl || '').substring(0, 50)}`);
}
}
});
test('TC-NOTIFY-002: 获取系统通知列表', async () => {
const res = await api.getSystemNotices(authToken);
console.log(`[TC-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}`);
if (records.length > 0) {
const n = records[0];
console.log(` 首条通知: title="${n.noticeTitle || n.title}", status=${n.status}`);
}
}
});
test('TC-NOTIFY-003: 获取用户消息列表', async () => {
const res = await api.getUserMessages(memberId, authToken);
console.log(`[TC-NOTIFY-003] status=${res.status}`);
if (api.isSuccess(res)) {
const messages = res.data?.data || res.data || [];
const records = Array.isArray(messages) ? messages : (messages.records || []);
console.log(` 消息数量: ${records.length}`);
}
// 消息可能为空,不强制要求有数据
});
test('TC-NOTIFY-004: 获取未读消息数', async () => {
const res = await api.getUnreadMessageCount(memberId, authToken);
console.log(`[TC-NOTIFY-004] status=${res.status}`);
if (api.isSuccess(res)) {
const count = Number(res.data?.data ?? res.data ?? 0);
console.log(` 未读消息数: ${count}`);
expect(typeof count).toBe('number');
expect(count).toBeGreaterThanOrEqual(0);
}
});
});
// ════════════════════════════════════════════════════
// 步骤3:总结
// ════════════════════════════════════════════════════
describe('总结', () => {
test('TC-P3-SUMMARY: 品牌定制 & 通知消息测试汇总', () => {
console.log('');
console.log('════════════════════════════════════════════');
console.log('P3-API - 品牌定制 & 通知消息测试结束');
console.log('════════════════════════════════════════════');
console.log(' 已测试:');
console.log(' 1. 品牌配置获取 (名称/颜色/Logo/背景)');
console.log(' 2. 颜色HEX格式校验');
console.log(' 3. Logo URL有效性');
console.log(' 4. 活跃Banner列表');
console.log(' 5. 系统通知列表');
console.log(' 6. 用户消息列表');
console.log(' 7. 未读消息数量');
console.log('════════════════════════════════════════════');
expect(memberId).toBeDefined();
expect(authToken).toBeTruthy();
});
});
});