This commit is contained in:
@@ -132,7 +132,7 @@ test('stale product data refreshes online and remains usable offline', async ()
|
||||
const refreshed = await lookupProductByBarcode(stale.barcode, { [stale.barcode]: stale });
|
||||
assert.equal(requests, 1);
|
||||
assert.equal(refreshed.product.name, 'New name');
|
||||
assert.equal(refreshed.product.price, 3.5);
|
||||
assert.equal(refreshed.product.price, undefined);
|
||||
assert.equal(refreshed.product.sustainability.originCountry, 'Frankreich');
|
||||
assert.equal(refreshed.product.sustainability.originSource, 'ingredient-origin');
|
||||
assert.ok(Date.parse(refreshed.product.fetchedAt) > Date.parse(stale.fetchedAt));
|
||||
@@ -155,6 +155,35 @@ test('stale product data refreshes online and remains usable offline', async ()
|
||||
}
|
||||
});
|
||||
|
||||
test('a recent cache entry from the old nutrition schema reloads carbohydrates', async () => {
|
||||
const cached = off({ code: '3017620422003', product_name: 'Test', nutriments: { sugars_100g: 56.3 } });
|
||||
delete cached.nutritionSchemaVersion;
|
||||
cached.manualOverrides = { nutrition: { sugarPer100g: 40 } };
|
||||
const originalFetch = globalThis.fetch;
|
||||
let requests = 0;
|
||||
try {
|
||||
globalThis.fetch = async () => {
|
||||
requests += 1;
|
||||
return { ok: true, json: async () => ({ status: 1, product: {
|
||||
code: cached.barcode, product_name: 'Test', nutriments: {
|
||||
sugars_100g: 56.3, carbohydrates_100g: 57.5
|
||||
}
|
||||
} }) };
|
||||
};
|
||||
const refreshed = await lookupProductByBarcode(cached.barcode, { [cached.barcode]: cached });
|
||||
assert.equal(requests, 1);
|
||||
assert.equal(refreshed.product.nutrition.carbohydratesPer100g, 57.5);
|
||||
assert.equal(refreshed.product.nutrition.sugarPer100g, 40);
|
||||
assert.equal(refreshed.product.nutritionSchemaVersion, 2);
|
||||
|
||||
const offline = await lookupProductByBarcode(cached.barcode, { [cached.barcode]: cached }, true);
|
||||
assert.equal(requests, 1);
|
||||
assert.equal(offline.product.cacheStale, true);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('ADEME import failure cannot replace the last good local snapshot', async () => {
|
||||
let wrote = false;
|
||||
await assert.rejects(importAgribalyse({
|
||||
|
||||
Reference in New Issue
Block a user