Skip to content

Commit

Permalink
✨ [Socialite] Various improvements + bug fixes (#39)
Browse files Browse the repository at this point in the history
* ✨ [Twitter] Can now match urls without a prefix

* 📝 [Changeset] Create report
  • Loading branch information
beefchimi authored Jan 20, 2022
1 parent ab28847 commit ade6193
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-toys-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'socialitejs': patch
---

Twitter `@` prefix is now optionally matched.
17 changes: 15 additions & 2 deletions src/networks/tests/twitter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {twitter} from '../twitter';

describe('Social networks > twitter', () => {
const mockSocialite = new Socialite(allSocialiteNetworks);
const mockCommonUrl = `https://www.twitter.com/${twitter.prefix}${mockGenericUser}`;

it('returns expected `id`, `user`, and `prefix` from common url', () => {
const mockCommonUrl = `https://www.twitter.com/${mockGenericUser}`;

const {id, user, prefix} = mockSocialite.parseProfile(
mockCommonUrl,
) as SocialiteProfile;
Expand All @@ -17,8 +18,20 @@ describe('Social networks > twitter', () => {
expect(prefix).toBe(twitter.prefix);
});

it('returns expected `id`, `user`, and `prefix` from prefixed url', () => {
const mockPrefixedUrl = `https://www.twitter.com/${twitter.prefix}${mockGenericUser}`;

const {id, user, prefix} = mockSocialite.parseProfile(
mockPrefixedUrl,
) as SocialiteProfile;

expect(id).toBe(twitter.id);
expect(user).toBe(mockGenericUser);
expect(prefix).toBe(twitter.prefix);
});

it('returns expected `id`, `user`, and `prefix` from url with trailing path', () => {
const mockUncommonUrl = `${mockCommonUrl}/trail-123`;
const mockUncommonUrl = `https://www.twitter.com/${twitter.prefix}${mockGenericUser}/trail-123`;
const {id, user, prefix} = mockSocialite.parseProfile(
mockUncommonUrl,
) as SocialiteProfile;
Expand Down
1 change: 0 additions & 1 deletion src/networks/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const twitter: SocialiteNetwork = {
appUrl: `https://mobile.twitter.com/${prefix}${profileReplacement.user}`,
matcher: {
domain: /twitter/,
user: `${prefix}[^\\/]+`,
},
prefix,
};
2 changes: 1 addition & 1 deletion src/tests/fixtures/valid-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
} from '../../types';
import {getUrlWithSubstitutions} from '../../utilities';

export const mockGenericUser = '~f00+96%Hum@n_123-!';
export const mockGenericUser = '~f00+96%Hum^n_123-!';

export const mockBehanceUser: UserName = 'Uz3r_N@me!';
export const mockBehanceUrl: BasicUrl = `https://www.behance.net/${mockBehanceUser}/`;
Expand Down

0 comments on commit ade6193

Please sign in to comment.