Skip to content

Commit 1d3f74e

Browse files
committed
test(inbox): parameterise updateSignalReportArtefact success cases
Collapse the two structurally-identical success-path cases into an it.each block per the project's parameterised-test preference (Greptile review). Generated-By: PostHog Code Task-Id: f961c44f-0c0b-4bff-ab85-b533bf1856ce
1 parent 72aaeb1 commit 1d3f74e

1 file changed

Lines changed: 23 additions & 50 deletions

File tree

apps/code/src/renderer/api/posthogClient.test.ts

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -405,76 +405,49 @@ describe("PostHogAPIClient", () => {
405405
return client;
406406
}
407407

408-
it("PUTs the full-replacement content and returns the parsed artefact", async () => {
408+
const OCTOCAT_REVIEWER = {
409+
github_login: "octocat",
410+
github_name: "The Octocat",
411+
relevant_commits: [],
412+
user: null,
413+
};
414+
415+
it.each([
416+
{
417+
name: "PUTs the full-replacement content and returns the parsed artefact",
418+
input: [{ github_login: "octocat" }, { user_uuid: "uuid-1" }],
419+
responseContent: [OCTOCAT_REVIEWER],
420+
},
421+
{
422+
name: "sends an empty content array when clearing reviewers",
423+
input: [],
424+
responseContent: [],
425+
},
426+
])("$name", async ({ input, responseContent }) => {
409427
const fetch = vi.fn().mockResolvedValue({
410428
ok: true,
411429
json: async () => ({
412430
id: "art-1",
413431
type: "suggested_reviewers",
414432
created_at: "2024-01-01T00:00:00Z",
415-
content: [
416-
{
417-
github_login: "octocat",
418-
github_name: "The Octocat",
419-
relevant_commits: [],
420-
user: null,
421-
},
422-
],
433+
content: responseContent,
423434
}),
424435
});
425436
const client = makeClient(fetch);
426437

427438
const result = await client.updateSignalReportArtefact(
428439
"report-1",
429440
"art-1",
430-
[{ github_login: "octocat" }, { user_uuid: "uuid-1" }],
441+
input,
431442
);
432443

433444
expect(result.type).toBe("suggested_reviewers");
434-
expect(result.content).toEqual([
435-
{
436-
github_login: "octocat",
437-
github_name: "The Octocat",
438-
relevant_commits: [],
439-
user: null,
440-
},
441-
]);
445+
expect(result.content).toEqual(responseContent);
442446
expect(fetch).toHaveBeenCalledWith(
443447
expect.objectContaining({
444448
method: "put",
445449
path: ARTEFACT_PATH,
446-
overrides: {
447-
body: JSON.stringify({
448-
content: [{ github_login: "octocat" }, { user_uuid: "uuid-1" }],
449-
}),
450-
},
451-
}),
452-
);
453-
});
454-
455-
it("sends an empty content array when clearing reviewers", async () => {
456-
const fetch = vi.fn().mockResolvedValue({
457-
ok: true,
458-
json: async () => ({
459-
id: "art-1",
460-
type: "suggested_reviewers",
461-
created_at: "2024-01-01T00:00:00Z",
462-
content: [],
463-
}),
464-
});
465-
const client = makeClient(fetch);
466-
467-
const result = await client.updateSignalReportArtefact(
468-
"report-1",
469-
"art-1",
470-
[],
471-
);
472-
473-
expect(result.content).toEqual([]);
474-
expect(fetch).toHaveBeenCalledWith(
475-
expect.objectContaining({
476-
method: "put",
477-
overrides: { body: JSON.stringify({ content: [] }) },
450+
overrides: { body: JSON.stringify({ content: input }) },
478451
}),
479452
);
480453
});

0 commit comments

Comments
 (0)