Files
dukang/packages/domain/src/phone.test.ts
T
jacy 0f48d7abda feat(admin,store): landline contact phone and package audit UX
Allow store contactPhone as landline, show pending package audit badge, and split live vs pending packages in HQ review.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 18:45:10 +08:00

40 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
isLandlinePhone,
isMobilePhone,
isStoreContactPhone,
normalizeContactPhone,
toDialablePhone,
} from './phone';
describe('store contact phone', () => {
it('accepts mainland mobile numbers', () => {
expect(isMobilePhone('13800138000')).toBe(true);
expect(isStoreContactPhone('13800138000')).toBe(true);
expect(isStoreContactPhone(' 13800138000 ')).toBe(true);
});
it('accepts landlines with or without hyphens and optional extension', () => {
expect(isLandlinePhone('0379-8888888')).toBe(true);
expect(isLandlinePhone('010-12345678')).toBe(true);
expect(isLandlinePhone('03798888888')).toBe(true);
expect(isLandlinePhone('01012345678')).toBe(true);
expect(isLandlinePhone('0379-8888888-12')).toBe(true);
expect(isStoreContactPhone('0379-8888 888')).toBe(true);
});
it('rejects login-style invalid and incomplete numbers', () => {
expect(isStoreContactPhone('')).toBe(false);
expect(isStoreContactPhone('12345678')).toBe(false);
expect(isStoreContactPhone('12345678901')).toBe(false);
expect(isStoreContactPhone('400-123-4567')).toBe(false);
expect(isMobilePhone('0379-8888888')).toBe(false);
});
it('normalizes spaces and strips dial punctuation', () => {
expect(normalizeContactPhone(' 0379-8888 888 ')).toBe('0379-8888888');
expect(toDialablePhone('0379-8888888')).toBe('03798888888');
expect(toDialablePhone('010 1234 5678')).toBe('01012345678');
});
});