import { describe, expect, it } from "vitest";

import { shouldSubmitGuestLogin } from "../hooks/use-chat-guest-login";

describe("shouldSubmitGuestLogin", () => {
  it("submits once after auth initialization reaches notLoggedIn", () => {
    expect(
      shouldSubmitGuestLogin({
        alreadyRequested: false,
        hasInitialized: true,
        isLoading: false,
        loginStatus: "notLoggedIn",
      }),
    ).toBe(true);
  });

  it("waits until auth initialization has completed", () => {
    expect(
      shouldSubmitGuestLogin({
        alreadyRequested: false,
        hasInitialized: false,
        isLoading: false,
        loginStatus: "notLoggedIn",
      }),
    ).toBe(false);
  });

  it("does not submit while auth is already loading", () => {
    expect(
      shouldSubmitGuestLogin({
        alreadyRequested: false,
        hasInitialized: true,
        isLoading: true,
        loginStatus: "notLoggedIn",
      }),
    ).toBe(false);
  });

  it("does not submit again for the same notLoggedIn window", () => {
    expect(
      shouldSubmitGuestLogin({
        alreadyRequested: true,
        hasInitialized: true,
        isLoading: false,
        loginStatus: "notLoggedIn",
      }),
    ).toBe(false);
  });

  it("does not submit when the user already has a login status", () => {
    expect(
      shouldSubmitGuestLogin({
        alreadyRequested: false,
        hasInitialized: true,
        isLoading: false,
        loginStatus: "guest",
      }),
    ).toBe(false);
  });
});
