forked from davedumto/LancePay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprisma_test.js
More file actions
53 lines (44 loc) · 1.73 KB
/
prisma_test.js
File metadata and controls
53 lines (44 loc) · 1.73 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
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
async function test() {
console.log('--- Testing LancePay API Logic ---')
try {
// 1. Check Schema Fix
const user = await prisma.user.findFirst({
include: { tags: true, auditEvents: true }
})
console.log('✅ Schema Fix: User model now includes tags relation.')
// 2. Mocking Auth & Logic Verification (Unit style)
// Since I can't easily run the Next.js server and provide a real Auth token in this environment,
// I will verify the Prisma queries and logic directly.
if (user) {
console.log(`Testing with User ID: ${user.id}`)
// Test Tags logic
const tags = await prisma.tag.findMany({
where: { userId: user.id },
include: { _count: { select: { invoiceTags: true } } }
})
console.log(`✅ Tags Fetch: Found ${tags.length} tags for user.`)
// Test Audit Log logic
const events = await prisma.auditEvent.findMany({
where: { actorId: user.id },
take: 5
})
console.log(`✅ Audit Log Fetch: Found ${events.length} recent events.`)
// Test Invoice Duplication logic
const invoice = await prisma.invoice.findFirst({ where: { userId: user.id } })
if (invoice) {
console.log(`✅ Found sample invoice: ${invoice.invoiceNumber}`)
// Verification of duplication fields (not actually creating in DB to avoid side effects if not desired,
// but the query construction was reviewed).
}
} else {
console.log('⚠️ No users found in database to perform full logic test.')
}
} catch (error) {
console.error('❌ Test failed:', error)
} finally {
await prisma.$disconnect()
}
}
test()