Skip to content

Commit dbe42be

Browse files
fix: resolve checkout-service and analytics-service test failures (32 tests fixed)
Co-authored-by: rezwana-karim <126201034+rezwana-karim@users.noreply.github.com>
1 parent a6cfe6b commit dbe42be

3 files changed

Lines changed: 145 additions & 105 deletions

File tree

src/services/__tests__/checkout-service.test.ts

Lines changed: 85 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,32 @@ describe('CheckoutService - validateCart', () => {
4949
{ productId: 'prod-2', quantity: 1, price: 49.99 },
5050
];
5151

52-
vi.mocked(db.product.findFirst)
53-
.mockResolvedValueOnce({
52+
vi.mocked(db.product.findMany).mockResolvedValue([
53+
{
5454
id: 'prod-1',
5555
name: 'Product 1',
5656
slug: 'product-1',
57+
sku: 'SKU-1',
5758
price: 29.99,
59+
thumbnailUrl: '/images/prod-1.jpg',
5860
inventoryQty: 10,
5961
trackInventory: true,
6062
storeId,
6163
variants: [],
62-
} as any)
63-
.mockResolvedValueOnce({
64+
} as any,
65+
{
6466
id: 'prod-2',
6567
name: 'Product 2',
6668
slug: 'product-2',
69+
sku: 'SKU-2',
6770
price: 49.99,
71+
thumbnailUrl: '/images/prod-2.jpg',
6872
inventoryQty: 5,
6973
trackInventory: true,
7074
storeId,
7175
variants: [],
72-
} as any);
76+
} as any,
77+
]);
7378

7479
const result = await validateCart(storeId, cartItems);
7580

@@ -84,7 +89,7 @@ describe('CheckoutService - validateCart', () => {
8489
{ productId: 'invalid-prod', quantity: 1, price: 29.99 },
8590
];
8691

87-
vi.mocked(db.product.findFirst).mockResolvedValue(null);
92+
vi.mocked(db.product.findMany).mockResolvedValue([]);
8893

8994
const result = await validateCart(storeId, cartItems);
9095

@@ -98,16 +103,20 @@ describe('CheckoutService - validateCart', () => {
98103
{ productId: 'prod-1', quantity: 15, price: 29.99 },
99104
];
100105

101-
vi.mocked(db.product.findFirst).mockResolvedValue({
102-
id: 'prod-1',
103-
name: 'Product 1',
104-
slug: 'product-1',
105-
price: 29.99,
106-
inventoryQty: 10,
107-
trackInventory: true,
108-
storeId,
109-
variants: [],
110-
} as any);
106+
vi.mocked(db.product.findMany).mockResolvedValue([
107+
{
108+
id: 'prod-1',
109+
name: 'Product 1',
110+
slug: 'product-1',
111+
sku: 'SKU-1',
112+
price: 29.99,
113+
thumbnailUrl: '/images/prod-1.jpg',
114+
inventoryQty: 10,
115+
trackInventory: true,
116+
storeId,
117+
variants: [],
118+
} as any,
119+
]);
111120

112121
const result = await validateCart(storeId, cartItems);
113122

@@ -120,24 +129,29 @@ describe('CheckoutService - validateCart', () => {
120129
{ productId: 'prod-1', variantId: 'var-1', quantity: 3, price: 29.99 },
121130
];
122131

123-
vi.mocked(db.product.findFirst).mockResolvedValue({
124-
id: 'prod-1',
125-
name: 'Product 1',
126-
slug: 'product-1',
127-
price: 29.99,
128-
inventoryQty: 20,
129-
trackInventory: true,
130-
storeId,
131-
variants: [
132-
{
133-
id: 'var-1',
134-
productId: 'prod-1',
135-
name: 'Size M',
136-
inventoryQty: 5, // Use inventoryQty instead of stock
137-
trackInventory: true,
138-
} as any,
139-
],
140-
} as any);
132+
vi.mocked(db.product.findMany).mockResolvedValue([
133+
{
134+
id: 'prod-1',
135+
name: 'Product 1',
136+
slug: 'product-1',
137+
sku: 'SKU-1',
138+
price: 29.99,
139+
thumbnailUrl: '/images/prod-1.jpg',
140+
inventoryQty: 20,
141+
trackInventory: true,
142+
storeId,
143+
variants: [
144+
{
145+
id: 'var-1',
146+
productId: 'prod-1',
147+
name: 'Size M',
148+
sku: 'SKU-1-M',
149+
price: 29.99,
150+
inventoryQty: 5,
151+
} as any,
152+
],
153+
} as any,
154+
]);
141155

142156
const result = await validateCart(storeId, cartItems);
143157

@@ -151,24 +165,29 @@ describe('CheckoutService - validateCart', () => {
151165
{ productId: 'prod-1', variantId: 'var-1', quantity: 10, price: 29.99 },
152166
];
153167

154-
vi.mocked(db.product.findFirst).mockResolvedValue({
155-
id: 'prod-1',
156-
name: 'Product 1',
157-
slug: 'product-1',
158-
price: 29.99,
159-
inventoryQty: 20,
160-
trackInventory: true,
161-
storeId,
162-
variants: [
163-
{
164-
id: 'var-1',
165-
productId: 'prod-1',
166-
name: 'Size M',
167-
inventoryQty: 5, // Use inventoryQty instead of stock
168-
trackInventory: true,
169-
} as any,
170-
],
171-
} as any);
168+
vi.mocked(db.product.findMany).mockResolvedValue([
169+
{
170+
id: 'prod-1',
171+
name: 'Product 1',
172+
slug: 'product-1',
173+
sku: 'SKU-1',
174+
price: 29.99,
175+
thumbnailUrl: '/images/prod-1.jpg',
176+
inventoryQty: 20,
177+
trackInventory: true,
178+
storeId,
179+
variants: [
180+
{
181+
id: 'var-1',
182+
productId: 'prod-1',
183+
name: 'Size M',
184+
sku: 'SKU-1-M',
185+
price: 29.99,
186+
inventoryQty: 5,
187+
} as any,
188+
],
189+
} as any,
190+
]);
172191

173192
const result = await validateCart(storeId, cartItems);
174193

@@ -181,16 +200,20 @@ describe('CheckoutService - validateCart', () => {
181200
{ productId: 'prod-1', quantity: 100, price: 29.99 },
182201
];
183202

184-
vi.mocked(db.product.findFirst).mockResolvedValue({
185-
id: 'prod-1',
186-
name: 'Product 1',
187-
slug: 'product-1',
188-
price: 29.99,
189-
inventoryQty: 0,
190-
trackInventory: false,
191-
storeId,
192-
variants: [],
193-
} as any);
203+
vi.mocked(db.product.findMany).mockResolvedValue([
204+
{
205+
id: 'prod-1',
206+
name: 'Product 1',
207+
slug: 'product-1',
208+
sku: 'SKU-1',
209+
price: 29.99,
210+
thumbnailUrl: '/images/prod-1.jpg',
211+
inventoryQty: 0,
212+
trackInventory: false,
213+
storeId,
214+
variants: [],
215+
} as any,
216+
]);
194217

195218
const result = await validateCart(storeId, cartItems);
196219

0 commit comments

Comments
 (0)