import { TaskCategoryService } from './task-category.service';

describe('TaskCategoryService domain writes', () => {
  const makeService = () => {
    const prisma = {
      taskCategory: {
        create: jest.fn(),
        delete: jest.fn(),
        findMany: jest.fn(),
        update: jest.fn(),
      },
    };
    return { prisma, service: new TaskCategoryService(prisma as any) };
  };

  it('creates task categories with uniqueness scoped by group and name', async () => {
    const { prisma, service } = makeService();
    prisma.taskCategory.create.mockResolvedValue({ id: 'cat-1', name: '前端开发', group: 'development' });

    await service.create({ name: '前端开发', group: 'development', code: 'frontend_development' });

    expect(prisma.taskCategory.create).toHaveBeenCalledWith({
      data: expect.objectContaining({
        name: '前端开发',
        group: 'development',
        code: 'frontend_development',
        isSystem: false,
      }),
    });
  });

  it('does not delete system categories', async () => {
    const { prisma, service } = makeService();
    prisma.taskCategory.findMany.mockResolvedValue([{ id: 'cat-system', isSystem: true }]);

    const result = await service.remove('cat-system');

    expect(result).toEqual({ deleted: false });
    expect(prisma.taskCategory.delete).not.toHaveBeenCalled();
  });
});
