import { describe, it, expect, beforeEach } from "vitest";
import { InMemoryContactListsRepository } from "../repositories/in-memory-contact-lists-repository";
import { GetAllContactListsUseCase } from "./get-all-contact-lists-use-case";

let contactListsRepository: InMemoryContactListsRepository;
let sut: GetAllContactListsUseCase;

describe("Get All Contact Lists Use Case", () => {
  beforeEach(() => {
    contactListsRepository = new InMemoryContactListsRepository();
    sut = new GetAllContactListsUseCase(contactListsRepository);
  });

  it("should return only the lists belonging to the given user", async () => {
    await contactListsRepository.create({ name: "Lista A", userId: "user-1" });
    await contactListsRepository.create({ name: "Lista B", userId: "user-2" });

    const { lists } = await sut.execute({ userId: "user-1" });

    expect(lists).toHaveLength(1);
    expect(lists[0].name).toBe("Lista A");
    expect(lists[0]._count.memberships).toBe(0);
  });
});
