import { describe, expect, it, vi } from "vitest";
import { changePassword, getProfile, updateProfile, uploadAvatar } from "./profileApi";

vi.mock("@shared/api/client", () => ({
  apiClient: {
    get: vi.fn(async () => ({
      data: {
        user: { email: "u@example.com" },
        profile: { display_name: "User", avatar_url: null }
      }
    })),
    patch: vi.fn(async () => ({ data: { profile: { display_name: "User" } } })),
    post: vi.fn(async () => ({ data: { profile: { avatar_url: "/api/v1/media/files/x" } } }))
  }
}));

describe("profileApi", () => {
  it("gets profile", async () => {
    const data = await getProfile();
    expect(data.user.email).toBe("u@example.com");
  });

  it("updates profile", async () => {
    const data = await updateProfile({ display_name: "User" });
    expect(data.profile.display_name).toBe("User");
  });

  it("changes password", async () => {
    await expect(
      changePassword({ current_password: "Valid123", new_password: "NewValid1" })
    ).resolves.toBeUndefined();
  });

  it("uploads avatar", async () => {
    const file = new File(["avatar"], "avatar.png", { type: "image/png" });
    const data = await uploadAvatar(file);
    expect(data.profile.avatar_url).toBe("/api/v1/media/files/x");
  });
});
