Skip to content

Commit e8f7c6a

Browse files
Jeremias Santosclaude
authored andcommitted
feat(pav-6): add getLinkedinAuthUrl to frontend auth service
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7542bd0 commit e8f7c6a

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

frontend/src/services/authService.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,19 @@ export async function getGoogleAuthUrl(): Promise<string> {
135135
throw createError(payload, "Falha ao obter URL de autenticacao Google.");
136136
}
137137

138+
return payload.url;
139+
}
140+
141+
export async function getLinkedinAuthUrl(): Promise<string> {
142+
const response = await fetch(buildUrl("/api/auth/linkedin/url"), {
143+
credentials: "include",
144+
});
145+
146+
const payload = await parseResponse(response);
147+
148+
if (!response.ok) {
149+
throw createError(payload, "Falha ao obter URL de autenticacao LinkedIn.");
150+
}
151+
138152
return payload.url;
139153
}

frontend/tests/unit/services/auth.service.test.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,48 @@ describe("authService", () => {
296296
);
297297
});
298298
});
299+
300+
describe("getLinkedinAuthUrl", () => {
301+
it("should return LinkedIn auth URL on success", async () => {
302+
fetchMock.mockResolvedValueOnce(
303+
mockResponse({
304+
jsonData: { url: "https://www.linkedin.com/oauth/v2/authorization?state=abc" },
305+
})
306+
);
307+
308+
const url = await auth.getLinkedinAuthUrl();
309+
310+
expect(url).toBe("https://www.linkedin.com/oauth/v2/authorization?state=abc");
311+
expect(fetchMock).toHaveBeenCalledWith(
312+
expect.stringContaining("/api/auth/linkedin/url"),
313+
expect.objectContaining({ credentials: "include" })
314+
);
315+
});
316+
317+
it("should throw error on failure with message", async () => {
318+
fetchMock.mockResolvedValueOnce(
319+
mockResponse({
320+
ok: false,
321+
status: 500,
322+
jsonData: { message: "Provider unavailable" },
323+
})
324+
);
325+
326+
await expect(auth.getLinkedinAuthUrl()).rejects.toThrow("Provider unavailable");
327+
});
328+
329+
it("should throw error on failure without message", async () => {
330+
fetchMock.mockResolvedValueOnce(
331+
mockResponse({
332+
ok: false,
333+
status: 500,
334+
jsonData: {},
335+
})
336+
);
337+
338+
await expect(auth.getLinkedinAuthUrl()).rejects.toThrow(
339+
"Falha ao obter URL de autenticacao LinkedIn."
340+
);
341+
});
342+
});
299343
});

0 commit comments

Comments
 (0)