|
| 1 | +import { assert, expect } from "chai"; |
| 2 | +import { createClient, Deepgram, DeepgramVersionError } from "../src"; |
| 3 | +import { faker } from "@faker-js/faker"; |
| 4 | +import DeepgramClient from "../src/DeepgramClient"; |
| 5 | + |
| 6 | +const errorText = |
| 7 | + "You are attempting to use an old format for a newer SDK version. Read more here: https://dpgr.am/js-v3"; |
| 8 | + |
| 9 | +describe("legacy error handling", () => { |
| 10 | + let deepgram: DeepgramClient; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + deepgram = createClient(faker.string.alphanumeric(40), { |
| 14 | + global: { url: "https://api.mock.deepgram.com" }, |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should create the correct client object", () => { |
| 19 | + expect(deepgram).to.not.be.undefined; |
| 20 | + expect(deepgram).is.instanceOf(DeepgramClient); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should error when using a v2 client object", async () => { |
| 24 | + assert.throw( |
| 25 | + () => { |
| 26 | + new Deepgram(faker.string.alphanumeric(40)); |
| 27 | + }, |
| 28 | + DeepgramVersionError, |
| 29 | + errorText |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should error when using an old v2 callstack for transcription", async () => { |
| 34 | + assert.throw( |
| 35 | + () => { |
| 36 | + deepgram.transcription.preRecorded( |
| 37 | + { |
| 38 | + url: "https://dpgr.am/spacewalk.wav", |
| 39 | + }, |
| 40 | + { |
| 41 | + model: "nova", |
| 42 | + callback: "http://callback/endpoint", |
| 43 | + } |
| 44 | + ); |
| 45 | + }, |
| 46 | + DeepgramVersionError, |
| 47 | + errorText |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should error when using an old v2 callstack for projects", async () => { |
| 52 | + assert.throw( |
| 53 | + () => { |
| 54 | + deepgram.projects.list(); |
| 55 | + }, |
| 56 | + DeepgramVersionError, |
| 57 | + errorText |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should error when using an old v2 callstack for keys", async () => { |
| 62 | + assert.throw( |
| 63 | + () => { |
| 64 | + deepgram.keys.list("projectId"); |
| 65 | + }, |
| 66 | + DeepgramVersionError, |
| 67 | + errorText |
| 68 | + ); |
| 69 | + }); |
| 70 | + |
| 71 | + it("should error when using an old v2 callstack for members", async () => { |
| 72 | + assert.throw( |
| 73 | + () => { |
| 74 | + deepgram.members.listMembers("projectId"); |
| 75 | + }, |
| 76 | + DeepgramVersionError, |
| 77 | + errorText |
| 78 | + ); |
| 79 | + }); |
| 80 | + |
| 81 | + it("should error when using an old v2 callstack for scopes", async () => { |
| 82 | + assert.throw( |
| 83 | + () => { |
| 84 | + deepgram.scopes.get("projectId", "projectMemberId"); |
| 85 | + }, |
| 86 | + DeepgramVersionError, |
| 87 | + errorText |
| 88 | + ); |
| 89 | + }); |
| 90 | + |
| 91 | + it("should error when using an old v2 callstack for invitation", async () => { |
| 92 | + assert.throw( |
| 93 | + () => { |
| 94 | + deepgram.invitation.list("projectId"); |
| 95 | + }, |
| 96 | + DeepgramVersionError, |
| 97 | + errorText |
| 98 | + ); |
| 99 | + }); |
| 100 | + |
| 101 | + it("should error when using an old v2 callstack for usage", async () => { |
| 102 | + assert.throw( |
| 103 | + () => { |
| 104 | + deepgram.usage.listRequests("projectId", {}); |
| 105 | + }, |
| 106 | + DeepgramVersionError, |
| 107 | + errorText |
| 108 | + ); |
| 109 | + }); |
| 110 | + |
| 111 | + it("should error when using an old v2 callstack for billing", async () => { |
| 112 | + assert.throw( |
| 113 | + () => { |
| 114 | + deepgram.billing.listBalances("projectId"); |
| 115 | + }, |
| 116 | + DeepgramVersionError, |
| 117 | + errorText |
| 118 | + ); |
| 119 | + }); |
| 120 | +}); |
0 commit comments