Skip to content

Commit 4b14637

Browse files
committed
chore: fix tesst
1 parent 0d5dfbe commit 4b14637

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

src/catalog/storage/r2.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ export default class StorageClient {
4646
const productData = await object.json();
4747
productData.attributeMap = Object.fromEntries((productData.attributes ?? [])
4848
.map(({ name, value }) => [name, value]));
49-
productData.variants = productData.variants || [];
50-
productData.variants.forEach((variant) => {
49+
(productData.variants ?? []).forEach((variant) => {
5150
variant.attributeMap = Object.fromEntries((variant.attributes ?? [])
5251
.map(({ name, value }) => [name, value]));
5352
});

test/catalog/storage/r2.test.js

+4-29
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('StorageClient Class Tests', () => {
7474
env: {
7575
CATALOG_BUCKET: {
7676
get: sinon.stub().resolves({
77-
text: sinon.stub().resolves(JSON.stringify({ sku: 'sku1', name: 'Test Product' })),
77+
json: sinon.stub().resolves({ sku: 'sku1', name: 'Test Product' }),
7878
}),
7979
},
8080
},
@@ -86,7 +86,9 @@ describe('StorageClient Class Tests', () => {
8686

8787
assert(ctx.log.debug.calledOnceWithExactly('Fetching product from R2:', 'org/site/store/view/products/sku1.json'));
8888
assert(ctx.env.CATALOG_BUCKET.get.calledOnceWithExactly('org/site/store/view/products/sku1.json'));
89-
assert.deepStrictEqual(product, { sku: 'sku1', name: 'Test Product' });
89+
assert.deepStrictEqual(product, {
90+
sku: 'sku1', attributeMap: {}, name: 'Test Product',
91+
});
9092
});
9193

9294
it('should throw 404 error if product not found', async () => {
@@ -117,33 +119,6 @@ describe('StorageClient Class Tests', () => {
117119
assert.strictEqual(thrownError, error);
118120
});
119121

120-
it('should throw error if JSON parsing fails', async () => {
121-
const ctx = {
122-
log: { debug: sinon.stub() },
123-
env: {
124-
CATALOG_BUCKET: {
125-
get: sinon.stub().resolves({
126-
text: sinon.stub().resolves('invalid json'),
127-
}),
128-
},
129-
},
130-
};
131-
132-
const sku = 'sku1';
133-
const client = new StorageClient(ctx, config);
134-
135-
let thrownError;
136-
try {
137-
await client.fetchProduct(sku);
138-
} catch (e) {
139-
thrownError = e;
140-
}
141-
142-
assert(ctx.log.debug.calledOnceWithExactly('Fetching product from R2:', 'org/site/store/view/products/sku1.json'));
143-
assert(ctx.env.CATALOG_BUCKET.get.calledOnceWithExactly('org/site/store/view/products/sku1.json'));
144-
assert(thrownError instanceof SyntaxError);
145-
});
146-
147122
it('should propagate errors from CATALOG_BUCKET.get', async () => {
148123
const ctx = {
149124
log: { debug: sinon.stub() },

0 commit comments

Comments
 (0)