fix(integration): Product ordered by variants prices (#5507)

* fix(integration): Product ordered by variants prices

* set cache to 0 to prevent issues between tests
This commit is contained in:
Adrien de Peretti
2023-10-31 16:20:55 +01:00
committed by GitHub
parent 2548ea8e5e
commit d6372246ee
2 changed files with 58 additions and 13 deletions
@@ -15,6 +15,12 @@ const {
defaultStoreProductsRelations, defaultStoreProductsRelations,
} = require("@medusajs/medusa/dist") } = require("@medusajs/medusa/dist")
const adminHeaders = {
headers: {
"x-medusa-access-token": "test_token",
},
}
jest.setTimeout(30000) jest.setTimeout(30000)
describe("/store/products", () => { describe("/store/products", () => {
@@ -30,7 +36,12 @@ describe("/store/products", () => {
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..")) const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd }) dbConnection = await initDb({
cwd,
env: {
CACHE_TTL: 0,
},
})
medusaProcess = await setupServer({ cwd }) medusaProcess = await setupServer({ cwd })
}) })
@@ -128,7 +139,7 @@ describe("/store/products", () => {
const api = useApi() const api = useApi()
await simpleProductFactory(dbConnection, { await simpleProductFactory(dbConnection, {
id: "test-product2", id: testProductId2,
status: "published", status: "published",
variants: [ variants: [
{ {
@@ -143,10 +154,29 @@ describe("/store/products", () => {
], ],
}) })
const response = await api.get( let response = await api.get(
"/store/products?order=-variants.prices.amount" "/store/products?order=-variants.prices.amount"
) )
// Update amount to unsure order, same amount will add randomness in the result with the same amounts
const productToUpdate = response.data.products.find(
(p) => p.id === testProductId
)
const priceToUpdate = productToUpdate.variants[0].prices[0]
const priceData = {
id: priceToUpdate.id,
currency_code: priceToUpdate.currency_code,
amount: 120,
}
await api.post(
`/admin/products/${testProductId}/variants/${productToUpdate.variants[0].id}`,
{ prices: [priceData] },
adminHeaders
)
response = await api.get("/store/products?order=-variants.prices.amount")
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(6) expect(response.data.products).toHaveLength(6)
@@ -161,7 +191,7 @@ describe("/store/products", () => {
) )
expect(testProduct2Index).toBe(3) // 200 expect(testProduct2Index).toBe(3) // 200
expect(testProductIndex).toBe(4) // 100 expect(testProductIndex).toBe(4) // 120
expect(testProduct1Index).toBe(5) // 100 expect(testProduct1Index).toBe(5) // 100
}) })
@@ -169,7 +199,7 @@ describe("/store/products", () => {
const api = useApi() const api = useApi()
await simpleProductFactory(dbConnection, { await simpleProductFactory(dbConnection, {
id: "test-product2", id: testProductId2,
status: "published", status: "published",
variants: [ variants: [
{ {
@@ -184,10 +214,29 @@ describe("/store/products", () => {
], ],
}) })
const response = await api.get( let response = await api.get(
"/store/products?order=variants.prices.amount" "/store/products?order=variants.prices.amount"
) )
// Update amount to unsure order, same amount will add randomness in the result with the same amounts
const productToUpdate = response.data.products.find(
(p) => p.id === testProductId1
)
const priceToUpdate = productToUpdate.variants[0].prices[0]
const priceData = {
id: priceToUpdate.id,
currency_code: priceToUpdate.currency_code,
amount: 120,
}
await api.post(
`/admin/products/${testProductId1}/variants/${productToUpdate.variants[0].id}`,
{ prices: [priceData] },
adminHeaders
)
response = await api.get("/store/products?order=variants.prices.amount")
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(6) expect(response.data.products).toHaveLength(6)
@@ -202,7 +251,7 @@ describe("/store/products", () => {
) )
expect(testProductIndex).toBe(0) // 100 expect(testProductIndex).toBe(0) // 100
expect(testProduct1Index).toBe(1) // 100 expect(testProduct1Index).toBe(1) // 120
expect(testProduct2Index).toBe(2) // 200 expect(testProduct2Index).toBe(2) // 200
}) })
@@ -971,11 +1020,7 @@ describe("/store/products", () => {
{ {
status: "published", status: "published",
}, },
{ adminHeaders
headers: {
"x-medusa-access-token": "test_token",
},
}
) )
.catch((err) => { .catch((err) => {
console.log(err) console.log(err)
+1 -1
View File
@@ -4,7 +4,7 @@ const DB_PASSWORD = process.env.DB_PASSWORD
const DB_NAME = process.env.DB_TEMP_NAME const DB_NAME = process.env.DB_TEMP_NAME
const redisUrl = process.env.REDIS_URL || "redis://localhost:6379" const redisUrl = process.env.REDIS_URL || "redis://localhost:6379"
const cacheTTL = process.env.CACHE_TTL || 15 const cacheTTL = process.env.CACHE_TTL ?? 15
const enableResponseCompression = const enableResponseCompression =
process.env.ENABLE_RESPONSE_COMPRESSION || true process.env.ENABLE_RESPONSE_COMPRESSION || true