|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { formatSendMessageError, createUnknownSendMessageError } from "./sendMessageError"; |
| 3 | + |
| 4 | +describe("formatSendMessageError", () => { |
| 5 | + test("formats api_key_not_found with authentication errorType", () => { |
| 6 | + const result = formatSendMessageError({ |
| 7 | + type: "api_key_not_found", |
| 8 | + provider: "anthropic", |
| 9 | + }); |
| 10 | + |
| 11 | + expect(result.errorType).toBe("authentication"); |
| 12 | + expect(result.message).toContain("anthropic"); |
| 13 | + expect(result.message).toContain("API key"); |
| 14 | + }); |
| 15 | + |
| 16 | + test("formats provider_not_supported", () => { |
| 17 | + const result = formatSendMessageError({ |
| 18 | + type: "provider_not_supported", |
| 19 | + provider: "unsupported-provider", |
| 20 | + }); |
| 21 | + |
| 22 | + expect(result.errorType).toBe("unknown"); |
| 23 | + expect(result.message).toContain("unsupported-provider"); |
| 24 | + expect(result.message).toContain("not supported"); |
| 25 | + }); |
| 26 | + |
| 27 | + test("formats invalid_model_string with model_not_found errorType", () => { |
| 28 | + const result = formatSendMessageError({ |
| 29 | + type: "invalid_model_string", |
| 30 | + message: "Invalid model format: foo", |
| 31 | + }); |
| 32 | + |
| 33 | + expect(result.errorType).toBe("model_not_found"); |
| 34 | + expect(result.message).toBe("Invalid model format: foo"); |
| 35 | + }); |
| 36 | + |
| 37 | + test("formats incompatible_workspace", () => { |
| 38 | + const result = formatSendMessageError({ |
| 39 | + type: "incompatible_workspace", |
| 40 | + message: "Workspace is incompatible", |
| 41 | + }); |
| 42 | + |
| 43 | + expect(result.errorType).toBe("unknown"); |
| 44 | + expect(result.message).toBe("Workspace is incompatible"); |
| 45 | + }); |
| 46 | + |
| 47 | + test("formats unknown errors", () => { |
| 48 | + const result = formatSendMessageError({ |
| 49 | + type: "unknown", |
| 50 | + raw: "Something went wrong", |
| 51 | + }); |
| 52 | + |
| 53 | + expect(result.errorType).toBe("unknown"); |
| 54 | + expect(result.message).toBe("Something went wrong"); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe("createUnknownSendMessageError", () => { |
| 59 | + test("creates unknown error with trimmed message", () => { |
| 60 | + const result = createUnknownSendMessageError(" test error "); |
| 61 | + |
| 62 | + expect(result).toEqual({ type: "unknown", raw: "test error" }); |
| 63 | + }); |
| 64 | + |
| 65 | + test("throws on empty message", () => { |
| 66 | + expect(() => createUnknownSendMessageError("")).toThrow(); |
| 67 | + expect(() => createUnknownSendMessageError(" ")).toThrow(); |
| 68 | + }); |
| 69 | +}); |
0 commit comments