Skip to content

Commit 8cc0185

Browse files
committed
chore: fix tests
1 parent f87c1af commit 8cc0185

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/routes/catalog/fetch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import StorageClient from './StorageClient.js';
1818
* @returns {Promise<Response>} - A promise that resolves to the product response.
1919
*/
2020
export default async function fetch(ctx) {
21-
const storage = StorageClient.fromContext(ctx);
2221
const { sku } = ctx.config;
22+
23+
const storage = StorageClient.fromContext(ctx);
2324
const product = await storage.fetchProduct(sku);
2425

25-
// TODO: use long ttl, add cache keys
2626
return new Response(JSON.stringify(product), {
2727
headers: { 'Content-Type': 'application/json' },
2828
});

src/routes/catalog/handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default async function handler(ctx, request) {
6060
storeCode,
6161
storeViewCode,
6262
subRoute,
63-
sku: sku.endsWith('.json') ? sku.slice(0, -5) : sku,
63+
sku: sku && sku.endsWith('.json') ? sku.slice(0, -5) : sku,
6464
});
6565

6666
const fn = handlers[subRoute]?.[method];

src/utils/media.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ export async function extractAndReplaceImages(ctx, product) {
127127
};
128128

129129
await Promise.all([
130-
processQueue([...product.images], async (image) => {
130+
processQueue([...product.images ?? []], async (image) => {
131131
const newUrl = await processImage(image.url);
132132
if (newUrl) {
133133
image.url = newUrl;
134134
}
135135
}),
136-
processQueue([...product.variants], async (variant) => {
136+
processQueue([...product.variants ?? []], async (variant) => {
137137
const newUrl = await processImage(variant.image);
138138
if (newUrl) {
139139
variant.image = newUrl;

test/routes/catalog/fetch.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('handleProductFetchRequest', () => {
4141

4242
it('should return the product response when fetchProduct succeeds', async () => {
4343
const product = { sku: 'sku1', name: 'Product 1' };
44+
ctx.config.sku = 'sku1';
4445

4546
storageStub.fetchProduct.resolves(product);
4647
const response = await handleProductFetchRequest(ctx);

0 commit comments

Comments
 (0)