add ranking of variants to product creation

This commit is contained in:
pKorsholm
2021-09-03 17:17:43 +02:00
parent 9e62746e43
commit 32880dbed3

View File

@@ -1,10 +1,77 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { ProductServiceMock } from "../../../../../services/__mocks__/product"
import { ProductVariantServiceMock } from "../../../../../services/__mocks__/product-variant"
import { ShippingProfileServiceMock } from "../../../../../services/__mocks__/shipping-profile"
describe("POST /admin/products", () => {
describe("successful creation", () => {
describe("successful creation with variants", () => {
let subject
beforeAll(async () => {
subject = await request("POST", "/admin/products", {
payload: {
title: "Test Product with variants",
description: "Test Description",
tags: [{ id: "test", value: "test" }],
handle: "test-product",
options: [{ title: "Test" }],
variants: [
{
title: "Test",
prices: [
{
currency_code: "USD",
amount: 100,
},
],
options: [
{
value: "100",
},
],
},
],
},
adminSession: {
jwt: {
userId: IdMap.getId("admin_user"),
},
},
})
})
it("returns 200", () => {
expect(subject.status).toEqual(200)
})
it("assigns invokes productVariantService with ranked variants", () => {
expect(ProductVariantServiceMock.create).toHaveBeenCalledTimes(1)
expect(ProductVariantServiceMock.create).toHaveBeenCalledWith(
IdMap.getId("productWithOptions"),
{
title: "Test",
rank: 0,
prices: [
{
currency_code: "USD",
amount: 100,
},
],
options: [
{
option_id: IdMap.getId("option1"),
value: "100",
},
],
inventory_quantity: 0,
}
)
expect(true).toEqual(true)
})
})
describe("successful creation test", () => {
let subject
beforeAll(async () => {
@@ -14,6 +81,7 @@ describe("POST /admin/products", () => {
description: "Test Description",
tags: [{ id: "test", value: "test" }],
handle: "test-product",
options: [{ title: "Denominations" }],
},
adminSession: {
jwt: {
@@ -28,6 +96,7 @@ describe("POST /admin/products", () => {
})
it("returns created product draft", () => {
console.log(subject.body)
expect(subject.body.product.id).toEqual(IdMap.getId("product1"))
})
@@ -40,10 +109,24 @@ describe("POST /admin/products", () => {
tags: [{ id: "test", value: "test" }],
handle: "test-product",
is_giftcard: false,
options: [{ title: "Denominations" }],
profile_id: IdMap.getId("default_shipping_profile"),
})
})
// it("calls productvariantservice create", () => {
// expect(ProductServiceMock.create).toHaveBeenCalledTimes(1)
// expect(ProductServiceMock.create).toHaveBeenCalledWith({
// title: "Test Product",
// discountable: true,
// description: "Test Description",
// tags: [{ id: "test", value: "test" }],
// handle: "test-product",
// is_giftcard: false,
// profile_id: IdMap.getId("default_shipping_profile"),
// })
// })
it("calls shipping profile default", () => {
expect(ShippingProfileServiceMock.retrieveDefault).toHaveBeenCalledTimes(
1