Discriminator in username

This commit is contained in:
Fedor Indutny 2022-10-18 10:12:02 -07:00 committed by GitHub
parent 58f0012f14
commit 00f82a6d39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 2706 additions and 892 deletions

View file

@ -12,7 +12,9 @@ import {
parseSgnlHref,
parseCaptchaHref,
parseE164FromSignalDotMeHash,
parseUsernameFromSignalDotMeHash,
parseSignalHttpsLink,
generateUsernameLink,
rewriteSignalHrefsIfNecessary,
} from '../../util/sgnlHref';
@ -373,6 +375,48 @@ describe('sgnlHref', () => {
});
});
describe('parseUsernameFromSignalDotMeHash', () => {
it('returns undefined for invalid inputs', () => {
['', ' u/+18885551234', 'z/18885551234'].forEach(hash => {
assert.isUndefined(parseUsernameFromSignalDotMeHash(hash));
});
});
it('returns the username for valid inputs', () => {
assert.strictEqual(
parseUsernameFromSignalDotMeHash('u/signal.03'),
'signal.03'
);
assert.strictEqual(
parseUsernameFromSignalDotMeHash('u/signal%2F03'),
'signal/03'
);
});
});
describe('generateUsernameLink', () => {
it('generates regular link', () => {
assert.strictEqual(
generateUsernameLink('signal.03'),
'https://signal.me/#u/signal.03'
);
});
it('generates encoded link', () => {
assert.strictEqual(
generateUsernameLink('signal/03'),
'https://signal.me/#u/signal%2F03'
);
});
it('generates short link', () => {
assert.strictEqual(
generateUsernameLink('signal/03', { short: true }),
'signal.me/#u/signal%2F03'
);
});
});
describe('parseSignalHttpsLink', () => {
it('returns a null command for invalid URLs', () => {
['', 'https', 'https://example/?foo=bar'].forEach(href => {