Skip to content

Commit 04496bf

Browse files
committed
up
1 parent 057ee61 commit 04496bf

2 files changed

Lines changed: 48 additions & 26 deletions

File tree

src/services/audit-service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export async function createAuditLog(options: CreateAuditLogOptions) {
9696
const storeId = options.storeId ?? context?.storeId;
9797
const userId = options.userId ?? context?.userId;
9898

99-
// Build changes JSON
100-
const changes = options.changes ? JSON.stringify(options.changes) : null;
99+
// Build changes JSON - use undefined instead of null for Prisma Json type
100+
const changes = options.changes ? JSON.stringify(options.changes) : undefined;
101101

102102
return db.auditLog.create({
103103
data: {
@@ -106,7 +106,7 @@ export async function createAuditLog(options: CreateAuditLogOptions) {
106106
entityId: options.entityId,
107107
storeId,
108108
userId,
109-
changes,
109+
...(changes !== undefined && { changes }),
110110
ipAddress: options.ipAddress,
111111
userAgent: options.userAgent,
112112
},
@@ -147,7 +147,7 @@ export async function createAuditLogBatch(entries: CreateAuditLogOptions[]) {
147147
entries.map(options => {
148148
const storeId = options.storeId ?? context?.storeId;
149149
const userId = options.userId ?? context?.userId;
150-
const changes = options.changes ? JSON.stringify(options.changes) : null;
150+
const changes = options.changes ? JSON.stringify(options.changes) : undefined;
151151

152152
return db.auditLog.create({
153153
data: {
@@ -156,7 +156,7 @@ export async function createAuditLogBatch(entries: CreateAuditLogOptions[]) {
156156
entityId: options.entityId,
157157
storeId,
158158
userId,
159-
changes,
159+
...(changes !== undefined && { changes }),
160160
ipAddress: options.ipAddress,
161161
userAgent: options.userAgent,
162162
},

tests/integration/jobs/export-job-lifecycle.test.ts

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Export Job Lifecycle (Integration)', () => {
3939
const store = await db.store.create({
4040
data: {
4141
name: 'Test Store',
42-
domain: 'test-store.example.com',
42+
slug: 'test-store',
4343
currency: 'USD',
4444
timezone: 'America/New_York',
4545
},
@@ -52,38 +52,56 @@ describe('Export Job Lifecycle (Integration)', () => {
5252
email: 'test@example.com',
5353
name: 'Test User',
5454
password: 'hashed_password',
55-
role: 'StoreAdmin',
55+
role: 'STORE_ADMIN',
5656
},
5757
});
5858
userId = user.id;
5959

6060
// Create test orders
6161
for (let i = 0; i < 5; i++) {
62+
// Create addresses for the order
63+
const shippingAddr = await db.address.create({
64+
data: {
65+
firstName: 'John',
66+
lastName: 'Doe',
67+
address1: '123 Main St',
68+
city: 'New York',
69+
state: 'NY',
70+
zip: '10001',
71+
country: 'US',
72+
storeId,
73+
},
74+
});
75+
76+
const billingAddr = await db.address.create({
77+
data: {
78+
firstName: 'John',
79+
lastName: 'Doe',
80+
address1: '123 Main St',
81+
city: 'New York',
82+
state: 'NY',
83+
zip: '10001',
84+
country: 'US',
85+
storeId,
86+
},
87+
});
88+
6289
await db.order.create({
6390
data: {
6491
storeId,
6592
userId,
6693
orderNumber: `ORD-${1000 + i}`,
6794
status: 'DELIVERED',
68-
total: 100 + i * 10,
69-
shippingAddress: JSON.stringify({
70-
firstName: 'John',
71-
lastName: 'Doe',
72-
address: '123 Main St',
73-
city: 'New York',
74-
state: 'NY',
75-
zip: '10001',
76-
country: 'US',
77-
}),
78-
billingAddress: JSON.stringify({
79-
firstName: 'John',
80-
lastName: 'Doe',
81-
address: '123 Main St',
82-
city: 'New York',
83-
state: 'NY',
84-
zip: '10001',
85-
country: 'US',
86-
}),
95+
subtotal: 100 + i * 10,
96+
tax: 0,
97+
shippingCost: 0,
98+
discount: 0,
99+
shippingAddress: {
100+
connect: { id: shippingAddr.id },
101+
},
102+
billingAddress: {
103+
connect: { id: billingAddr.id },
104+
},
87105
},
88106
});
89107
}
@@ -268,6 +286,10 @@ describe('Export Job Lifecycle (Integration)', () => {
268286
.mockRejectedValueOnce(new Error('Transient error'))
269287
.mockResolvedValueOnce({
270288
url: 'https://blob.vercel-storage.com/test-export.csv',
289+
downloadUrl: 'https://blob.vercel-storage.com/test-export.csv',
290+
pathname: 'test-export.csv',
291+
contentType: 'text/csv',
292+
contentDisposition: 'attachment; filename="test-export.csv"',
271293
});
272294

273295
const { jobId } = await enqueueOrderExport(storeId, userId, {}, 5);

0 commit comments

Comments
 (0)