import { Company } from '@core/identity/domain/entities/Company'; import { CompanyRepository } from '@core/identity/domain/repositories/CompanyRepository'; /** * In-memory implementation of ICompanyRepository for testing */ export class InMemoryCompanyRepository implements CompanyRepository { private companies: Map = new Map(); create(company: Pick): Company { // Create a new Company instance with generated ID const contactEmail = company.getContactEmail(); return Company.create({ name: company.getName(), ownerUserId: company.getOwnerUserId(), ...(contactEmail !== undefined ? { contactEmail } : {}), }); } async save(company: Company): Promise { this.companies.set(company.getId(), company); } async delete(id: string): Promise { this.companies.delete(id); } async findById(id: string): Promise { return this.companies.get(id) || null; } async findByOwnerUserId(userId: string): Promise { for (const company of this.companies.values()) { if (company.getOwnerUserId().toString() === userId) { return company; } } return null; } // Helper method for testing to get all companies getAll(): Company[] { return Array.from(this.companies.values()); } // Helper method for testing to clear all clear(): void { this.companies.clear(); } }