Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion __tests__/common/socials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { detectPlatformFromUrl } from '../../src/common/schema/socials';
import {
detectPlatformFromUrl,
socialLinksInputSchema,
} from '../../src/common/schema/socials';

describe('detectPlatformFromUrl', () => {
it('should detect twitter.com', () => {
Expand Down Expand Up @@ -89,4 +92,85 @@ describe('detectPlatformFromUrl', () => {
expect(detectPlatformFromUrl('not-a-url')).toBeNull();
expect(detectPlatformFromUrl('')).toBeNull();
});

it('should detect codepen.io', () => {
expect(detectPlatformFromUrl('https://codepen.io/username')).toBe(
'codepen',
);
});

it('should detect reddit.com', () => {
expect(detectPlatformFromUrl('https://reddit.com/user/username')).toBe(
'reddit',
);
});
Comment on lines +102 to +106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think reddit is one with multiple urls iirc


it('should detect stackoverflow.com', () => {
expect(
detectPlatformFromUrl('https://stackoverflow.com/users/123/username'),
).toBe('stackoverflow');
});
});

describe('socialLinksInputSchema', () => {
it('should validate array of social links', () => {
const input = [
{ url: 'https://github.com/johndoe' },
{ url: 'https://linkedin.com/in/johndoe' },
];
const result = socialLinksInputSchema.parse(input);
expect(result).toEqual([
{ platform: 'github', url: 'https://github.com/johndoe' },
{ platform: 'linkedin', url: 'https://linkedin.com/in/johndoe' },
]);
});

it('should auto-detect platform from URL', () => {
const input = [{ url: 'https://x.com/johndoe' }];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same couyld still be twitter.com iirc

const result = socialLinksInputSchema.parse(input);
expect(result).toEqual([
{ platform: 'twitter', url: 'https://x.com/johndoe' },
]);
});

it('should use provided platform when specified', () => {
const input = [
{ url: 'https://example.com/profile', platform: 'custom-site' },
];
const result = socialLinksInputSchema.parse(input);
expect(result).toEqual([
{ platform: 'custom-site', url: 'https://example.com/profile' },
]);
});

it('should fallback to "other" for unknown domains without explicit platform', () => {
const input = [{ url: 'https://unknown-site.com/profile' }];
const result = socialLinksInputSchema.parse(input);
expect(result).toEqual([
{ platform: 'other', url: 'https://unknown-site.com/profile' },
]);
});

it('should reject invalid URLs', () => {
const input = [{ url: 'not-a-valid-url' }];
expect(() => socialLinksInputSchema.parse(input)).toThrow();
});

it('should handle empty array', () => {
const result = socialLinksInputSchema.parse([]);
expect(result).toEqual([]);
});

it('should handle multiple links preserving order', () => {
const input = [
{ url: 'https://github.com/user' },
{ url: 'https://twitter.com/user' },
{ url: 'https://linkedin.com/in/user' },
];
const result = socialLinksInputSchema.parse(input);
expect(result).toHaveLength(3);
expect(result[0].platform).toBe('github');
expect(result[1].platform).toBe('twitter');
expect(result[2].platform).toBe('linkedin');
});
});
Loading