Files
radicle-desktop/tests/unit/patchContributions.test.ts
Rūdolfs Ošiņš 56e495ba8d Add unit tests for patch review logic and draft storage
Code review is the app's core workflow and had almost no coverage. A
mutation run checked that each test fails when the logic it covers breaks.
2026-10-01 18:20:24 +02:00

56 lines
1.3 KiB
TypeScript

import { expect, test } from "vitest";
import { patchContributions } from "@app/lib/patchContributions";
import { author, comment, review, revision } from "./support/cobs";
const alice = author("alice");
const bob = author("bob");
const revisions = [
revision({
id: "r1",
author: alice,
discussion: [
comment({ author: alice }),
comment({ author: bob }),
comment({ author: bob }),
],
reviews: [
review({
author: bob,
comments: [comment({ author: bob }), comment({ author: alice })],
}),
],
}),
revision({
id: "r2",
author: bob,
reviews: [review({ author: alice }), review({ author: bob })],
}),
];
test("counts one person's revisions, comments and reviews", () => {
expect(patchContributions(revisions, bob.did)).toEqual({
revisionCount: 1,
commentCount: 3,
reviewCount: 2,
});
});
test("counts comments in revision discussions and in reviews", () => {
expect(patchContributions(revisions, alice.did)).toEqual({
revisionCount: 1,
commentCount: 2,
reviewCount: 1,
});
});
test("counts nothing for someone who took no part", () => {
expect(patchContributions(revisions, author("carol").did)).toEqual({
revisionCount: 0,
commentCount: 0,
reviewCount: 0,
});
});