Test if productservice.update updates rankings of variants
This commit is contained in:
@@ -148,6 +148,15 @@ describe("ProductService", () => {
|
|||||||
if (query.where.id === "123") {
|
if (query.where.id === "123") {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
if (query.where.id === "ranking test") {
|
||||||
|
return Promise.resolve({
|
||||||
|
id: "ranking test",
|
||||||
|
variants: [
|
||||||
|
{ id: "test_321", title: "Greener", rank: 1 },
|
||||||
|
{ id: "test_123", title: "Blueer", rank: 0 },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
return Promise.resolve({ id: IdMap.getId("ironman") })
|
return Promise.resolve({ id: IdMap.getId("ironman") })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -165,7 +174,12 @@ describe("ProductService", () => {
|
|||||||
withTransaction: function() {
|
withTransaction: function() {
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
update: () => Promise.resolve(),
|
update: (variant, update) => {
|
||||||
|
if (variant.id) {
|
||||||
|
return update
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const productTagRepository = MockRepository({
|
const productTagRepository = MockRepository({
|
||||||
@@ -248,6 +262,30 @@ describe("ProductService", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("successfully updates variant ranking", async () => {
|
||||||
|
await productService.update("ranking test", {
|
||||||
|
variants: [
|
||||||
|
{ id: "test_321", title: "Greener", rank: 1 },
|
||||||
|
{ id: "test_123", title: "Blueer", rank: 0 },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(eventBusService.emit).toHaveBeenCalledTimes(1)
|
||||||
|
expect(eventBusService.emit).toHaveBeenCalledWith(
|
||||||
|
"product.updated",
|
||||||
|
expect.any(Object)
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(productRepository.save).toHaveBeenCalledTimes(1)
|
||||||
|
expect(productRepository.save).toHaveBeenCalledWith({
|
||||||
|
id: "ranking test",
|
||||||
|
variants: [
|
||||||
|
{ id: "test_321", title: "Greener", rank: 0 },
|
||||||
|
{ id: "test_123", title: "Blueer", rank: 1 },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("successfully updates tags", async () => {
|
it("successfully updates tags", async () => {
|
||||||
await productService.update(IdMap.getId("ironman"), {
|
await productService.update(IdMap.getId("ironman"), {
|
||||||
tags: [
|
tags: [
|
||||||
|
|||||||
Reference in New Issue
Block a user