-
Notifications
You must be signed in to change notification settings - Fork 111
test: add comprehensive tests for socialLinksInputSchema validation #3410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adds unit tests for the socialLinksInputSchema Zod schema: - Validates array of social links with platform auto-detection - Tests explicit platform override - Tests fallback to "other" for unknown domains - Tests rejection of invalid URLs - Tests empty array handling - Tests order preservation Also adds missing platform detection tests for codepen, reddit, and stackoverflow. Closes ENG-258
|
🍹 The Update (preview) for dailydotdev/api/prod (at c296577) was successful. Resource Changes Name Type Operation
~ vpc-native-update-trending-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generate-search-invites-cron kubernetes:batch/v1:CronJob update
~ vpc-native-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-update-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-personalized-digest-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-clean-stale-user-transactions-cron kubernetes:batch/v1:CronJob update
~ vpc-native-private-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-post-analytics-clickhouse-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-tag-recommendations-cron kubernetes:batch/v1:CronJob update
~ vpc-native-user-profile-updated-sync-cron kubernetes:batch/v1:CronJob update
~ vpc-native-ws-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-temporal-deployment kubernetes:apps/v1:Deployment update
- vpc-native-api-clickhouse-migration-e68fea1e kubernetes:batch/v1:Job delete
+ vpc-native-api-clickhouse-migration-3b9f2c73 kubernetes:batch/v1:Job create
~ vpc-native-personalized-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-opportunities-cron kubernetes:batch/v1:CronJob update
~ vpc-native-sync-subscription-with-cio-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-current-streak-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-zombie-images-cron kubernetes:batch/v1:CronJob update
+ vpc-native-api-db-migration-3b9f2c73 kubernetes:batch/v1:Job create
~ vpc-native-clean-zombie-user-companies-cron kubernetes:batch/v1:CronJob update
~ vpc-native-clean-gifted-plus-cron kubernetes:batch/v1:CronJob update
~ vpc-native-daily-digest-cron kubernetes:batch/v1:CronJob update
~ vpc-native-hourly-notification-cron kubernetes:batch/v1:CronJob update
- vpc-native-api-db-migration-e68fea1e kubernetes:batch/v1:Job delete
~ vpc-native-clean-zombie-users-cron kubernetes:batch/v1:CronJob update
~ vpc-native-validate-active-users-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-tags-str-cron kubernetes:batch/v1:CronJob update
~ vpc-native-bg-deployment kubernetes:apps/v1:Deployment update
~ vpc-native-update-source-public-threshold-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-highlighted-views-cron kubernetes:batch/v1:CronJob update
~ vpc-native-update-source-tag-view-cron kubernetes:batch/v1:CronJob update
~ vpc-native-calculate-top-readers-cron kubernetes:batch/v1:CronJob update
~ vpc-native-generic-referral-reminder-cron kubernetes:batch/v1:CronJob update
~ vpc-native-check-analytics-report-cron kubernetes:batch/v1:CronJob update
~ vpc-native-post-analytics-history-day-clickhouse-cron kubernetes:batch/v1:CronJob update
|
Backfill Migration (ENG-255)Note: The backfill migration needs to be created manually due to file protection hooks. The migration should be run in batches to minimize lock time on the large Recommended Approach: Batch Processing-- Run in batches of 10,000 to minimize table locks
DO $$
DECLARE
batch_size INT := 10000;
affected_rows INT;
BEGIN
LOOP
UPDATE "user"
SET "socialLinks" = (
SELECT COALESCE(jsonb_agg(link ORDER BY priority), '[]'::jsonb)
FROM (
SELECT jsonb_build_object('platform', platform, 'url', url) as link, priority
FROM (VALUES
(1, 'github', CASE WHEN github IS NOT NULL THEN 'https://github.com/' || github END),
(2, 'linkedin', CASE WHEN linkedin IS NOT NULL THEN 'https://linkedin.com/in/' || linkedin END),
(3, 'twitter', CASE WHEN twitter IS NOT NULL THEN 'https://x.com/' || twitter END),
(4, 'youtube', CASE WHEN youtube IS NOT NULL THEN 'https://youtube.com/@' || youtube END),
(5, 'stackoverflow', CASE WHEN stackoverflow IS NOT NULL THEN 'https://stackoverflow.com/users/' || stackoverflow END),
(6, 'threads', CASE WHEN threads IS NOT NULL THEN 'https://threads.net/@' || threads END),
(7, 'bluesky', CASE WHEN bluesky IS NOT NULL THEN 'https://bsky.app/profile/' || bluesky END),
(8, 'mastodon', mastodon),
(9, 'roadmap', CASE WHEN roadmap IS NOT NULL THEN 'https://roadmap.sh/u/' || roadmap END),
(10, 'codepen', CASE WHEN codepen IS NOT NULL THEN 'https://codepen.io/' || codepen END),
(11, 'reddit', CASE WHEN reddit IS NOT NULL THEN 'https://reddit.com/user/' || reddit END),
(12, 'hashnode', hashnode),
(13, 'portfolio', portfolio)
) AS t(priority, platform, url)
WHERE url IS NOT NULL
) AS links
)
WHERE id IN (
SELECT id FROM "user"
WHERE ("socialLinks" = '[]' OR "socialLinks" IS NULL)
AND (github IS NOT NULL OR linkedin IS NOT NULL OR twitter IS NOT NULL
OR youtube IS NOT NULL OR stackoverflow IS NOT NULL OR threads IS NOT NULL
OR bluesky IS NOT NULL OR mastodon IS NOT NULL OR roadmap IS NOT NULL
OR codepen IS NOT NULL OR reddit IS NOT NULL OR hashnode IS NOT NULL
OR portfolio IS NOT NULL)
LIMIT batch_size
FOR UPDATE SKIP LOCKED
);
GET DIAGNOSTICS affected_rows = ROW_COUNT;
RAISE NOTICE 'Updated % rows', affected_rows;
EXIT WHEN affected_rows = 0;
-- Small pause between batches to reduce load
PERFORM pg_sleep(0.1);
END LOOP;
END $$;Key Optimizations
Pre-migration Count Query-- Check how many rows will be affected
SELECT COUNT(*) FROM "user"
WHERE ("socialLinks" = '[]' OR "socialLinks" IS NULL)
AND (github IS NOT NULL OR linkedin IS NOT NULL OR twitter IS NOT NULL
OR youtube IS NOT NULL OR stackoverflow IS NOT NULL OR threads IS NOT NULL
OR bluesky IS NOT NULL OR mastodon IS NOT NULL OR roadmap IS NOT NULL
OR codepen IS NOT NULL OR reddit IS NOT NULL OR hashnode IS NOT NULL
OR portfolio IS NOT NULL); |
| it('should detect reddit.com', () => { | ||
| expect(detectPlatformFromUrl('https://reddit.com/user/username')).toBe( | ||
| 'reddit', | ||
| ); | ||
| }); |
There was a problem hiding this comment.
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 auto-detect platform from URL', () => { | ||
| const input = [{ url: 'https://x.com/johndoe' }]; |
There was a problem hiding this comment.
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
Summary
Adds comprehensive backend tests for the
socialLinksInputSchemavalidation, complementing the Phase 1 backend implementation that was merged in #3404.Changes
socialLinksInputSchemavalidation including:Related Issues
Test plan
pnpm test __tests__/common/socials.ts)