Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.
TypeScript
refactor(api): update record deletion tests and enhance agent task handling
Lewis Carhart82694a6c4a3b
diff --git a/apps/api/test/record-delete.spec.ts b/apps/api/test/record-delete.spec.tsindex 554279da..7941c22b 100644--- a/apps/api/test/record-delete.spec.ts+++ b/apps/api/test/record-delete.spec.ts@@ -18,7 +18,13 @@ const colleague = `stays@${domain}`;const userId = `user-${suffix}`;const stamp = new ActivityStampService(db);-const agent = new AgentTriggerService(db);++const agent = {+ contactCreated: async () => undefined,+ companyCreated: async () => undefined,+ companyRequested: async () => undefined,+} as unknown as AgentTriggerService;+const directory = new CompanyDirectoryService(db, agent);const log = new EnrichmentLogService(db, stamp);const queue = new AgentQueueService(db);@@ -43,15 +49,48 @@ async function matchContext() {};}+const domains = [domain, doomedDomain];+const ours = {+ OR: domains.map((host) => ({ email: { endsWith: `@${host}` } })),+};++async function parked(subject: { contactId?: string; companyId?: string }) {+ return db.agentTask.create({+ data: {+ ...subject,+ kind: "identify",+ reason: `record-delete-spec (${suffix})`,+ dueAt: new Date(Date.now() + 60 * 60 * 1000),+ },+ select: { id: true },+ });+}+async function clean() {- const domains = [domain, doomedDomain];- await db.contact.deleteMany({- where: { OR: domains.map((host) => ({ email: { endsWith: `@${host}` } })) },+ const [existingContacts, existingCompanies] = await Promise.all([+ db.contact.findMany({ where: ours, select: { id: true } }),+ db.company.findMany({+ where: { domain: { in: domains } },+ select: { id: true },+ }),+ ]);++ const contactIds = existingContacts.map((row) => row.id);+ const companyIds = existingCompanies.map((row) => row.id);++ await db.agentTask.deleteMany({+ where: {+ OR: [+ { reason: `record-delete-spec (${suffix})` },+ { contactId: { in: contactIds } },+ { companyId: { in: companyIds } },+ ],+ },});+ await db.agentEvent.deleteMany({ where: { contactId: { in: contactIds } } });+ await db.contact.deleteMany({ where: ours });await db.company.deleteMany({ where: { domain: { in: domains } } });- await db.suppressedContact.deleteMany({- where: { OR: domains.map((host) => ({ email: { endsWith: `@${host}` } })) },- });+ await db.suppressedContact.deleteMany({ where: ours });await db.user.deleteMany({ where: { id: userId } });}@@ -76,6 +115,8 @@ describe("deleting a contact", () => {});contactId = created.id;+ await parked({ contactId });+await db.agentEvent.create({data: {id: `evt-${suffix}`,@@ -169,6 +210,8 @@ describe("deleting a company", () => {select: { id: true },});+ await parked({ companyId: company.id });+expect(await companies.delete(company.id)).toEqual({id: company.id,name: "Doomed",