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:
committed by
GitHub
parent
2548ea8e5e
commit
d6372246ee
@@ -15,6 +15,12 @@ const {
|
||||
defaultStoreProductsRelations,
|
||||
} = require("@medusajs/medusa/dist")
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/products", () => {
|
||||
@@ -30,7 +36,12 @@ describe("/store/products", () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
dbConnection = await initDb({
|
||||
cwd,
|
||||
env: {
|
||||
CACHE_TTL: 0,
|
||||
},
|
||||
})
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
})
|
||||
|
||||
@@ -128,7 +139,7 @@ describe("/store/products", () => {
|
||||
const api = useApi()
|
||||
|
||||
await simpleProductFactory(dbConnection, {
|
||||
id: "test-product2",
|
||||
id: testProductId2,
|
||||
status: "published",
|
||||
variants: [
|
||||
{
|
||||
@@ -143,10 +154,29 @@ describe("/store/products", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const response = await api.get(
|
||||
let response = await api.get(
|
||||
"/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.data.products).toHaveLength(6)
|
||||
|
||||
@@ -161,7 +191,7 @@ describe("/store/products", () => {
|
||||
)
|
||||
|
||||
expect(testProduct2Index).toBe(3) // 200
|
||||
expect(testProductIndex).toBe(4) // 100
|
||||
expect(testProductIndex).toBe(4) // 120
|
||||
expect(testProduct1Index).toBe(5) // 100
|
||||
})
|
||||
|
||||
@@ -169,7 +199,7 @@ describe("/store/products", () => {
|
||||
const api = useApi()
|
||||
|
||||
await simpleProductFactory(dbConnection, {
|
||||
id: "test-product2",
|
||||
id: testProductId2,
|
||||
status: "published",
|
||||
variants: [
|
||||
{
|
||||
@@ -184,10 +214,29 @@ describe("/store/products", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const response = await api.get(
|
||||
let response = await api.get(
|
||||
"/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.data.products).toHaveLength(6)
|
||||
|
||||
@@ -202,7 +251,7 @@ describe("/store/products", () => {
|
||||
)
|
||||
|
||||
expect(testProductIndex).toBe(0) // 100
|
||||
expect(testProduct1Index).toBe(1) // 100
|
||||
expect(testProduct1Index).toBe(1) // 120
|
||||
expect(testProduct2Index).toBe(2) // 200
|
||||
})
|
||||
|
||||
@@ -971,11 +1020,7 @@ describe("/store/products", () => {
|
||||
{
|
||||
status: "published",
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
adminHeaders
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
|
||||
@@ -4,7 +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
|
||||
const cacheTTL = process.env.CACHE_TTL ?? 15
|
||||
const enableResponseCompression =
|
||||
process.env.ENABLE_RESPONSE_COMPRESSION || true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user