feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -401,3 +401,232 @@ describe('OmniCard AI 用户端微官网 Bento 首页与 Hero 业务逻辑测试
|
||||
});
|
||||
});
|
||||
|
||||
describe('OmniCard AI 门户 Cookie 同意条契约 (R33)', () => {
|
||||
const fs = require('fs') as typeof import('fs');
|
||||
const path = require('path') as typeof import('path');
|
||||
const PORTAL_PAGE = path.resolve(
|
||||
__dirname,
|
||||
'../../../mpuniapp/pages/portal/index.uvue'
|
||||
);
|
||||
const LOCALE_FILE = path.resolve(
|
||||
__dirname,
|
||||
'../../../mpuniapp/common/locale.uts'
|
||||
);
|
||||
const COOKIE_CONSENT_KEY = 'omni_cookie_consent';
|
||||
const COOKIE_CONSENT_ACCEPTED = 'accepted';
|
||||
|
||||
function readPortalPage(): string {
|
||||
return fs.readFileSync(PORTAL_PAGE, 'utf8');
|
||||
}
|
||||
|
||||
function extractFunctionBody(source: string, fnName: string): string {
|
||||
const marker = `function ${fnName}`;
|
||||
const start = source.indexOf(marker);
|
||||
expect(start).toBeGreaterThan(-1);
|
||||
const braceStart = source.indexOf('{', start);
|
||||
expect(braceStart).toBeGreaterThan(-1);
|
||||
let depth = 0;
|
||||
for (let i = braceStart; i < source.length; i++) {
|
||||
const ch = source.charAt(i);
|
||||
if (ch === '{') depth++;
|
||||
if (ch === '}') {
|
||||
depth--;
|
||||
if (depth === 0) {
|
||||
return source.slice(braceStart, i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
it('8.1 无本地同意记录时模板仅渲染一条 Cookie 同意条,文案走 i18n', () => {
|
||||
const pageSource = readPortalPage();
|
||||
const localeSource = fs.readFileSync(LOCALE_FILE, 'utf8');
|
||||
const template = pageSource.split('<script')[0];
|
||||
const cookieBlockMatch = template.match(
|
||||
/v-if="showCookieBanner"[\s\S]*?cookie-consent-bar[\s\S]*?<\/view>/
|
||||
);
|
||||
const cookieBlock = cookieBlockMatch != null ? cookieBlockMatch[0] : '';
|
||||
|
||||
expect(template.includes('cookie-consent-bar')).toBe(true);
|
||||
expect((template.match(/class="cookie-consent-bar"/g) || []).length).toBe(1);
|
||||
expect(template.includes('v-if="showCookieBanner"')).toBe(true);
|
||||
expect(cookieBlock.includes("textOf('portal.cookie_notice')") || pageSource.includes("textOf('portal.cookie_notice')")).toBe(true);
|
||||
expect(pageSource.includes("textOf('portal.cookie_accept')")).toBe(true);
|
||||
expect(pageSource.includes("textOf('portal.cookie_reject')")).toBe(true);
|
||||
expect(/[\u4e00-\u9fff]/.test(cookieBlock)).toBe(false);
|
||||
|
||||
expect(localeSource.includes("'portal.cookie_notice'")).toBe(true);
|
||||
expect(localeSource.includes("'portal.cookie_accept'")).toBe(true);
|
||||
expect(localeSource.includes("'portal.cookie_reject'")).toBe(true);
|
||||
|
||||
expect(pageSource.includes(COOKIE_CONSENT_KEY)).toBe(true);
|
||||
expect(pageSource.includes(COOKIE_CONSENT_ACCEPTED)).toBe(true);
|
||||
expect(pageSource.includes('initCookieBanner')).toBe(true);
|
||||
});
|
||||
|
||||
it('8.2 点同意才写入本地同意记录并收起条;无记录时不假装已同意', () => {
|
||||
const pageSource = readPortalPage();
|
||||
const acceptBody = extractFunctionBody(pageSource, 'acceptCookieConsent');
|
||||
const initBody = extractFunctionBody(pageSource, 'initCookieBanner');
|
||||
|
||||
expect(acceptBody.includes('setStorageSync')).toBe(true);
|
||||
expect(
|
||||
acceptBody.includes(COOKIE_CONSENT_KEY) ||
|
||||
acceptBody.includes('COOKIE_CONSENT_KEY')
|
||||
).toBe(true);
|
||||
expect(
|
||||
acceptBody.includes(COOKIE_CONSENT_ACCEPTED) ||
|
||||
acceptBody.includes('COOKIE_CONSENT_ACCEPTED')
|
||||
).toBe(true);
|
||||
expect(acceptBody.includes('showCookieBanner.value = false')).toBe(true);
|
||||
|
||||
expect(initBody.includes('getStorageSync') || pageSource.includes('readCookieConsentRaw')).toBe(true);
|
||||
expect(pageSource.includes(`'${COOKIE_CONSENT_KEY}'`) || pageSource.includes(`"${COOKIE_CONSENT_KEY}"`)).toBe(true);
|
||||
expect(pageSource.includes(`'${COOKIE_CONSENT_ACCEPTED}'`) || pageSource.includes(`"${COOKIE_CONSENT_ACCEPTED}"`)).toBe(true);
|
||||
expect(initBody.includes('showCookieBanner')).toBe(true);
|
||||
expect(initBody.includes('hasCookieConsentRecord')).toBe(true);
|
||||
// 初始化不得写死已同意(不在无检查时直接 false)
|
||||
expect(initBody.trim() === '{ showCookieBanner.value = false; }').toBe(false);
|
||||
|
||||
// 行为模拟:无记录 → 应显示;写入 accepted → 收起
|
||||
const storage = new Map<string, string>();
|
||||
const hasRecord = (): boolean =>
|
||||
storage.get(COOKIE_CONSENT_KEY) === COOKIE_CONSENT_ACCEPTED;
|
||||
let show = !hasRecord();
|
||||
expect(show).toBe(true);
|
||||
storage.set(COOKIE_CONSENT_KEY, COOKIE_CONSENT_ACCEPTED);
|
||||
show = !hasRecord();
|
||||
expect(show).toBe(false);
|
||||
expect(hasRecord()).toBe(true);
|
||||
});
|
||||
|
||||
it('8.3 点拒绝不得写入同意记录,不得把拒绝当成已同意', () => {
|
||||
const pageSource = readPortalPage();
|
||||
const rejectBody = extractFunctionBody(pageSource, 'rejectCookieConsent');
|
||||
|
||||
expect(rejectBody.includes('setStorageSync')).toBe(false);
|
||||
expect(rejectBody.includes('COOKIE_CONSENT_ACCEPTED')).toBe(false);
|
||||
expect(rejectBody.includes(`'${COOKIE_CONSENT_ACCEPTED}'`)).toBe(false);
|
||||
expect(rejectBody.includes('showCookieBanner.value = false')).toBe(true);
|
||||
|
||||
// 行为模拟:拒绝只收起当前会话条,本地仍无同意记录
|
||||
const storage = new Map<string, string>();
|
||||
let show = !storage.has(COOKIE_CONSENT_KEY);
|
||||
expect(show).toBe(true);
|
||||
// reject: hide only
|
||||
show = false;
|
||||
expect(storage.has(COOKIE_CONSENT_KEY)).toBe(false);
|
||||
expect(storage.get(COOKIE_CONSENT_KEY)).toBeUndefined();
|
||||
// 再次进入:无同意记录 → 仍应出现同意条
|
||||
show = storage.get(COOKIE_CONSENT_KEY) !== COOKIE_CONSENT_ACCEPTED;
|
||||
expect(show).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('OmniCard AI 门户 Line / KakaoTalk 空 URL 不渲染 (R38)', () => {
|
||||
const fs = require('fs') as typeof import('fs');
|
||||
const path = require('path') as typeof import('path');
|
||||
const PORTAL_PAGE = path.resolve(
|
||||
__dirname,
|
||||
'../../../mpuniapp/pages/portal/index.uvue'
|
||||
);
|
||||
const PORTAL_LOGIC = path.resolve(
|
||||
__dirname,
|
||||
'../../../mpuniapp/pages/portal/usePortal.uts'
|
||||
);
|
||||
const LOCALE_FILE = path.resolve(
|
||||
__dirname,
|
||||
'../../../mpuniapp/common/locale.uts'
|
||||
);
|
||||
|
||||
function readPortalPage(): string {
|
||||
return fs.readFileSync(PORTAL_PAGE, 'utf8');
|
||||
}
|
||||
|
||||
function readPortalLogic(): string {
|
||||
return fs.readFileSync(PORTAL_LOGIC, 'utf8');
|
||||
}
|
||||
|
||||
it('9.1 isRenderableHttpUrl:空/缺失/非 http(s) 为 false,合法 http(s) 为 true', () => {
|
||||
// @ts-ignore
|
||||
const { isRenderableHttpUrl } = require('../../../mpuniapp/pages/portal/usePortal.uts');
|
||||
|
||||
expect(isRenderableHttpUrl(undefined)).toBe(false);
|
||||
expect(isRenderableHttpUrl(null as any)).toBe(false);
|
||||
expect(isRenderableHttpUrl('')).toBe(false);
|
||||
expect(isRenderableHttpUrl(' ')).toBe(false);
|
||||
expect(isRenderableHttpUrl('line.me/ti/p/@demo')).toBe(false);
|
||||
expect(isRenderableHttpUrl('ftp://example.com/line')).toBe(false);
|
||||
expect(isRenderableHttpUrl('javascript:alert(1)')).toBe(false);
|
||||
expect(isRenderableHttpUrl('https://line.me/ti/p/@real')).toBe(true);
|
||||
expect(isRenderableHttpUrl('http://open.kakao.com/o/real')).toBe(true);
|
||||
});
|
||||
|
||||
it('9.2 模板仅在 hasQuickAction(line|kakao) 时渲染,无示例链接与演示账号', () => {
|
||||
const pageSource = readPortalPage();
|
||||
const logicSource = readPortalLogic();
|
||||
const localeSource = fs.readFileSync(LOCALE_FILE, 'utf8');
|
||||
const template = pageSource.split('<script')[0];
|
||||
|
||||
expect(template.includes("hasQuickAction('line')")).toBe(true);
|
||||
expect(template.includes("hasQuickAction('kakao')")).toBe(true);
|
||||
expect(template.includes("textOf('portal.line')")).toBe(true);
|
||||
expect(template.includes("textOf('portal.kakao')")).toBe(true);
|
||||
|
||||
// 不得硬编码演示账号 / 示例社交链
|
||||
expect(/line\.me\/ti\/p\/@demo/i.test(pageSource)).toBe(false);
|
||||
expect(/open\.kakao\.com\/o\/demo/i.test(pageSource)).toBe(false);
|
||||
expect(/example\.com\/(line|kakao)/i.test(pageSource)).toBe(false);
|
||||
expect(pageSource.includes('演示账号')).toBe(false);
|
||||
|
||||
// 空 URL 不渲染依赖 isRenderableHttpUrl / hasQuickAction
|
||||
expect(logicSource.includes('isRenderableHttpUrl')).toBe(true);
|
||||
expect(pageSource.includes('isRenderableHttpUrl') || pageSource.includes("hasQuickAction('line')")).toBe(true);
|
||||
|
||||
expect(localeSource.includes("'portal.line'")).toBe(true);
|
||||
expect(localeSource.includes("'portal.kakao'")).toBe(true);
|
||||
});
|
||||
|
||||
it('9.3 Line/Kakao 有合法 URL 可触发复制;空值不打开且不填示例链', () => {
|
||||
let clipboardText = '';
|
||||
const toastCalls: Array<{ title: string; icon?: string }> = [];
|
||||
(global as any).uni = {
|
||||
showToast: (options: { title: string; icon?: string }) => {
|
||||
toastCalls.push(options);
|
||||
},
|
||||
setClipboardData: (options: { data: string; success?: () => void }) => {
|
||||
clipboardText = options.data;
|
||||
options.success?.();
|
||||
},
|
||||
getStorageSync: () => '',
|
||||
setStorageSync: () => {},
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
const { triggerQuickAction } = require('../../../mpuniapp/pages/portal/usePortal.uts');
|
||||
|
||||
const okEmpty = triggerQuickAction('line', '');
|
||||
expect(okEmpty).toBe(false);
|
||||
expect(clipboardText).toBe('');
|
||||
expect(toastCalls.length).toBeGreaterThan(0);
|
||||
|
||||
toastCalls.length = 0;
|
||||
const okBad = triggerQuickAction('kakao', 'not-a-url');
|
||||
expect(okBad).toBe(false);
|
||||
expect(clipboardText).toBe('');
|
||||
|
||||
const lineUrl = 'https://line.me/ti/p/@real-user';
|
||||
const okLine = triggerQuickAction('line', lineUrl);
|
||||
expect(okLine).toBe(true);
|
||||
expect(clipboardText).toBe(lineUrl);
|
||||
|
||||
const kakaoUrl = 'https://open.kakao.com/o/real-user';
|
||||
const okKakao = triggerQuickAction('kakao', kakaoUrl);
|
||||
expect(okKakao).toBe(true);
|
||||
expect(clipboardText).toBe(kakaoUrl);
|
||||
|
||||
delete (global as any).uni;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户