feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -66,6 +66,7 @@ describe('OmniCard AI 用户端无摩擦互换名片业务逻辑测试 (useExcha
|
||||
name: 'Tariq Mansour',
|
||||
status: 'new',
|
||||
intentScore: 20,
|
||||
persisted: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -104,6 +105,14 @@ describe('OmniCard AI 用户端无摩擦互换名片业务逻辑测试 (useExcha
|
||||
delete (global as { uni?: Record<string, unknown> }).uni;
|
||||
});
|
||||
|
||||
const SUCCESS_TOAST_RE = /已提交|已完成|已互换|已保存|交换成功|提交成功|Card Exchanged/i;
|
||||
|
||||
function assertNoSuccessToast(): void {
|
||||
for (const toast of toastCalls) {
|
||||
expect(SUCCESS_TOAST_RE.test(toast.title)).toBe(false);
|
||||
}
|
||||
}
|
||||
|
||||
function loadUseExchange() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
return require('../../../mpuniapp/pages/portal/useExchange.uts') as {
|
||||
@@ -139,16 +148,18 @@ describe('OmniCard AI 用户端无摩擦互换名片业务逻辑测试 (useExcha
|
||||
canSubmit: boolean;
|
||||
errorMessage: string;
|
||||
}) => Promise<unknown>;
|
||||
isExchangeSubmitSuccess: (lead: unknown) => boolean;
|
||||
};
|
||||
}
|
||||
|
||||
describe('1. 表单校验不触发 submitLead', () => {
|
||||
it('1.1 缺少姓名时不调用 submitLead', async () => {
|
||||
describe('1. 表单校验不触发 submitLead,且不得报成功', () => {
|
||||
it('1.1 缺少姓名时不调用 submitLead,不弹出已互换/已保存', async () => {
|
||||
const { createExchangeState, applyExchangeOptions, submitExchange } =
|
||||
loadUseExchange();
|
||||
|
||||
const state = createExchangeState();
|
||||
applyExchangeOptions(state, { cardId: 'card-101' });
|
||||
toastCalls = [];
|
||||
state.form.phone = '+971501234567';
|
||||
|
||||
const result = await submitExchange(state);
|
||||
@@ -158,14 +169,16 @@ describe('OmniCard AI 用户端无摩擦互换名片业务逻辑测试 (useExcha
|
||||
expect(lastRequestOptions).toBeNull();
|
||||
expect(toastCalls.length).toBeGreaterThan(0);
|
||||
expect(toastCalls[0].title).toContain('姓名');
|
||||
assertNoSuccessToast();
|
||||
});
|
||||
|
||||
it('1.2 缺少 WhatsApp 与邮箱时不调用 submitLead', async () => {
|
||||
it('1.2 缺少 WhatsApp 与邮箱时不调用 submitLead,不报成功', async () => {
|
||||
const { createExchangeState, applyExchangeOptions, submitExchange } =
|
||||
loadUseExchange();
|
||||
|
||||
const state = createExchangeState();
|
||||
applyExchangeOptions(state, { cardId: 'card-101' });
|
||||
toastCalls = [];
|
||||
state.form.name = 'Tariq Mansour';
|
||||
|
||||
const result = await submitExchange(state);
|
||||
@@ -174,16 +187,34 @@ describe('OmniCard AI 用户端无摩擦互换名片业务逻辑测试 (useExcha
|
||||
expect(requestCallCount).toBe(0);
|
||||
expect(lastRequestOptions).toBeNull();
|
||||
expect(toastCalls.length).toBeGreaterThan(0);
|
||||
assertNoSuccessToast();
|
||||
});
|
||||
});
|
||||
|
||||
describe('2. 合法数据调用 submitLead 并携带 cardId', () => {
|
||||
it('2.1 姓名 + WhatsApp 会提交并带上 cardId', async () => {
|
||||
it('1.3 姓名与联系方式全空时提交不得报成功', async () => {
|
||||
const { createExchangeState, applyExchangeOptions, submitExchange } =
|
||||
loadUseExchange();
|
||||
|
||||
const state = createExchangeState();
|
||||
applyExchangeOptions(state, { cardId: 'card-101' });
|
||||
toastCalls = [];
|
||||
|
||||
const result = await submitExchange(state);
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(requestCallCount).toBe(0);
|
||||
expect(state.form.name).toBe('');
|
||||
assertNoSuccessToast();
|
||||
});
|
||||
});
|
||||
|
||||
describe('2. 合法数据调用 submitLead 并携带 cardId', () => {
|
||||
it('2.1 姓名 + WhatsApp 会提交并带上 cardId,仅明确成功才提示', async () => {
|
||||
const { createExchangeState, applyExchangeOptions, submitExchange } =
|
||||
loadUseExchange();
|
||||
|
||||
const state = createExchangeState();
|
||||
applyExchangeOptions(state, { cardId: 'card-101' });
|
||||
toastCalls = [];
|
||||
state.form.name = 'Tariq Mansour';
|
||||
state.form.company = 'Dubai Energy Holding';
|
||||
state.form.phone = '+971501234567';
|
||||
@@ -202,6 +233,7 @@ describe('OmniCard AI 用户端无摩擦互换名片业务逻辑测试 (useExcha
|
||||
expect(state.form.name).toBe('');
|
||||
expect(state.form.phone).toBe('');
|
||||
expect(state.form.notes).toBe('');
|
||||
expect(toastCalls.some(t => SUCCESS_TOAST_RE.test(t.title))).toBe(true);
|
||||
});
|
||||
|
||||
it('2.2 姓名 + 邮箱同样会调用 submitLead', async () => {
|
||||
@@ -221,6 +253,92 @@ describe('OmniCard AI 用户端无摩擦互换名片业务逻辑测试 (useExcha
|
||||
});
|
||||
});
|
||||
|
||||
describe('4. 接口失败或未落库不得报互换完成', () => {
|
||||
it('4.1 接口失败时返回 null,不弹出已互换/已保存', async () => {
|
||||
const { createExchangeState, applyExchangeOptions, submitExchange } =
|
||||
loadUseExchange();
|
||||
|
||||
mockRequestResponse = {
|
||||
statusCode: 200,
|
||||
data: { code: 1001, message: '交换名片失败' },
|
||||
};
|
||||
|
||||
const state = createExchangeState();
|
||||
applyExchangeOptions(state, { cardId: 'card-101' });
|
||||
toastCalls = [];
|
||||
state.form.name = 'Tariq Mansour';
|
||||
state.form.phone = '+971501234567';
|
||||
|
||||
const result = await submitExchange(state);
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(requestCallCount).toBe(1);
|
||||
expect(state.form.name).toBe('Tariq Mansour');
|
||||
assertNoSuccessToast();
|
||||
});
|
||||
|
||||
it('4.2 persisted 不为 true 时不得报成功、不得清空表单', async () => {
|
||||
const {
|
||||
createExchangeState,
|
||||
applyExchangeOptions,
|
||||
submitExchange,
|
||||
isExchangeSubmitSuccess,
|
||||
} = loadUseExchange();
|
||||
|
||||
mockRequestResponse.data = {
|
||||
code: 1000,
|
||||
message: 'success',
|
||||
data: {
|
||||
id: 'lead_mem_1',
|
||||
cardId: 'card-101',
|
||||
name: 'Tariq Mansour',
|
||||
status: 'new',
|
||||
intentScore: 20,
|
||||
persisted: false,
|
||||
},
|
||||
};
|
||||
|
||||
expect(isExchangeSubmitSuccess({ id: 'x', persisted: false })).toBe(false);
|
||||
expect(isExchangeSubmitSuccess({ id: 'x', persisted: true })).toBe(true);
|
||||
|
||||
const state = createExchangeState();
|
||||
applyExchangeOptions(state, { cardId: 'card-101' });
|
||||
toastCalls = [];
|
||||
state.form.name = 'Tariq Mansour';
|
||||
state.form.phone = '+971501234567';
|
||||
|
||||
const result = await submitExchange(state);
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(requestCallCount).toBe(1);
|
||||
expect(state.form.name).toBe('Tariq Mansour');
|
||||
expect(state.errorMessage.length).toBeGreaterThan(0);
|
||||
assertNoSuccessToast();
|
||||
});
|
||||
});
|
||||
|
||||
describe('5. 页面仅在明确成功时展示完成态', () => {
|
||||
it('5.1 exchange.uvue 用 isExchangeSubmitSuccess 判定再置 submitSuccess', () => {
|
||||
const fs = require('fs') as typeof import('fs');
|
||||
const path = require('path') as typeof import('path');
|
||||
const pagePath = path.resolve(
|
||||
__dirname,
|
||||
'../../../mpuniapp/pages/portal/exchange.uvue'
|
||||
);
|
||||
const pageSource = fs.readFileSync(pagePath, 'utf8');
|
||||
|
||||
expect(pageSource.includes('isExchangeSubmitSuccess')).toBe(true);
|
||||
expect(pageSource.includes('submitSuccess.value = true')).toBe(true);
|
||||
expect(pageSource.includes('successTitle')).toBe(true);
|
||||
|
||||
const submitFn = pageSource.indexOf('async function handleSubmit');
|
||||
expect(submitFn).toBeGreaterThan(-1);
|
||||
const submitBody = pageSource.slice(submitFn, submitFn + 600);
|
||||
expect(submitBody.includes('isExchangeSubmitSuccess')).toBe(true);
|
||||
expect(submitBody.includes('submitSuccess.value = true')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('3. onLoad 名片标识', () => {
|
||||
it('3.1 缺少 cardId 与 slug 时 toast 并禁止提交', () => {
|
||||
const { createExchangeState, applyExchangeOptions, submitExchange } =
|
||||
|
||||
在新工单中引用
屏蔽一个用户