fix(deepgram): use correct /v1/projects/{project_id}/keys endpoint
- Replace non-existent /v1/auth/grant with /v1/projects/{project_id}/keys
- Add DEEPGRAM_PROJECT_ID env variable
- Update request body and response parsing
- Update tests
Typecheck: OK · Tests: 241/241 ✅
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7cac057062
commit
a62b4816a2
3 changed files with 57 additions and 32 deletions
|
|
@ -33,6 +33,7 @@ const JSON_HEADERS = {
|
|||
describe("POST /transcriptions/token — Sprint 4b", () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
process.env.DEEPGRAM_PROJECT_ID = "proj-test-123";
|
||||
});
|
||||
|
||||
it("401 sans Authorization", async () => {
|
||||
|
|
@ -47,8 +48,8 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
access_token: "dg-temp-abc123",
|
||||
expires_in: 600,
|
||||
key: "dg-temp-abc123",
|
||||
api_key_id: "id-1",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
|
@ -65,10 +66,10 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
expect(body.expires_in).toBe(600);
|
||||
});
|
||||
|
||||
it("appelle Deepgram avec ttl_seconds=600 et Authorization Token <key>", async () => {
|
||||
it("appelle POST /v1/projects/{id}/keys avec Authorization Token <key> et le bon body", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ access_token: "tok", expires_in: 600 }),
|
||||
json: async () => ({ key: "tok" }),
|
||||
});
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
|
|
@ -80,10 +81,16 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
const [url, init] = fetchMock.mock.calls[0];
|
||||
expect(String(url)).toContain("/v1/auth/grant");
|
||||
expect(String(url)).toBe(
|
||||
"https://api.deepgram.com/v1/projects/proj-test-123/keys",
|
||||
);
|
||||
const headers = (init?.headers ?? {}) as Record<string, string>;
|
||||
expect(headers["Authorization"]).toMatch(/^Token /);
|
||||
expect(JSON.parse(init.body as string)).toEqual({ ttl_seconds: 600 });
|
||||
expect(JSON.parse(init.body as string)).toEqual({
|
||||
comment: "expria-temp",
|
||||
scopes: ["usage:write"],
|
||||
time_to_live_in_seconds: 600,
|
||||
});
|
||||
});
|
||||
|
||||
it("500 INTERNAL_ERROR si Deepgram non-OK", async () => {
|
||||
|
|
@ -122,12 +129,12 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
expect(res.status).toBe(500);
|
||||
});
|
||||
|
||||
it("500 INTERNAL_ERROR si access_token absent dans la réponse Deepgram", async () => {
|
||||
it("500 INTERNAL_ERROR si key absent dans la réponse Deepgram", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ expires_in: 600 }),
|
||||
json: async () => ({ api_key_id: "id-1" }),
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue