Manage Global Variables
Why mock Global Variables?
How to use kvStore
kvStoreimport { kvStore } from "@hypertestco/node-sdk";
// let SHOULD_RETURN_STOCK_QUANTITY = true; // old global variable
async function updateStockQuantityConfig() {
setInterval(async () => {
const { data: { shouldReturnStockQuantity } } = await axios.get('http://host/getConfig');
// SHOULD_RETURN_STOCK_QUANTITY = shouldReturnStockQuantity;
kvStore.set('shouldReturnStockQuantity', shouldReturnStockQuantity === true);
}, 5 * 1000); // Poll every 5 seconds
}
updateStockQuantityConfig();
app.get('/getInventoryStats', (req, res) => {
const inventoryStats = db.InventoryStats.find({
select: {
// stock: SHOULD_RETURN_STOCK_QUANTITY, // source of inconsistency
stock: kvStore.get('shouldReturnStockQuantity'),
}
});
res.json({ inventoryStats });
});Last updated