Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions lib/account/__tests__/flattenAccountSocials.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, it, expect } from "vitest";
import { flattenAccountSocials } from "@/lib/account/flattenAccountSocials";

const rows = [
{
id: "account-social-1",
account_id: "acct-1",
social_id: "soc-1",
social: {
id: "soc-1",
username: "apache_207",
profile_url: "tiktok.com/@apache_207",
avatar: "a",
bio: "",
region: "",
followerCount: 10,
followingCount: 1,
updated_at: "t",
},
},
] as never;

describe("flattenAccountSocials", () => {
it("returns social_id (what scrape/sub-resources need) and drops the link-row id", () => {
const [s] = flattenAccountSocials(rows) as Array<Record<string, unknown>>;
expect(s.social_id).toBe("soc-1");
expect(s.username).toBe("apache_207");
expect(s.id).toBeUndefined(); // account_socials.id used to leak here → scrape 404s on it
});
});
3 changes: 1 addition & 2 deletions lib/account/flattenAccountSocials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AccountSocialWithSocial } from "@/lib/supabase/account_socials/sel
type AccountSocialRow = Tables<"account_socials">;
type SocialRow = Tables<"socials">;

export type AccountSocialResponse = Pick<AccountSocialRow, "id" | "social_id"> &
export type AccountSocialResponse = Pick<AccountSocialRow, "social_id"> &
Pick<SocialRow, "username" | "profile_url" | "avatar" | "bio" | "region" | "updated_at"> & {
follower_count: SocialRow["followerCount"];
following_count: SocialRow["followingCount"];
Expand All @@ -27,7 +27,6 @@ export function flattenAccountSocials(
throw new Error(`No social data found for account_social id: ${accountSocial.id}`);
}
return {
id: accountSocial.id,
social_id: accountSocial.social_id,
username: socialData.username,
profile_url: socialData.profile_url,
Expand Down
Loading