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
7 changes: 6 additions & 1 deletion src/lib/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ function productData(
stage: product.stage,
teamSize: product.teamSize ? Number(product.teamSize) : undefined,
fundingStatus: product.fundingStatus,
tractionMetrics: product.tractionMetric ? ({ selfReported: product.tractionMetric, verification: "unverified self-reported" } as Prisma.InputJsonObject) : undefined,
tractionMetrics:
product.tractionMetric === null
? Prisma.DbNull
: product.tractionMetric
? ({ selfReported: product.tractionMetric, verification: "unverified self-reported" } as Prisma.InputJsonObject)
: undefined,
websiteUrl: product.websiteUrl,
demoUrl: product.demoUrl,
repositoryUrl: product.repositoryUrl,
Expand Down
34 changes: 34 additions & 0 deletions tests/profile-traction-clear.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from "vitest";
import { Prisma, type PrismaClient } from "@prisma/client";
import { profileSaveSchema, saveProfile } from "@/lib/profile";

const profile = { username: "ada", visibility: "PUBLIC", messagingPermission: "EVERYONE", connectionPermission: "EVERYONE" };

async function savedTraction(tractionMetric: unknown) {
const updates: Array<Record<string, unknown>> = [];
const prisma = {
userProfile: {
findUnique: async () => ({ userId: "user-1" }),
upsert: async (args: { update: Record<string, unknown> }) => args.update,
},
product: {
updateMany: async (args: { data: Record<string, unknown> }) => (updates.push(args.data), { count: 1 }),
},
} as unknown as PrismaClient;
const input = profileSaveSchema.parse({ profile, product: { id: "product-1", name: "Engine", tractionMetric } });
await saveProfile(prisma, "user-1", input);
return updates[0]!.tractionMetrics;
}

describe("product traction metric", () => {
it("clears the stored traction when the field is emptied", async () => {
expect(await savedTraction("")).toBe(Prisma.DbNull);
expect(await savedTraction(" ")).toBe(Prisma.DbNull);
expect(await savedTraction(null)).toBe(Prisma.DbNull);
});

it("saves typed traction as unverified and leaves a missing field untouched", async () => {
expect(await savedTraction("40 paying teams")).toEqual({ selfReported: "40 paying teams", verification: "unverified self-reported" });
expect(await savedTraction(undefined)).toBeUndefined();
});
});
Loading