SalesSheet.ai — Code Editor
test/factories
contactFactory.ts
dealFactory.ts
emailFactory.ts
activityFactory.ts
userFactory.ts
test/helpers
scenario.ts
1// test/factories/contactFactory.ts
2import { faker } from '@faker-js/faker';
3import type { Contact } from '@/types';
4
5export function createContact(
6 overrides: Partial<Contact> = {}
7): Contact {
8 return {
9 id: faker.string.uuid(),
10 firstName: faker.person.firstName(),
11 lastName: faker.person.lastName(),
12 email: faker.internet.email(),
13 phone: faker.phone.number(),
14 company: faker.company.name(),
15 title: faker.person.jobTitle(),
16 tags: [],
17 createdAt: new Date().toISOString(),
18 ...overrides,
19 };
20}
21
22// Composable: deal factory auto-links a contact
23export function createDealWithContact() {
24 const contact = createContact();
25 const deal = createDeal({
26 contactId: contact.id,
27 value: 45_000,
28 stage: 'qualified',
29 });
30 return { contact, deal };
31}
32
33// Usage in tests:
34it('updates deal stage', async () => {
35 const { deal } = createDealWithContact();
36 const result = await updateDealStage(
37 deal.id, 'won'
38 );
39 expect(result.stage).toBe('won');
40});