2022-10-24 20:46:36 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
|
2024-02-14 18:18:49 +00:00
|
|
|
import * as Username from '../../util/Username';
|
2022-10-24 20:46:36 +00:00
|
|
|
|
|
|
|
describe('Username', () => {
|
|
|
|
describe('getUsernameFromSearch', () => {
|
|
|
|
const { getUsernameFromSearch } = Username;
|
|
|
|
|
|
|
|
it('matches invalid username searches', () => {
|
2024-02-14 18:18:49 +00:00
|
|
|
assert.isUndefined(getUsernameFromSearch('us'));
|
|
|
|
assert.isUndefined(getUsernameFromSearch('123'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('matches partial username searches without discriminator', () => {
|
|
|
|
assert.strictEqual(getUsernameFromSearch('use'), 'use');
|
|
|
|
assert.strictEqual(getUsernameFromSearch('use.'), 'use.');
|
2022-10-24 20:46:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('matches valid username searches', () => {
|
|
|
|
assert.strictEqual(getUsernameFromSearch('username.12'), 'username.12');
|
2023-05-24 00:07:59 +00:00
|
|
|
assert.strictEqual(getUsernameFromSearch('xyz.568'), 'xyz.568');
|
2022-10-24 20:46:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not match something that looks like a phone number', () => {
|
|
|
|
assert.isUndefined(getUsernameFromSearch('+'));
|
|
|
|
assert.isUndefined(getUsernameFromSearch('2223'));
|
|
|
|
assert.isUndefined(getUsernameFromSearch('+3'));
|
|
|
|
assert.isUndefined(getUsernameFromSearch('+234234234233'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|