-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp-test-setup.js
More file actions
65 lines (52 loc) · 2.21 KB
/
Copy pathtmp-test-setup.js
File metadata and controls
65 lines (52 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function preparePerfectTest() {
console.log("Setting up the perfect 'Time Travel' test scenario for you...");
// 1. Find a real Lead
const lead = await prisma.lead.findFirst({
orderBy: { createdAt: 'desc' }
});
if (!lead) {
console.log("No leads found in database!");
process.exit(1);
}
console.log(`✅ Using Lead: ${lead.name} (${lead.id})`);
// 2. Create an executed Recurring Contract for this Lead
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
const signedLastMonth = new Date();
signedLastMonth.setDate(signedLastMonth.getDate() - 31);
const contract = await prisma.contract.create({
data: {
title: `Automated Test Lien Release - ${Date.now()}`,
body: `<p>This is a test recurring contract executed 30 days ago.</p> <div class="doc-block-btn sig-block" data-id="sig-0">[ Click to Sign ]</div>`,
status: "Signed",
leadId: lead.id,
companyId: lead.companyId,
sentAt: signedLastMonth,
approvedBy: "Justin (Test Client)",
approvedAt: signedLastMonth,
recurringDays: 30,
nextDueDate: yesterday
}
});
// Seed the first signature record
await prisma.contractSigningRecord.create({
data: {
contractId: contract.id,
signedBy: "Justin (Test Client)",
signedAt: signedLastMonth,
periodStart: signedLastMonth,
periodEnd: yesterday,
signatureUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" // tiny pixel
}
});
console.log(`✅ Forged a 30-day-old signed contract (ID: ${contract.id})`);
console.log(`\n=========================================`);
console.log(`TEST READY!`);
console.log(`Lead Name: ${lead.name}`);
console.log(`Lead URL: /leads/${lead.id}`);
console.log(`=========================================\n`);
await prisma.$disconnect();
}
preparePerfectTest().catch(console.error);