import { describe, expect, it } from "vitest";
import {
  AuthenticationError,
  UnauthenticatedError,
  UnauthorizedError,
  TooManyRequestsError,
} from "./auth";
import { InputParseError } from "./common";

describe("AuthenticationError", () => {
  it("is an instance of Error with the given message", () => {
    const err = new AuthenticationError("bad credentials");
    expect(err).toBeInstanceOf(Error);
    expect(err.message).toBe("bad credentials");
  });
});

describe("UnauthenticatedError", () => {
  it("is an instance of Error with the given message", () => {
    const err = new UnauthenticatedError("not logged in");
    expect(err).toBeInstanceOf(Error);
    expect(err.message).toBe("not logged in");
  });
});

describe("UnauthorizedError", () => {
  it("is an instance of Error with the given message", () => {
    const err = new UnauthorizedError("forbidden");
    expect(err).toBeInstanceOf(Error);
    expect(err.message).toBe("forbidden");
  });
});

describe("InputParseError", () => {
  it("is an instance of Error with the given message", () => {
    const err = new InputParseError("invalid input");
    expect(err).toBeInstanceOf(Error);
    expect(err.message).toBe("invalid input");
  });
});

describe("TooManyRequestsError", () => {
  it("is an instance of Error with the given message", () => {
    const err = new TooManyRequestsError("too many attempts");
    expect(err).toBeInstanceOf(Error);
    expect(err.message).toBe("too many attempts");
    expect(err.name).toBe("TooManyRequestsError");
  });
});
