|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import type { PgBeamClientOptions } from "./index"; |
| 3 | +import { ApiError, extractMessage, PgBeamClient } from "./index"; |
| 4 | + |
| 5 | +describe("SDK index re-exports", () => { |
| 6 | + it("exports PgBeamClient class", () => { |
| 7 | + expect(PgBeamClient).toBeDefined(); |
| 8 | + expect(typeof PgBeamClient).toBe("function"); |
| 9 | + }); |
| 10 | + |
| 11 | + it("exports ApiError class", () => { |
| 12 | + expect(ApiError).toBeDefined(); |
| 13 | + expect(typeof ApiError).toBe("function"); |
| 14 | + }); |
| 15 | + |
| 16 | + it("exports extractMessage function", () => { |
| 17 | + expect(extractMessage).toBeDefined(); |
| 18 | + expect(typeof extractMessage).toBe("function"); |
| 19 | + }); |
| 20 | + |
| 21 | + it("PgBeamClient can be instantiated", () => { |
| 22 | + const client = new PgBeamClient({ |
| 23 | + token: "test-token", |
| 24 | + baseUrl: "https://api.example.com", |
| 25 | + }); |
| 26 | + expect(client).toBeInstanceOf(PgBeamClient); |
| 27 | + }); |
| 28 | + |
| 29 | + it("ApiError can be instantiated and has expected properties", () => { |
| 30 | + const error = new ApiError(404, "Not Found", { message: "not found" }); |
| 31 | + expect(error).toBeInstanceOf(ApiError); |
| 32 | + expect(error.status).toBe(404); |
| 33 | + expect(error.statusText).toBe("Not Found"); |
| 34 | + expect(error.body).toEqual({ message: "not found" }); |
| 35 | + }); |
| 36 | + |
| 37 | + it("extractMessage extracts message from error body", () => { |
| 38 | + const error = new ApiError(400, "Bad Request", { |
| 39 | + message: "invalid input", |
| 40 | + }); |
| 41 | + const msg = extractMessage(error); |
| 42 | + expect(msg).toBe("invalid input"); |
| 43 | + }); |
| 44 | + |
| 45 | + it("extractMessage handles error without body", () => { |
| 46 | + const error = new ApiError(500, "Internal Server Error", undefined); |
| 47 | + const msg = extractMessage(error); |
| 48 | + expect(typeof msg).toBe("string"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("type exports are importable (compile-time check)", () => { |
| 52 | + // These are type-only exports — this test verifies the module |
| 53 | + // can be imported without errors at runtime. |
| 54 | + const opts: PgBeamClientOptions = { |
| 55 | + token: "tok", |
| 56 | + baseUrl: "https://api.example.com", |
| 57 | + }; |
| 58 | + expect(opts.token).toBe("tok"); |
| 59 | + }); |
| 60 | +}); |
0 commit comments