Files
CRM_Montzar/apps/api/test/person-name.test.ts
T
MahdiandCursor b9bb2ff9fa feat(contacts): keep Tahesab honorifics with person gender
Male and female names can store the title when requested, and Tahesab import and export use the same gender.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-29 18:46:10 +03:30

102 lines
4.0 KiB
TypeScript

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { applyPersonGenderTitle, splitPersonHonorific } from '@mento/shared';
describe('عنوان جنسیت در نام شخص', () => {
it('ی عربی جناب آقای را مرد می‌خواند و عنوان معیار را می‌گذارد', () => {
const named = applyPersonGenderTitle({
firstName: 'جناب آقاي آرش انتظاري',
lastName: '',
});
assert.equal(named.gender, 'male');
assert.equal(named.showGenderInName, true);
assert.equal(`${named.firstName} ${named.lastName}`, 'جناب آقای آرش انتظاری');
});
it('سرکار خانم را زن می‌خواند، با فاصله و بی‌فاصله', () => {
const spaced = applyPersonGenderTitle({
firstName: 'سرکار خانم آبيدا',
lastName: 'افرندنژاد تهران',
});
assert.equal(spaced.gender, 'female');
assert.equal(spaced.showGenderInName, true);
assert.equal(`${spaced.firstName} ${spaced.lastName}`, 'سرکار خانم آبیدا افرندنژاد تهران');
const tight = applyPersonGenderTitle({
firstName: 'سرکارخانم مریم رضایی',
lastName: '',
});
assert.equal(tight.gender, 'female');
assert.equal(`${tight.firstName} ${tight.lastName}`, 'سرکار خانم مریم رضایی');
});
it('بدون عنوان، هیچکدام می‌ماند و چیزی اضافه نمی‌کند', () => {
const shop = applyPersonGenderTitle({ firstName: 'فروشگاه', lastName: 'الماس' });
assert.equal(shop.gender, 'none');
assert.equal(shop.showGenderInName, false);
assert.equal(shop.firstName, 'فروشگاه');
assert.equal(shop.lastName, 'الماس');
});
it('تیک خاموش جنسیت را نگه می‌دارد ولی عنوان را برمی‌دارد', () => {
const hidden = applyPersonGenderTitle({
firstName: 'جناب آقای آرش',
lastName: 'انتظاری',
gender: 'male',
showGenderInName: false,
});
assert.equal(hidden.gender, 'male');
assert.equal(hidden.showGenderInName, false);
assert.equal(`${hidden.firstName} ${hidden.lastName}`, 'آرش انتظاری');
});
it('هیچکدام عنوان را برمی‌دارد حتی اگر تیک روشن باشد', () => {
const cleared = applyPersonGenderTitle({
firstName: 'جناب آقای آرش',
lastName: 'انتظاری',
gender: 'none',
showGenderInName: true,
});
assert.equal(cleared.gender, 'none');
assert.equal(cleared.showGenderInName, false);
assert.equal(`${cleared.firstName} ${cleared.lastName}`, 'آرش انتظاری');
});
it('عنوان را فقط یک بار می‌گذارد', () => {
const once = applyPersonGenderTitle({
firstName: 'آرش',
lastName: 'انتظاری',
gender: 'male',
showGenderInName: true,
});
assert.equal(`${once.firstName} ${once.lastName}`, 'جناب آقای آرش انتظاری');
const again = applyPersonGenderTitle({
firstName: once.firstName,
lastName: once.lastName,
gender: 'male',
showGenderInName: true,
});
assert.equal(`${again.firstName} ${again.lastName}`, 'جناب آقای آرش انتظاری');
});
it('ویرایش بخشی از نام، آقای را دوباره به ته نام نمی‌چسباند', () => {
const existing = applyPersonGenderTitle({
firstName: 'آرش',
lastName: 'انتظاری',
gender: 'male',
showGenderInName: true,
});
const bare = splitPersonHonorific(existing.firstName, existing.lastName);
const next = applyPersonGenderTitle({
firstName: 'محمد',
lastName: bare.lastName,
gender: 'male',
showGenderInName: true,
});
assert.equal(bare.firstName, 'آرش');
assert.equal(bare.lastName, 'انتظاری');
assert.equal(`${next.firstName} ${next.lastName}`, 'جناب آقای محمد انتظاری');
});
});