feat(product,dashboard): Allow re-ordering images (#10187)
* migration * fix snapshot * primarykey * init work on dnd * progress * dnd * undo changes * undo changes * undo changes * undo changes * fix firefox issue * lint * lint * lint * add changeset * undo changes to product module * set activator node * init work on service layer * alternative * switch to OneToMany * add tests * progress * update migration * update approach and remove all references to images in product.ts tests * handle delete images on empty array * fix config and order type * update changeset * rm flag * export type and fix type in test * fix type --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oli Juhl
parent
b12408dbd8
commit
1659c9be5d
@@ -74,6 +74,13 @@ medusaIntegrationTestRunner({
|
||||
// BREAKING: Type input changed from {type: {value: string}} to {type_id: string}
|
||||
type_id: baseType.id,
|
||||
tags: [{ id: baseTag1.id }, { id: baseTag2.id }],
|
||||
images: [{
|
||||
url: "image-one",
|
||||
},
|
||||
{
|
||||
url: "image-two",
|
||||
},
|
||||
],
|
||||
}),
|
||||
adminHeaders
|
||||
)
|
||||
@@ -116,6 +123,24 @@ medusaIntegrationTestRunner({
|
||||
|
||||
describe("/admin/products", () => {
|
||||
describe("GET /admin/products", () => {
|
||||
it("returns a list of products with images ordered by rank", async () => {
|
||||
const res = await api.get("/admin/products", adminHeaders)
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
expect(res.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: baseProduct.id,
|
||||
images: expect.arrayContaining([
|
||||
expect.objectContaining({ url: "image-one", rank: 0 }),
|
||||
expect.objectContaining({ url: "image-two", rank: 1 }),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
it("returns a list of products with all statuses when no status or invalid status is provided", async () => {
|
||||
const res = await api
|
||||
.get("/admin/products", adminHeaders)
|
||||
@@ -965,6 +990,17 @@ medusaIntegrationTestRunner({
|
||||
expect(hasPrices).toBe(true)
|
||||
})
|
||||
|
||||
it("should get a product with images ordered by rank", async () => {
|
||||
const res = await api.get(`/admin/products/${baseProduct.id}`, adminHeaders)
|
||||
|
||||
expect(res.data.product.images).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ url: "image-one", rank: 0 }),
|
||||
expect.objectContaining({ url: "image-two", rank: 1 }),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should get a product with prices", async () => {
|
||||
const res = await api
|
||||
.get(
|
||||
|
||||
@@ -526,6 +526,14 @@ medusaIntegrationTestRunner({
|
||||
prices: [{ amount: 3000, currency_code: "usd" }],
|
||||
},
|
||||
],
|
||||
images: [
|
||||
{
|
||||
url: "image-one",
|
||||
},
|
||||
{
|
||||
url: "image-two",
|
||||
},
|
||||
],
|
||||
})
|
||||
;[product2, [variant2]] = await createProducts({
|
||||
title: "test product 2 uniquely",
|
||||
@@ -620,6 +628,22 @@ medusaIntegrationTestRunner({
|
||||
])
|
||||
})
|
||||
|
||||
it("should list all products with images ordered by rank", async () => {
|
||||
const response = await api.get("/store/products", storeHeaders)
|
||||
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: product.id,
|
||||
images: expect.arrayContaining([
|
||||
expect.objectContaining({ url: "image-one", rank: 0 }),
|
||||
expect.objectContaining({ url: "image-two", rank: 1 }),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should list all products excluding variants", async () => {
|
||||
let response = await api.get(
|
||||
`/admin/products?fields=-variants`,
|
||||
@@ -1406,6 +1430,14 @@ medusaIntegrationTestRunner({
|
||||
],
|
||||
},
|
||||
],
|
||||
images: [
|
||||
{
|
||||
url: "image-one",
|
||||
},
|
||||
{
|
||||
url: "image-two",
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
const defaultSalesChannel = await createSalesChannel(
|
||||
@@ -1454,6 +1486,17 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("should retrieve product with images ordered by rank", async () => {
|
||||
const response = await api.get(`/store/products/${product.id}`, storeHeaders)
|
||||
|
||||
expect(response.data.product.images).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ url: "image-one", rank: 0 }),
|
||||
expect.objectContaining({ url: "image-two", rank: 1 }),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
// TODO: There are 2 problems that need to be solved to enable this test
|
||||
// 1. When adding product to another category, the product is being removed from earlier assigned categories
|
||||
// 2. MikroORM seems to be doing a join strategy to load relationships, we need to send a separate query to fetch relationships
|
||||
|
||||
Reference in New Issue
Block a user