Skip to content

Commit 9ac12cf

Browse files
Jeremias Santosclaude
authored andcommitted
test(pav-6): improve branch coverage to meet 80% threshold
- Add unit test for email validation in handleCallback (oauth_email_required) - Add LinkedIn provider to auth.service mock registry - Add logInfo test without ctx to cover nullish coalescing branch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6179e3f commit 9ac12cf

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

backend/tests/unit/modules/auth/auth.service.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ vi.mock("../../../../src/modules/auth/providers/auth.provider", () => ({
1616
getAuthUrl: mocks.getAuthUrl,
1717
exchangeCode: mocks.exchangeCode,
1818
},
19+
linkedin: {
20+
getAuthUrl: mocks.getAuthUrl,
21+
exchangeCode: mocks.exchangeCode,
22+
},
1923
},
2024
}));
2125

@@ -132,6 +136,19 @@ describe("AuthService", () => {
132136
);
133137
});
134138

139+
it("throws when profile has no email", async () => {
140+
mocks.exchangeCode.mockResolvedValueOnce({
141+
...mockProfile,
142+
email: undefined,
143+
});
144+
145+
await expect(service.handleCallback(validCallbackParams)).rejects.toThrow(
146+
"oauth_email_required",
147+
);
148+
149+
expect(mocks.findOrCreateUser).not.toHaveBeenCalled();
150+
});
151+
135152
it("calls findOrCreateUser with provider and profile", async () => {
136153
mocks.exchangeCode.mockResolvedValueOnce(mockProfile);
137154
mocks.findOrCreateUser.mockResolvedValueOnce(mockUser);

backend/tests/unit/utils/logger.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ describe("logger", () => {
6565
vi.resetModules();
6666
});
6767

68+
it("logInfo works without ctx", async () => {
69+
const spy = vi
70+
.spyOn(process.stdout, "write")
71+
.mockImplementation(() => true);
72+
73+
const { logInfo } = await import("../../../src/logger.ts");
74+
logInfo("no context");
75+
76+
const output = spy.mock.calls.map((c) => String(c[0])).join("");
77+
const parsed = JSON.parse(output);
78+
79+
expect(parsed.msg).toBe("no context");
80+
81+
spy.mockRestore();
82+
});
83+
6884
it("defaults to info level", async () => {
6985
delete process.env.LOG_LEVEL;
7086
vi.resetModules();

0 commit comments

Comments
 (0)