fix(deepgram): revert to /v1/auth/grant for temporary JWT tokens
- /v1/projects/{id}/keys creates permanent API keys, not WebSocket-compatible JWT tokens
- /v1/auth/grant requires Member-scoped API key (now configured)
- Remove DEEPGRAM_PROJECT_ID dependency
- 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
a62b4816a2
commit
14880fe94c
3 changed files with 33 additions and 56 deletions
|
|
@ -33,7 +33,6 @@ 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 () => {
|
||||
|
|
@ -48,8 +47,8 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
key: "dg-temp-abc123",
|
||||
api_key_id: "id-1",
|
||||
access_token: "dg-temp-abc123",
|
||||
expires_in: 600,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
|
@ -66,10 +65,10 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
expect(body.expires_in).toBe(600);
|
||||
});
|
||||
|
||||
it("appelle POST /v1/projects/{id}/keys avec Authorization Token <key> et le bon body", async () => {
|
||||
it("appelle POST /v1/auth/grant avec Authorization Token <key> et ttl_seconds=600", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ key: "tok" }),
|
||||
json: async () => ({ access_token: "tok" }),
|
||||
});
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
|
|
@ -81,16 +80,10 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
const [url, init] = fetchMock.mock.calls[0];
|
||||
expect(String(url)).toBe(
|
||||
"https://api.deepgram.com/v1/projects/proj-test-123/keys",
|
||||
);
|
||||
expect(String(url)).toBe("https://api.deepgram.com/v1/auth/grant");
|
||||
const headers = (init?.headers ?? {}) as Record<string, string>;
|
||||
expect(headers["Authorization"]).toMatch(/^Token /);
|
||||
expect(JSON.parse(init.body as string)).toEqual({
|
||||
comment: "expria-temp",
|
||||
scopes: ["usage:write"],
|
||||
time_to_live_in_seconds: 600,
|
||||
});
|
||||
expect(JSON.parse(init.body as string)).toEqual({ ttl_seconds: 600 });
|
||||
});
|
||||
|
||||
it("500 INTERNAL_ERROR si Deepgram non-OK", async () => {
|
||||
|
|
@ -129,12 +122,12 @@ describe("POST /transcriptions/token — Sprint 4b", () => {
|
|||
expect(res.status).toBe(500);
|
||||
});
|
||||
|
||||
it("500 INTERNAL_ERROR si key absent dans la réponse Deepgram", async () => {
|
||||
it("500 INTERNAL_ERROR si access_token absent dans la réponse Deepgram", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ api_key_id: "id-1" }),
|
||||
json: async () => ({ expires_in: 600 }),
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue