feat(core-flows,medusa,pricing,types,utils): added price list workflows + endpoints (#6648)
Apologies for the giant PR in advance, but most of these are removing of files and migrations from old workflows and routes to new. What: - Adds CRUD endpoints for price lists - Migrate workflows from old sdk to new - Added missing updatePriceListPrices method to pricing module
This commit is contained in:
@@ -1,175 +0,0 @@
|
||||
import {
|
||||
simpleCustomerGroupFactory,
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("POST /admin/price-lists", () => {
|
||||
let appContainer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
await simpleCustomerGroupFactory(dbConnection, {
|
||||
id: "customer-group-1",
|
||||
name: "Test Group",
|
||||
})
|
||||
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
id: "test-region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
})
|
||||
|
||||
product = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product-with-variant",
|
||||
variants: [
|
||||
{
|
||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
id: "test-product-option-1",
|
||||
title: "Test option 1",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
it("should create price list and money amounts", async () => {
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [
|
||||
{
|
||||
amount: 3000,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const data = {
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
customer_groups: [{ id: "customer-group-1" }],
|
||||
status: "active",
|
||||
starts_at: new Date(),
|
||||
prices: [
|
||||
{
|
||||
amount: 400,
|
||||
variant_id: variant.id,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
||||
|
||||
let response = await api.get(
|
||||
`/admin/price-lists/${result.data.price_list.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_list).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: expect.any(String),
|
||||
ends_at: null,
|
||||
customer_groups: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
name: "Test Group",
|
||||
metadata: null,
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
currency_code: "usd",
|
||||
amount: 400,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: expect.any(String),
|
||||
region_id: null,
|
||||
variant: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
title: expect.any(String),
|
||||
product_id: expect.any(String),
|
||||
sku: null,
|
||||
barcode: null,
|
||||
ean: null,
|
||||
upc: null,
|
||||
variant_rank: 0,
|
||||
inventory_quantity: 10,
|
||||
allow_backorder: false,
|
||||
manage_inventory: true,
|
||||
hs_code: null,
|
||||
origin_country: null,
|
||||
mid_code: null,
|
||||
material: null,
|
||||
weight: null,
|
||||
length: null,
|
||||
height: null,
|
||||
width: null,
|
||||
metadata: null,
|
||||
}),
|
||||
variant_id: expect.any(String),
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -1,128 +0,0 @@
|
||||
import {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
let appContainer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
id: "test-region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
})
|
||||
|
||||
product = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product-with-variant",
|
||||
variants: [
|
||||
{
|
||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
id: "test-product-option-1",
|
||||
title: "Test option 1",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
it("should delete price list and money amounts", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [
|
||||
{
|
||||
amount: 3000,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const data = {
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
customer_groups: [],
|
||||
status: "active",
|
||||
prices: [
|
||||
{
|
||||
amount: 400,
|
||||
variant_id: variant.id,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
||||
const priceListId = result.data.price_list.id
|
||||
|
||||
const getResponse = await api.get(
|
||||
`/admin/price-lists/${priceListId}`,
|
||||
adminHeaders
|
||||
)
|
||||
expect(getResponse.status).toEqual(200)
|
||||
|
||||
let psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
price_list_id: [priceListId],
|
||||
})
|
||||
expect(psmas.length).toEqual(1)
|
||||
|
||||
const deleteRes = await api.delete(
|
||||
`/admin/price-lists/${priceListId}`,
|
||||
adminHeaders
|
||||
)
|
||||
expect(deleteRes.status).toEqual(200)
|
||||
|
||||
const afterDelete = await api
|
||||
.get(`/admin/price-lists/${priceListId}`, adminHeaders)
|
||||
.catch((err) => {
|
||||
return err
|
||||
})
|
||||
expect(afterDelete.response.status).toEqual(404)
|
||||
|
||||
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
price_list_id: [priceListId],
|
||||
})
|
||||
expect(psmas.length).toEqual(0)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -1,184 +0,0 @@
|
||||
import { simpleProductFactory } from "../../../../factories"
|
||||
|
||||
import {
|
||||
IPricingModuleService,
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("GET /admin/price-lists/:id", () => {
|
||||
let appContainer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
product = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product-with-variant",
|
||||
variants: [
|
||||
{
|
||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
id: "test-product-option-1",
|
||||
title: "Test option 1",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
it("should get price list and its money amounts with variants", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [
|
||||
{
|
||||
amount: 3000,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
rules: [],
|
||||
})
|
||||
|
||||
const [priceList] = await pricingModuleService.createPriceLists([
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
ends_at: new Date(),
|
||||
starts_at: new Date(),
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.OVERRIDE,
|
||||
prices: [
|
||||
{
|
||||
amount: 5000,
|
||||
currency_code: "usd",
|
||||
price_set_id: priceSet.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
await pricingModuleService.createPriceLists([
|
||||
{
|
||||
title: "test price list 1",
|
||||
description: "test 1",
|
||||
ends_at: new Date(),
|
||||
starts_at: new Date(),
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.OVERRIDE,
|
||||
prices: [
|
||||
{
|
||||
amount: 5000,
|
||||
currency_code: "usd",
|
||||
price_set_id: priceSet.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/price-lists/${priceList.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_list).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: expect.any(String),
|
||||
ends_at: expect.any(String),
|
||||
customer_groups: [],
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
currency_code: "usd",
|
||||
amount: 5000,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: expect.any(String),
|
||||
region_id: null,
|
||||
variant: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
title: expect.any(String),
|
||||
product_id: expect.any(String),
|
||||
sku: null,
|
||||
barcode: null,
|
||||
ean: null,
|
||||
upc: null,
|
||||
variant_rank: 0,
|
||||
inventory_quantity: 10,
|
||||
allow_backorder: false,
|
||||
manage_inventory: true,
|
||||
hs_code: null,
|
||||
origin_country: null,
|
||||
mid_code: null,
|
||||
material: null,
|
||||
weight: null,
|
||||
length: null,
|
||||
height: null,
|
||||
width: null,
|
||||
metadata: null,
|
||||
}),
|
||||
variant_id: expect.any(String),
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when price list is not found", async () => {
|
||||
const error = await api
|
||||
.get(`/admin/price-lists/does-not-exist`, adminHeaders)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.response.status).toBe(404)
|
||||
expect(error.response.data).toEqual({
|
||||
type: "not_found",
|
||||
message: "Price list with id: does-not-exist was not found",
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -1,152 +0,0 @@
|
||||
import { simpleProductFactory } from "../../../../factories"
|
||||
|
||||
import {
|
||||
IPricingModuleService,
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("GET /admin/price-lists", () => {
|
||||
let appContainer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
product = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product-with-variant",
|
||||
variants: [
|
||||
{
|
||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
id: "test-product-option-1",
|
||||
title: "Test option 1",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
it("should get price list and its money amounts with variants", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [
|
||||
{
|
||||
amount: 3000,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
rules: [],
|
||||
})
|
||||
|
||||
const [priceList] = await pricingModuleService.createPriceLists([
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
ends_at: new Date(),
|
||||
starts_at: new Date(),
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.OVERRIDE,
|
||||
prices: [
|
||||
{
|
||||
amount: 5000,
|
||||
currency_code: "usd",
|
||||
price_set_id: priceSet.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const response = await api.get(`/admin/price-lists`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.price_lists).toEqual([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: expect.any(String),
|
||||
ends_at: expect.any(String),
|
||||
customer_groups: [],
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
currency_code: "usd",
|
||||
amount: 5000,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: expect.any(String),
|
||||
region_id: null,
|
||||
variant: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
title: expect.any(String),
|
||||
product_id: expect.any(String),
|
||||
sku: null,
|
||||
barcode: null,
|
||||
ean: null,
|
||||
upc: null,
|
||||
variant_rank: 0,
|
||||
inventory_quantity: 10,
|
||||
allow_backorder: false,
|
||||
manage_inventory: true,
|
||||
hs_code: null,
|
||||
origin_country: null,
|
||||
mid_code: null,
|
||||
material: null,
|
||||
weight: null,
|
||||
length: null,
|
||||
height: null,
|
||||
width: null,
|
||||
metadata: null,
|
||||
}),
|
||||
variant_id: expect.any(String),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -258,6 +258,351 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/price-lists", () => {
|
||||
it("should create price list and money amounts", async () => {
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [{ amount: 3000, currency_code: "usd" }],
|
||||
})
|
||||
|
||||
const data = {
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: new Date(),
|
||||
rules: {
|
||||
customer_group_id: [customerGroup.id],
|
||||
},
|
||||
prices: [
|
||||
{
|
||||
amount: 400,
|
||||
variant_id: variant.id,
|
||||
currency_code: "usd",
|
||||
rules: { region_id: region.id },
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api.post(
|
||||
`admin/price-lists`,
|
||||
data,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_list).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: expect.any(String),
|
||||
ends_at: null,
|
||||
rules: {
|
||||
customer_group_id: [customerGroup.id],
|
||||
},
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
currency_code: "usd",
|
||||
amount: 400,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
variant_id: variant.id,
|
||||
rules: {
|
||||
region_id: region.id,
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw error when required attributes are not provided", async () => {
|
||||
const data = {
|
||||
prices: [
|
||||
{
|
||||
amount: 400,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const errorResponse = await api
|
||||
.post(`admin/price-lists`, data, adminHeaders)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(errorResponse.response.status).toEqual(400)
|
||||
expect(errorResponse.response.data.message).toEqual(
|
||||
"title must be a string, description must be a string, type must be one of the following values: sale, override, variant_id must be a string"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("DELETE /admin/price-lists/:id", () => {
|
||||
it("should delete price list and money amounts", async () => {
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [{ amount: 3000, currency_code: "usd" }],
|
||||
})
|
||||
|
||||
const data = {
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: new Date(),
|
||||
prices: [
|
||||
{ amount: 400, variant_id: variant.id, currency_code: "usd" },
|
||||
],
|
||||
}
|
||||
|
||||
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
||||
const priceListId = result.data.price_list.id
|
||||
|
||||
let psmas = await pricingModule.listPriceSetMoneyAmounts({
|
||||
price_list_id: [priceListId],
|
||||
})
|
||||
|
||||
expect(psmas.length).toEqual(1)
|
||||
|
||||
const deleteRes = await api.delete(
|
||||
`/admin/price-lists/${priceListId}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(deleteRes.status).toEqual(200)
|
||||
|
||||
const afterDelete = await api
|
||||
.get(`/admin/price-lists/${priceListId}`, adminHeaders)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(afterDelete.response.status).toEqual(404)
|
||||
|
||||
psmas = await pricingModule.listPriceSetMoneyAmounts({
|
||||
price_list_id: [priceListId],
|
||||
})
|
||||
expect(psmas.length).toEqual(0)
|
||||
})
|
||||
|
||||
it("should idempotently return a success even if price lists dont exist", async () => {
|
||||
const deleteRes = await api.delete(
|
||||
`/admin/price-lists/does-not-exist`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(deleteRes.status).toEqual(200)
|
||||
expect(deleteRes.data).toEqual({
|
||||
id: "does-not-exist",
|
||||
object: "price_list",
|
||||
deleted: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/price-lists/:id", () => {
|
||||
it("should throw error when trying to update a price list that does not exist", async () => {
|
||||
const updateRes = await api
|
||||
.post(
|
||||
`admin/price-lists/does-not-exist`,
|
||||
{ title: "new price list name" },
|
||||
adminHeaders
|
||||
)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(updateRes.response.status).toEqual(404)
|
||||
expect(updateRes.response.data.message).toEqual(
|
||||
"Price lists with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should update price lists successfully", async () => {
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [{ amount: 3000, currency_code: "usd" }],
|
||||
})
|
||||
|
||||
const [priceList] = await pricingModule.createPriceLists([
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
ends_at: new Date(),
|
||||
starts_at: new Date(),
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.OVERRIDE,
|
||||
},
|
||||
])
|
||||
|
||||
const data = {
|
||||
title: "new price list name",
|
||||
description: "new price list description",
|
||||
rules: {
|
||||
customer_group_id: [customerGroup.id],
|
||||
},
|
||||
prices: [
|
||||
{
|
||||
amount: 400,
|
||||
variant_id: variant.id,
|
||||
currency_code: "usd",
|
||||
rules: { region_id: region.id },
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api.post(
|
||||
`admin/price-lists/${priceList.id}`,
|
||||
data,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_list).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
title: "new price list name",
|
||||
description: "new price list description",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: expect.any(String),
|
||||
ends_at: expect.any(String),
|
||||
rules: {
|
||||
customer_group_id: [customerGroup.id],
|
||||
},
|
||||
prices: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
currency_code: "usd",
|
||||
amount: 400,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
variant_id: variant.id,
|
||||
rules: {
|
||||
region_id: region.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/price-lists/:id/prices", () => {
|
||||
it("should upsert price list prices successfully", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [{ amount: 3000, currency_code: "usd" }],
|
||||
})
|
||||
|
||||
const [priceList] = await pricingModule.createPriceLists([
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
prices: [
|
||||
{
|
||||
id: "test-price-id",
|
||||
amount: 5000,
|
||||
currency_code: "usd",
|
||||
price_set_id: priceSet.id,
|
||||
rules: { region_id: region.id },
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const data = {
|
||||
prices: [
|
||||
{
|
||||
amount: 400,
|
||||
variant_id: variant.id,
|
||||
currency_code: "usd",
|
||||
rules: { region_id: region.id },
|
||||
},
|
||||
{
|
||||
id: "test-price-id",
|
||||
variant_id: variant.id,
|
||||
amount: 200,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api.post(
|
||||
`admin/price-lists/${priceList.id}/prices`,
|
||||
data,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_list.prices.length).toEqual(2)
|
||||
expect(response.data.price_list).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
currency_code: "usd",
|
||||
amount: 400,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-price-id",
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("DELETE /admin/price-lists/:id/prices", () => {
|
||||
it("should delete price list prices", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [],
|
||||
})
|
||||
|
||||
const [priceList] = await pricingModule.createPriceLists([
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
prices: [
|
||||
{
|
||||
id: "test-price-id",
|
||||
amount: 5000,
|
||||
currency_code: "usd",
|
||||
price_set_id: priceSet.id,
|
||||
rules: {
|
||||
region_id: region.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
let response = await api.delete(
|
||||
`/admin/price-lists/${priceList.id}/prices`,
|
||||
{ ...adminHeaders, data: { ids: ["test-price-id"] } }
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
ids: ["test-price-id"],
|
||||
object: "price_list_prices",
|
||||
deleted: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,265 +0,0 @@
|
||||
import {
|
||||
simpleCustomerGroupFactory,
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
|
||||
import {
|
||||
IPricingModuleService,
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("POST /admin/price-lists/:id", () => {
|
||||
let appContainer
|
||||
let product
|
||||
let variant
|
||||
let variant2
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
await simpleCustomerGroupFactory(dbConnection, {
|
||||
id: "customer-group-2",
|
||||
name: "Test Group 2",
|
||||
})
|
||||
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
id: "test-region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
})
|
||||
|
||||
product = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product-with-variant",
|
||||
variants: [
|
||||
{
|
||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||
},
|
||||
{
|
||||
options: [
|
||||
{ option_id: "test-product-option-2", value: "test 2" },
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
id: "test-product-option-1",
|
||||
title: "Test option 1",
|
||||
},
|
||||
{
|
||||
id: "test-product-option-2",
|
||||
title: "Test option 2",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
variant = product.variants[0]
|
||||
variant2 = product.variants[1]
|
||||
})
|
||||
|
||||
it("should update price lists successfully with prices", async () => {
|
||||
const var2PriceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant2.id,
|
||||
prices: [],
|
||||
})
|
||||
|
||||
const [priceList] = await pricingModuleService.createPriceLists([
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
ends_at: new Date(),
|
||||
starts_at: new Date(),
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.OVERRIDE,
|
||||
prices: [
|
||||
{
|
||||
amount: 3000,
|
||||
currency_code: "usd",
|
||||
price_set_id: var2PriceSet.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [
|
||||
{
|
||||
amount: 3000,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const data = {
|
||||
name: "new price list name",
|
||||
description: "new price list description",
|
||||
customer_groups: [{ id: "customer-group-2" }],
|
||||
prices: [
|
||||
{
|
||||
variant_id: variant.id,
|
||||
amount: 5000,
|
||||
currency_code: "usd",
|
||||
},
|
||||
{
|
||||
id: priceList?.price_set_money_amounts?.[0].money_amount?.id,
|
||||
amount: 6000,
|
||||
currency_code: "usd",
|
||||
variant_id: variant2.id,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
await api.post(`admin/price-lists/${priceList.id}`, data, adminHeaders)
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/price-lists/${priceList.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_list).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
name: "new price list name",
|
||||
description: "new price list description",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: expect.any(String),
|
||||
ends_at: expect.any(String),
|
||||
customer_groups: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
name: "Test Group 2",
|
||||
metadata: null,
|
||||
},
|
||||
],
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
currency_code: "usd",
|
||||
amount: 5000,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: priceList.id,
|
||||
region_id: null,
|
||||
variant: expect.objectContaining({
|
||||
id: variant.id,
|
||||
}),
|
||||
variant_id: variant.id,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
currency_code: "usd",
|
||||
amount: 6000,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
price_list_id: priceList.id,
|
||||
region_id: null,
|
||||
variant: expect.objectContaining({
|
||||
id: variant2.id,
|
||||
}),
|
||||
variant_id: variant2.id,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should not delete customer groups if customer_groups is not passed as a param", async () => {
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant2.id,
|
||||
prices: [],
|
||||
})
|
||||
|
||||
const [priceList] = await pricingModuleService.createPriceLists([
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
status: PriceListStatus.DRAFT,
|
||||
rules: {
|
||||
customer_group_id: ["customer-group-2"],
|
||||
},
|
||||
prices: [],
|
||||
},
|
||||
])
|
||||
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
variantId: variant.id,
|
||||
prices: [],
|
||||
})
|
||||
|
||||
const data = {
|
||||
status: PriceListStatus.ACTIVE,
|
||||
}
|
||||
|
||||
await api.post(`admin/price-lists/${priceList.id}`, data, adminHeaders)
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/price-lists/${priceList.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_list).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
customer_groups: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
name: "Test Group 2",
|
||||
metadata: null,
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user