chore(integration-tests): Flaky tests (#3126)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore: fix flaky tests
|
||||||
@@ -1915,9 +1915,10 @@ describe("/admin/products", () => {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const variantId = "test-variant"
|
||||||
const response = await api
|
const response = await api
|
||||||
.post(
|
.post(
|
||||||
"/admin/products/test-product/variants/test-variant",
|
`/admin/products/test-product/variants/${variantId}`,
|
||||||
data,
|
data,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
@@ -1927,9 +1928,12 @@ describe("/admin/products", () => {
|
|||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
expect(response.data.product.variants[0].prices.length).toEqual(2)
|
const variant = response.data.product.variants.find(
|
||||||
|
(v) => v.id === variantId
|
||||||
|
)
|
||||||
|
expect(variant.prices.length).toEqual(2)
|
||||||
|
|
||||||
expect(response.data.product.variants[0].prices).toEqual(
|
expect(variant.prices).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
amount: 8000,
|
amount: 8000,
|
||||||
@@ -1958,9 +1962,10 @@ describe("/admin/products", () => {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const variantId = "test-variant_3"
|
||||||
const response = await api
|
const response = await api
|
||||||
.post(
|
.post(
|
||||||
"/admin/products/test-product1/variants/test-variant_3",
|
`/admin/products/test-product1/variants/${variantId}`,
|
||||||
data,
|
data,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
@@ -1970,11 +1975,13 @@ describe("/admin/products", () => {
|
|||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
expect(response.data.product.variants[0].prices.length).toEqual(
|
const variant = response.data.product.variants.find(
|
||||||
data.prices.length
|
(v) => v.id === variantId
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.data.product.variants[0].prices).toEqual(
|
expect(variant.prices.length).toEqual(data.prices.length)
|
||||||
|
|
||||||
|
expect(variant.prices).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
amount: 8000,
|
amount: 8000,
|
||||||
|
|||||||
@@ -471,8 +471,18 @@ describe("/store/products", () => {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(response.data.products).toHaveLength(5)
|
const products = response.data.products
|
||||||
expect(response.data.products).toEqual(
|
|
||||||
|
expect(products).toHaveLength(5)
|
||||||
|
|
||||||
|
const testProduct = products.find((p) => p.id === testProductId)
|
||||||
|
expect(testProduct.variants).toHaveLength(3)
|
||||||
|
|
||||||
|
for (const variant of testProduct.variants) {
|
||||||
|
expect(variant.prices).toHaveLength(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(products).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: testProductId1,
|
id: testProductId1,
|
||||||
@@ -481,11 +491,11 @@ describe("/store/products", () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: testProductId,
|
id: testProductId,
|
||||||
collection_id: "test-collection",
|
collection_id: "test-collection",
|
||||||
variants: [
|
variants: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
original_price: 100,
|
original_price: 100,
|
||||||
calculated_price: 80,
|
calculated_price: 80,
|
||||||
prices: [
|
prices: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: "test-price",
|
id: "test-price",
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
@@ -496,12 +506,12 @@ describe("/store/products", () => {
|
|||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
amount: 80,
|
amount: 80,
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
original_price: 100,
|
original_price: 100,
|
||||||
calculated_price: 80,
|
calculated_price: 80,
|
||||||
prices: [
|
prices: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: "test-price1",
|
id: "test-price1",
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
@@ -512,12 +522,12 @@ describe("/store/products", () => {
|
|||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
amount: 80,
|
amount: 80,
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
original_price: 100,
|
original_price: 100,
|
||||||
calculated_price: 80,
|
calculated_price: 80,
|
||||||
prices: [
|
prices: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: "test-price2",
|
id: "test-price2",
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
@@ -528,9 +538,9 @@ describe("/store/products", () => {
|
|||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
amount: 80,
|
amount: 80,
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: testProductFilteringId2,
|
id: testProductFilteringId2,
|
||||||
|
|||||||
@@ -169,7 +169,10 @@ export class ProductRepository extends Repository<Product> {
|
|||||||
"variants.deleted_at IS NULL"
|
"variants.deleted_at IS NULL"
|
||||||
)
|
)
|
||||||
|
|
||||||
order["variants.variant_rank"] = "ASC"
|
if (!Object.keys(order).some((key) => key.startsWith("variants"))) {
|
||||||
|
// variant_rank being select false, apply the filter here directly
|
||||||
|
querybuilder.addOrderBy(`${toplevel}.variant_rank`, "ASC")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
querybuilder = querybuilder.leftJoinAndSelect(
|
querybuilder = querybuilder.leftJoinAndSelect(
|
||||||
`products.${toplevel}`,
|
`products.${toplevel}`,
|
||||||
|
|||||||
@@ -650,6 +650,9 @@ describe("ProductVariantService", () => {
|
|||||||
.mockImplementation(() => Promise.resolve())
|
.mockImplementation(() => Promise.resolve())
|
||||||
|
|
||||||
const regionService = {
|
const regionService = {
|
||||||
|
withTransaction: function () {
|
||||||
|
return this
|
||||||
|
},
|
||||||
list: jest.fn().mockImplementation((config) => {
|
list: jest.fn().mockImplementation((config) => {
|
||||||
const idOrIds = config.id
|
const idOrIds = config.id
|
||||||
|
|
||||||
|
|||||||
@@ -347,9 +347,11 @@ class ProductVariantService extends TransactionBaseService {
|
|||||||
prices
|
prices
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const regionsServiceTx = this.regionService_.withTransaction(manager)
|
||||||
|
|
||||||
for (const price of prices) {
|
for (const price of prices) {
|
||||||
if (price.region_id) {
|
if (price.region_id) {
|
||||||
const region = await this.regionService_.retrieve(price.region_id)
|
const region = await regionsServiceTx.retrieve(price.region_id)
|
||||||
|
|
||||||
await this.setRegionPrice(variantId, {
|
await this.setRegionPrice(variantId, {
|
||||||
currency_code: region.currency_code,
|
currency_code: region.currency_code,
|
||||||
|
|||||||
Reference in New Issue
Block a user