fix: update product images (#494)
This commit is contained in:
1 parent
0cf9e416f3
commit
c0e947f47a
2 files changed
+26
-3
No files matched your search
@@ -592,6 +592,28 @@ describe("/admin/products", () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("updates product (removes images when empty array included)", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
images: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post("/admin/products/test-product", payload, {
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer test_token",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
expect(response.data.product.images.length).toEqual(0)
|
||||||
|
})
|
||||||
|
|
||||||
it("fails to update product with invalid status", async () => {
|
it("fails to update product with invalid status", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
@@ -696,6 +718,7 @@ describe("/admin/products", () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("testing for soft-deletion + uniqueness on handles, collection and variant properties", () => {
|
describe("testing for soft-deletion + uniqueness on handles, collection and variant properties", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ class ProductService extends BaseService {
|
|||||||
|
|
||||||
let product = productRepo.create(rest)
|
let product = productRepo.create(rest)
|
||||||
|
|
||||||
if (images && images.length) {
|
if (images) {
|
||||||
product.images = await this.upsertImages_(images)
|
product.images = await this.upsertImages_(images)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,11 +380,11 @@ class ProductService extends BaseService {
|
|||||||
...rest
|
...rest
|
||||||
} = update
|
} = update
|
||||||
|
|
||||||
if (!product.thumbnail && !update.thumbnail && images && images.length) {
|
if (!product.thumbnail && !update.thumbnail && images?.length) {
|
||||||
product.thumbnail = images[0]
|
product.thumbnail = images[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (images && images.length) {
|
if (images) {
|
||||||
product.images = await this.upsertImages_(images)
|
product.images = await this.upsertImages_(images)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user