19 lines
1.2 KiB
TypeScript
19 lines
1.2 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { formatProfileName, profileNameError } from '../src/shared/profile-name.js';
|
|
|
|
test('name tags distinguish duplicate nicknames and keep all digits beyond four places', () => {
|
|
assert.equal(formatProfileName({ displayName: '손오공', nameTag: 1 }), '손오공#0001');
|
|
assert.equal(formatProfileName({ displayName: '손오공', nameTag: 2 }), '손오공#0002');
|
|
assert.equal(formatProfileName({ displayName: '손오공', nameTag: 10000 }), '손오공#10000');
|
|
assert.equal(profileNameError('손오공#0001'), 'INVALID_PROFILE_NAME');
|
|
});
|
|
|
|
test('nickname validation accepts ordinary names and rejects profanity and separated variants', () => {
|
|
for (const name of ['손오공', '무도가', '구름-1234', 'ClassMaster', '별빛 전사']) assert.equal(profileNameError(name), undefined, name);
|
|
for (const name of ['시발', '씨 발', '씨-발', 'ㅅㅂ', '병_신', 'FUCK', 'fuck', '씨\u200b발', '시1발']) {
|
|
assert.equal(profileNameError(name), 'PROFILE_NAME_PROFANITY', name);
|
|
}
|
|
for (const name of ['', '가', '가'.repeat(17), '<img>', null, undefined, {}]) assert.equal(profileNameError(name), 'INVALID_PROFILE_NAME');
|
|
});
|