feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -98,6 +98,8 @@ type UseLeadDetailModule = {
|
||||
imageUrls: string[];
|
||||
};
|
||||
formatWhatsAppUrl: (phone: string | null | undefined) => string;
|
||||
callLeadPhone: (phone: string | null | undefined) => boolean;
|
||||
openLeadWhatsApp: (phoneOrWhatsApp: string | null | undefined) => boolean;
|
||||
createLeadDetailState?: () => Record<string, any>;
|
||||
generateAiIcebreaker: (
|
||||
lead: LeadEntity | null,
|
||||
@@ -113,7 +115,12 @@ type UseLeadDetailModule = {
|
||||
attachments?: string[];
|
||||
},
|
||||
api?: SaveNoteApi
|
||||
) => Promise<LeadEntity>;
|
||||
) => Promise<{
|
||||
ok: boolean;
|
||||
code?: number;
|
||||
lead: LeadEntity | null;
|
||||
errorMessage: string;
|
||||
}>;
|
||||
resolveLeadDetailText: (key: string) => string;
|
||||
};
|
||||
|
||||
@@ -156,18 +163,40 @@ function loadUseLeadDetail(): UseLeadDetailModule {
|
||||
}
|
||||
|
||||
describe('OmniCard AI 名片主潜客详情业务逻辑 (useLeadDetail.uts)', () => {
|
||||
let showToastMock: jest.Mock;
|
||||
let makePhoneCallMock: jest.Mock;
|
||||
let setClipboardDataMock: jest.Mock;
|
||||
let openUrlCalls: string[];
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
showToastMock = jest.fn();
|
||||
makePhoneCallMock = jest.fn();
|
||||
setClipboardDataMock = jest.fn(
|
||||
(options: { data: string; success?: () => void }) => {
|
||||
options.success?.();
|
||||
}
|
||||
);
|
||||
openUrlCalls = [];
|
||||
(global as { uni?: Record<string, unknown> }).uni = {
|
||||
getLocale: () => 'zh-CN',
|
||||
showToast: jest.fn(),
|
||||
showToast: showToastMock,
|
||||
makePhoneCall: makePhoneCallMock,
|
||||
setClipboardData: setClipboardDataMock,
|
||||
navigateBack: jest.fn(),
|
||||
navigateTo: jest.fn(),
|
||||
};
|
||||
(global as { window?: { open?: (url: string, target?: string) => void } }).window =
|
||||
{
|
||||
open: (url: string, _target?: string) => {
|
||||
openUrlCalls.push(url);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete (global as { uni?: Record<string, unknown> }).uni;
|
||||
delete (global as { window?: unknown }).window;
|
||||
});
|
||||
|
||||
describe('1. parseLeadId', () => {
|
||||
@@ -276,8 +305,10 @@ describe('OmniCard AI 名片主潜客详情业务逻辑 (useLeadDetail.uts)', ()
|
||||
);
|
||||
|
||||
expect(httpPost).toHaveBeenCalledTimes(1);
|
||||
expect(result.notes).toBe('Met at GITEX\nAsked for quote');
|
||||
expect(result.status).toBe('hot');
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.code).toBe(1000);
|
||||
expect(result.lead?.notes).toBe('Met at GITEX\nAsked for quote');
|
||||
expect(result.lead?.status).toBe('hot');
|
||||
});
|
||||
|
||||
it('3.3 updateLeadStage 调用 updateOwnerLeadStatus 推进商机阶段', async () => {
|
||||
@@ -366,6 +397,101 @@ describe('OmniCard AI 名片主潜客详情业务逻辑 (useLeadDetail.uts)', ()
|
||||
expect(ok).toBe(false);
|
||||
expect(httpPost).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('3.6 submitLeadNote 仅 code===1000 清空 nextNote;网络错误/非1000 保留输入', async () => {
|
||||
const mod = loadUseLeadDetail() as UseLeadDetailModule & {
|
||||
submitLeadNote: (
|
||||
state: Record<string, any>,
|
||||
api?: SaveNoteApi
|
||||
) => Promise<boolean>;
|
||||
saveNote: UseLeadDetailModule['saveNote'];
|
||||
};
|
||||
|
||||
const successPost = jest.fn(
|
||||
async (_url: string, data: Record<string, string | number>) => {
|
||||
return buildLead({ notes: String(data.notes) });
|
||||
}
|
||||
);
|
||||
const okState: Record<string, any> = {
|
||||
leadId: 21,
|
||||
lead: buildLead(),
|
||||
existingNotes: 'Met at GITEX',
|
||||
nextNote: 'Asked for quote',
|
||||
attachments: [],
|
||||
saving: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
const ok = await mod.submitLeadNote(okState, { httpPost: successPost });
|
||||
expect(ok).toBe(true);
|
||||
expect(okState.nextNote).toBe('');
|
||||
expect(okState.existingNotes).toContain('Asked for quote');
|
||||
|
||||
const failPost = jest.fn(async () => {
|
||||
throw new Error('网络连接异常,请重试');
|
||||
});
|
||||
const failState: Record<string, any> = {
|
||||
leadId: 21,
|
||||
lead: buildLead(),
|
||||
existingNotes: 'Met at GITEX',
|
||||
nextNote: 'Keep this draft',
|
||||
attachments: ['https://cdn.example.com/shot.jpg'],
|
||||
saving: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
const failOk = await mod.submitLeadNote(failState, { httpPost: failPost });
|
||||
expect(failOk).toBe(false);
|
||||
expect(failState.nextNote).toBe('Keep this draft');
|
||||
expect(failState.attachments).toEqual([
|
||||
'https://cdn.example.com/shot.jpg',
|
||||
]);
|
||||
expect(failState.existingNotes).toBe('Met at GITEX');
|
||||
expect(failState.errorMessage.length).toBeGreaterThan(0);
|
||||
|
||||
const non1000Post = jest.fn(async () => {
|
||||
throw new Error('请求处理失败');
|
||||
});
|
||||
const non1000State: Record<string, any> = {
|
||||
leadId: 21,
|
||||
lead: buildLead(),
|
||||
existingNotes: 'Old',
|
||||
nextNote: 'Draft stays',
|
||||
attachments: [],
|
||||
saving: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
const non1000Ok = await mod.submitLeadNote(non1000State, {
|
||||
httpPost: non1000Post,
|
||||
});
|
||||
expect(non1000Ok).toBe(false);
|
||||
expect(non1000State.nextNote).toBe('Draft stays');
|
||||
});
|
||||
|
||||
it('3.7 saveNote 成功结果带 code===1000;失败不伪装成功', async () => {
|
||||
const { saveNote } = loadUseLeadDetail();
|
||||
const httpPost = jest.fn(
|
||||
async (_url: string, data: Record<string, string | number>) => {
|
||||
return buildLead({ notes: String(data.notes) });
|
||||
}
|
||||
);
|
||||
const result = await saveNote(
|
||||
{ id: 21, notes: 'A', next: 'B' },
|
||||
{ httpPost }
|
||||
);
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.code).toBe(1000);
|
||||
expect(result.lead?.notes).toBe('A\nB');
|
||||
|
||||
const failPost = jest.fn(async () => {
|
||||
throw new Error('请求处理失败');
|
||||
});
|
||||
const failResult = await saveNote(
|
||||
{ id: 21, notes: 'A', next: 'B' },
|
||||
{ httpPost: failPost }
|
||||
);
|
||||
expect(failResult.ok).toBe(false);
|
||||
expect(failResult.code).not.toBe(1000);
|
||||
expect(failResult.lead).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('4. resolveLeadDetailText 只增文案', () => {
|
||||
@@ -456,6 +582,116 @@ describe('OmniCard AI 名片主潜客详情业务逻辑 (useLeadDetail.uts)', ()
|
||||
expect(state.source).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('6. 电话与 WhatsApp 真实触达 (callLeadPhone / openLeadWhatsApp)', () => {
|
||||
it('6.1 有合法电话时调用 makePhoneCall,不 toast 即将提供', () => {
|
||||
const { callLeadPhone, resolveLeadDetailText } = loadUseLeadDetail();
|
||||
|
||||
const ok = callLeadPhone('+971-50-1234567');
|
||||
|
||||
expect(ok).toBe(true);
|
||||
expect(makePhoneCallMock).toHaveBeenCalledTimes(1);
|
||||
expect(makePhoneCallMock.mock.calls[0][0].phoneNumber).toBe('+971-50-1234567');
|
||||
const comingSoon = resolveLeadDetailText('comingSoon');
|
||||
const toastedComingSoon = showToastMock.mock.calls.some(
|
||||
(c: unknown[]) =>
|
||||
c[0] != null &&
|
||||
typeof c[0] === 'object' &&
|
||||
(c[0] as { title?: string }).title === comingSoon
|
||||
);
|
||||
expect(toastedComingSoon).toBe(false);
|
||||
});
|
||||
|
||||
it('6.2 无合法电话时 toast comingSoon,不调 makePhoneCall', () => {
|
||||
const { callLeadPhone, resolveLeadDetailText } = loadUseLeadDetail();
|
||||
|
||||
expect(callLeadPhone('')).toBe(false);
|
||||
expect(callLeadPhone(null)).toBe(false);
|
||||
expect(callLeadPhone(' ')).toBe(false);
|
||||
expect(callLeadPhone('---')).toBe(false);
|
||||
expect(makePhoneCallMock).not.toHaveBeenCalled();
|
||||
expect(showToastMock).toHaveBeenCalled();
|
||||
expect(showToastMock.mock.calls[0][0].title).toBe(
|
||||
resolveLeadDetailText('comingSoon')
|
||||
);
|
||||
});
|
||||
|
||||
it('6.3 makePhoneCall fail 回调提示错误,不伪造成功', () => {
|
||||
makePhoneCallMock.mockImplementation(
|
||||
(options: {
|
||||
phoneNumber: string;
|
||||
fail?: (err: { errMsg?: string }) => void;
|
||||
}) => {
|
||||
options.fail?.({ errMsg: 'makePhoneCall:fail' });
|
||||
}
|
||||
);
|
||||
const { callLeadPhone, resolveLeadDetailText } = loadUseLeadDetail();
|
||||
|
||||
const ok = callLeadPhone('+8613800000000');
|
||||
expect(ok).toBe(true);
|
||||
expect(makePhoneCallMock).toHaveBeenCalledTimes(1);
|
||||
const failToast = showToastMock.mock.calls.find(
|
||||
(c: unknown[]) =>
|
||||
c[0] != null &&
|
||||
typeof c[0] === 'object' &&
|
||||
(c[0] as { title?: string }).title ===
|
||||
resolveLeadDetailText('callFailed')
|
||||
);
|
||||
expect(failToast).toBeDefined();
|
||||
expect(failToast![0].title).not.toBe(resolveLeadDetailText('comingSoon'));
|
||||
});
|
||||
|
||||
it('6.4 有号码时 openLeadWhatsApp 打开 wa.me 数字链接', () => {
|
||||
const { openLeadWhatsApp, formatWhatsAppUrl } = loadUseLeadDetail();
|
||||
const expected = formatWhatsAppUrl('+971-50-1234567');
|
||||
|
||||
const ok = openLeadWhatsApp('+971-50-1234567');
|
||||
|
||||
expect(ok).toBe(true);
|
||||
expect(expected).toBe('https://wa.me/971501234567');
|
||||
expect(openUrlCalls).toContain(expected);
|
||||
expect(
|
||||
showToastMock.mock.calls.some(
|
||||
(c: unknown[]) =>
|
||||
c[0] != null &&
|
||||
typeof c[0] === 'object' &&
|
||||
(c[0] as { title?: string }).title === '即将提供'
|
||||
)
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('6.5 无号码时 openLeadWhatsApp toast comingSoon,不打开空 wa.me', () => {
|
||||
const { openLeadWhatsApp, resolveLeadDetailText } = loadUseLeadDetail();
|
||||
|
||||
expect(openLeadWhatsApp('')).toBe(false);
|
||||
expect(openLeadWhatsApp(null)).toBe(false);
|
||||
expect(openLeadWhatsApp('abc')).toBe(false);
|
||||
expect(openUrlCalls).toEqual([]);
|
||||
expect(setClipboardDataMock).not.toHaveBeenCalled();
|
||||
const openedEmpty = setClipboardDataMock.mock.calls.some(
|
||||
(c: unknown[]) =>
|
||||
c[0] != null &&
|
||||
typeof c[0] === 'object' &&
|
||||
String((c[0] as { data?: string }).data || '').includes('wa.me/')
|
||||
);
|
||||
expect(openedEmpty).toBe(false);
|
||||
expect(showToastMock.mock.calls[0][0].title).toBe(
|
||||
resolveLeadDetailText('comingSoon')
|
||||
);
|
||||
});
|
||||
|
||||
it('6.6 无 window.open 时回退 setClipboardData 写入 wa.me 链接', () => {
|
||||
delete (global as { window?: unknown }).window;
|
||||
const { openLeadWhatsApp } = loadUseLeadDetail();
|
||||
|
||||
const ok = openLeadWhatsApp('0086 138-0000-0000');
|
||||
expect(ok).toBe(true);
|
||||
expect(setClipboardDataMock).toHaveBeenCalledTimes(1);
|
||||
expect(setClipboardDataMock.mock.calls[0][0].data).toBe(
|
||||
'https://wa.me/8613800000000'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('OmniCard AI 名片主潜客详情页契约 (leads-detail.uvue)', () => {
|
||||
@@ -485,9 +721,14 @@ describe('OmniCard AI 名片主潜客详情页契约 (leads-detail.uvue)', () =>
|
||||
expect(pageSource.includes('uploadHint')).toBe(true);
|
||||
expect(pageSource.includes('image-uploader')).toBe(true);
|
||||
expect(logicSource.includes('async function submitLeadNote')).toBe(true);
|
||||
expect(
|
||||
combined.includes('handleWhatsApp') || logicSource.includes('formatWhatsAppUrl')
|
||||
).toBe(true);
|
||||
expect(logicSource.includes('function callLeadPhone')).toBe(true);
|
||||
expect(logicSource.includes('function openLeadWhatsApp')).toBe(true);
|
||||
expect(logicSource.includes('uni.makePhoneCall')).toBe(true);
|
||||
expect(logicSource.includes('https://wa.me/')).toBe(true);
|
||||
expect(pageSource.includes('callLeadPhone')).toBe(true);
|
||||
expect(pageSource.includes('openLeadWhatsApp')).toBe(true);
|
||||
expect(pageSource.includes('handleCallPhone')).toBe(true);
|
||||
expect(pageSource.includes('handleWhatsApp')).toBe(true);
|
||||
expect(
|
||||
combined.includes('handleSaveContact') || logicSource.includes('saveContactToDevice')
|
||||
).toBe(true);
|
||||
@@ -512,6 +753,22 @@ describe('OmniCard AI 名片主潜客详情页契约 (leads-detail.uvue)', () =>
|
||||
expect(pageSource.includes('lead-cta-inner')).toBe(true);
|
||||
expect(pageSource.includes('max-width: 480px')).toBe(true);
|
||||
expect(pageSource.includes("'contactSaved'")).toBe(false);
|
||||
expect(
|
||||
pageSource.includes('code === 1000') ||
|
||||
logicSource.includes('code === 1000')
|
||||
).toBe(true);
|
||||
expect(pageSource.includes('noteSavedToast')).toBe(true);
|
||||
expect(pageSource.includes('handleSave')).toBe(true);
|
||||
const saveStart = pageSource.indexOf('async function handleSave():');
|
||||
const handleSaveBlock =
|
||||
saveStart >= 0 ? pageSource.slice(saveStart, saveStart + 720) : '';
|
||||
expect(handleSaveBlock.includes('noteSavedToast')).toBe(true);
|
||||
expect(handleSaveBlock.includes('if (ok)')).toBe(true);
|
||||
expect(handleSaveBlock.includes('submitLeadNote')).toBe(true);
|
||||
// 失败不得 toast 已保存:noteSavedToast 仅出现在 if (ok) 分支内
|
||||
expect(handleSaveBlock.indexOf('if (ok)')).toBeLessThan(
|
||||
handleSaveBlock.indexOf('noteSavedToast')
|
||||
);
|
||||
});
|
||||
it('无 emoji、无 any,模板无硬编码中文主文案', () => {
|
||||
const pageSource = fs.readFileSync(DETAIL_PAGE, 'utf8');
|
||||
|
||||
在新工单中引用
屏蔽一个用户