feat(medusa): invalidate price selection caching within update request (#3553)

* feat: invalidate price selection caching on update

* feat: add `onVariantsPricesUpdate` to PriceSelectionStrategy

* fix: update units

* fix: import

* Create .changeset/tame-pillows-heal.md

* fix: address feedback

* refactor: make `onVariantsPricesUpdate` optional

---------

Co-authored-by: fPolic <frane@medusajs.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Frane Polić
2023-03-28 11:18:13 +02:00
committed by GitHub
parent 455c56c4b3
commit 1ce3cc5ae4
10 changed files with 53 additions and 47 deletions

View File

@@ -44,7 +44,7 @@ describe("/admin/products", () => {
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({
cwd,
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true }
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true },
})
})
@@ -1784,7 +1784,9 @@ describe("/admin/products", () => {
})
expect(response.status).toEqual(200)
const variant = response.data.product.variants.find(v => v.id === variantId)
const variant = response.data.product.variants.find(
(v) => v.id === variantId
)
expect(variant.prices.length).toEqual(1)
expect(variant.prices).toEqual(
expect.arrayContaining([

View File

@@ -4,6 +4,7 @@ const DB_PASSWORD = process.env.DB_PASSWORD
const DB_NAME = process.env.DB_TEMP_NAME
const redisUrl = process.env.REDIS_URL || "redis://localhost:6379"
const cacheTTL = process.env.CACHE_TTL || 15
module.exports = {
plugins: [],
@@ -17,11 +18,7 @@ module.exports = {
modules: {
cacheService: {
resolve: "@medusajs/cache-inmemory",
// don't set cache since this is shared between tests
// and since we have "test-product" / "test-variant" as ids
// in a bunch of tests, this could cause that incorrect data is returned
// (e.g. price selection caches calculations under `ps:${variantId}`)
options: { ttl: 0 },
options: { ttl: cacheTTL },
},
},
}