fix(medusa): fields params usage in the storefront endpoints (#2980)
This commit is contained in:
@@ -155,6 +155,58 @@ describe("/store/carts", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("lookup order response contains only fields defined with `fields` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get(
|
||||
"/store/orders?display_id=111&email=test@email.com&fields=status,object"
|
||||
)
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(Object.keys(response.data.order)).toEqual([
|
||||
// fields
|
||||
"status",
|
||||
"object",
|
||||
// relations
|
||||
"shipping_address",
|
||||
"fulfillments",
|
||||
"items",
|
||||
"shipping_methods",
|
||||
"discounts",
|
||||
"customer",
|
||||
"payments",
|
||||
"region",
|
||||
])
|
||||
})
|
||||
|
||||
it("get order response contains only fields defined with `fields` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/orders/order_test?fields=status,object")
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(Object.keys(response.data.order)).toEqual([
|
||||
// fields
|
||||
"status",
|
||||
"object",
|
||||
// relations
|
||||
"shipping_address",
|
||||
"fulfillments",
|
||||
"items",
|
||||
"shipping_methods",
|
||||
"discounts",
|
||||
"customer",
|
||||
"payments",
|
||||
"region",
|
||||
])
|
||||
})
|
||||
|
||||
it("looks up order", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const {
|
||||
simpleProductFactory,
|
||||
simpleProductCategoryFactory
|
||||
simpleProductCategoryFactory,
|
||||
} = require("../../factories")
|
||||
|
||||
const productSeeder = require("../../helpers/store-product-seeder")
|
||||
@@ -194,6 +194,26 @@ describe("/store/products", () => {
|
||||
expect(testProduct2Index).toBe(2) // 200
|
||||
})
|
||||
|
||||
it("products contain only fields defined with `fields` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/store/products?fields=handle")
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(Object.keys(response.data.products[0])).toEqual([
|
||||
// fields
|
||||
"handle",
|
||||
// relations
|
||||
"variants",
|
||||
"options",
|
||||
"images",
|
||||
"tags",
|
||||
"collection",
|
||||
"type",
|
||||
])
|
||||
})
|
||||
|
||||
it("returns a list of ordered products by id ASC and filtered with free text search", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -455,7 +475,10 @@ describe("/store/products", () => {
|
||||
})
|
||||
|
||||
describe("Product Category filtering", () => {
|
||||
let categoryWithProduct, categoryWithoutProduct, nestedCategoryWithProduct, nested2CategoryWithProduct
|
||||
let categoryWithProduct,
|
||||
categoryWithoutProduct,
|
||||
nestedCategoryWithProduct,
|
||||
nested2CategoryWithProduct
|
||||
const nestedCategoryWithProductId = "nested-category-with-product-id"
|
||||
const nested2CategoryWithProductId = "nested2-category-with-product-id"
|
||||
const categoryWithProductId = "category-with-product-id"
|
||||
@@ -463,14 +486,11 @@ describe("/store/products", () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager
|
||||
categoryWithProduct = await simpleProductCategoryFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: categoryWithProductId,
|
||||
name: "category with Product",
|
||||
products: [{ id: testProductId }],
|
||||
}
|
||||
)
|
||||
categoryWithProduct = await simpleProductCategoryFactory(dbConnection, {
|
||||
id: categoryWithProductId,
|
||||
name: "category with Product",
|
||||
products: [{ id: testProductId }],
|
||||
})
|
||||
|
||||
nestedCategoryWithProduct = await simpleProductCategoryFactory(
|
||||
dbConnection,
|
||||
@@ -504,49 +524,36 @@ describe("/store/products", () => {
|
||||
it("returns a list of products in product category without category children", async () => {
|
||||
const api = useApi()
|
||||
const params = `category_id[]=${categoryWithProductId}`
|
||||
const response = await api
|
||||
.get(
|
||||
`/store/products?${params}`,
|
||||
)
|
||||
const response = await api.get(`/store/products?${params}`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
expect(response.data.products).toEqual(
|
||||
[
|
||||
expect.objectContaining({
|
||||
id: testProductId,
|
||||
}),
|
||||
]
|
||||
)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: testProductId,
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("returns a list of products in product category without category children explicitly set to false", async () => {
|
||||
const api = useApi()
|
||||
const params = `category_id[]=${categoryWithProductId}&include_category_children=false`
|
||||
const response = await api
|
||||
.get(
|
||||
`/store/products?${params}`,
|
||||
)
|
||||
const response = await api.get(`/store/products?${params}`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
expect(response.data.products).toEqual(
|
||||
[
|
||||
expect.objectContaining({
|
||||
id: testProductId,
|
||||
}),
|
||||
]
|
||||
)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: testProductId,
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("returns a list of products in product category with category children", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const params = `category_id[]=${categoryWithProductId}&include_category_children=true`
|
||||
const response = await api
|
||||
.get(
|
||||
`/store/products?${params}`,
|
||||
)
|
||||
const response = await api.get(`/store/products?${params}`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(3)
|
||||
@@ -560,7 +567,7 @@ describe("/store/products", () => {
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: testProductFilteringId1,
|
||||
})
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
@@ -569,10 +576,7 @@ describe("/store/products", () => {
|
||||
const api = useApi()
|
||||
|
||||
const params = `category_id[]=${categoryWithoutProductId}&include_category_children=true`
|
||||
const response = await api
|
||||
.get(
|
||||
`/store/products?${params}`,
|
||||
)
|
||||
const response = await api.get(`/store/products?${params}`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(0)
|
||||
@@ -1082,5 +1086,27 @@ describe("/store/products", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("response contains only fields defined with `fields` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
"/store/products/test-product?fields=handle"
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(Object.keys(response.data.product)).toEqual([
|
||||
// fields
|
||||
"handle",
|
||||
// relations
|
||||
"variants",
|
||||
"options",
|
||||
"images",
|
||||
"tags",
|
||||
"collection",
|
||||
"type",
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user