Chore/integration tests modules utils (#6581)

new wrapper for medusa integration tests.
for now it is only applied to the modules directory, but it could be used in the api integration tests or any other integrations that requires a db and a server up and running. 

It is not perfect, but I wanted to have something working and centralised before improving it, also avoiding too many conflicts with other prs
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-03-06 10:03:07 +00:00
1 parent a6736c7ee0
commit 51bb6f1e89
99 files changed
+10164 -10303

No files matched your search

@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleProductFactory,
simpleRegionFactory,
@@ -11,11 +8,10 @@ import {
PriceListStatus,
PriceListType,
} from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
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)
@@ -29,205 +25,193 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
let appContainer
let product
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
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]
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should update money amounts if variant id is present in prices", async () => {
const [priceList] = await pricingModuleService.createPriceLists([
{
title: "test price list",
description: "test",
ends_at: new Date().toISOString(),
starts_at: new Date().toISOString(),
status: PriceListStatus.ACTIVE,
type: PriceListType.OVERRIDE,
},
])
await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})
const api = useApi() as any
const data = {
prices: [
{
variant_id: variant.id,
amount: 5000,
currency_code: "usd",
},
{
amount: 6000,
region_id: "test-region",
variant_id: variant.id,
},
],
}
await api.post(
`admin/price-lists/${priceList.id}/prices/batch`,
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: "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),
}),
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: expect.any(String),
region_id: "test-region",
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),
}),
],
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 update money amounts if variant id is present in prices", async () => {
const [priceList] = await pricingModuleService.createPriceLists([
{
title: "test price list",
description: "test",
ends_at: new Date().toISOString(),
starts_at: new Date().toISOString(),
status: PriceListStatus.ACTIVE,
type: PriceListType.OVERRIDE,
},
])
await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})
const data = {
prices: [
{
variant_id: variant.id,
amount: 5000,
currency_code: "usd",
},
{
amount: 6000,
region_id: "test-region",
variant_id: variant.id,
},
],
}
await api.post(
`admin/price-lists/${priceList.id}/prices/batch`,
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: "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),
}),
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: expect.any(String),
region_id: "test-region",
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,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleCustomerGroupFactory,
simpleProductFactory,
@@ -8,11 +5,10 @@ import {
} from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
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)
@@ -26,166 +22,154 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("POST /admin/price-lists", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("POST /admin/price-lists", () => {
let appContainer
let product
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer)
await simpleCustomerGroupFactory(dbConnection, {
id: "customer-group-1",
name: "Test Group",
})
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]
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create price list and money amounts", async () => {
await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
await simpleRegionFactory(dbConnection, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
},
],
})
tax_rate: 0,
})
const api = useApi() as any
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",
},
],
}
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",
},
],
})
const result = await api.post(`admin/price-lists`, data, adminHeaders)
variant = product.variants[0]
})
let response = await api.get(
`/admin/price-lists/${result.data.price_list.id}`,
adminHeaders
)
it("should create price list and money amounts", async () => {
await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})
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: [
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,
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),
}),
],
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,18 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleProductFactory,
simpleRegionFactory,
} from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { AxiosInstance } from "axios"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
@@ -26,155 +21,140 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant1
let priceSet
let priceListId
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
let appContainer
let product
let variant1
let priceSet
let priceListId
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
const api = useApi()! as AxiosInstance
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",
},
],
})
variant1 = product.variants[0]
priceSet = await createVariantPriceSet({
container: appContainer,
variantId: variant1.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: variant1.id,
currency_code: "usd",
},
],
}
const priceListResult = await api.post(
`admin/price-lists`,
data,
adminHeaders
)
priceListId = priceListResult.data.price_list.id
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete prices in batch based on product ids", async () => {
const api = useApi()! as AxiosInstance
let priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
expect(priceSetMoneyAmounts.length).toEqual(2)
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/products/prices/batch`,
{
headers: adminHeaders.headers,
data: {
product_ids: [product.id],
},
}
)
expect(deleteRes.status).toEqual(200)
beforeEach(async () => {
await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer)
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
})
await simpleRegionFactory(dbConnection, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
expect(priceSetMoneyAmounts.length).toEqual(1)
expect(priceSetMoneyAmounts).toEqual([
expect.objectContaining({
price_list: null,
}),
])
})
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",
},
],
})
it("should delete prices based on single product id", async () => {
const api = useApi()! as AxiosInstance
variant1 = product.variants[0]
let priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
priceSet = await createVariantPriceSet({
container: appContainer,
variantId: variant1.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: variant1.id,
currency_code: "usd",
},
],
}
const priceListResult = await api.post(
`admin/price-lists`,
data,
adminHeaders
)
priceListId = priceListResult.data.price_list.id
})
expect(priceSetMoneyAmounts.length).toEqual(2)
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/products/${product.id}/prices`,
adminHeaders
)
expect(deleteRes.status).toEqual(200)
it("should delete prices in batch based on product ids", async () => {
let priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
})
expect(priceSetMoneyAmounts.length).toEqual(2)
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/products/prices/batch`,
{
headers: adminHeaders.headers,
data: {
product_ids: [product.id],
},
}
)
expect(deleteRes.status).toEqual(200)
priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
})
expect(priceSetMoneyAmounts.length).toEqual(1)
expect(priceSetMoneyAmounts).toEqual([
expect.objectContaining({
price_list: null,
}),
])
})
it("should delete prices based on single product id", async () => {
let priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
})
expect(priceSetMoneyAmounts.length).toEqual(2)
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/products/${product.id}/prices`,
adminHeaders
)
expect(deleteRes.status).toEqual(200)
priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id],
})
expect(priceSetMoneyAmounts.length).toEqual(1)
expect(priceSetMoneyAmounts).toEqual([
expect.objectContaining({
price_list: null,
}),
])
})
})
expect(priceSetMoneyAmounts.length).toEqual(1)
expect(priceSetMoneyAmounts).toEqual([
expect.objectContaining({
price_list: null,
}),
])
})
},
})
@@ -1,17 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleProductFactory,
simpleRegionFactory,
} from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
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)
@@ -25,107 +21,95 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => {
let appContainer
let product
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer)
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]
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete all prices based on product variant ids", async () => {
const priceSet = await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
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 all prices based on product variant ids", 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
let psmas = await pricingModuleService.listPriceSetMoneyAmounts({
price_list_id: [priceListId],
})
expect(psmas.length).toEqual(1)
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/variants/${variant.id}/prices`,
adminHeaders
)
expect(deleteRes.status).toEqual(200)
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
price_list_id: [priceListId],
})
expect(psmas.length).toEqual(0)
})
})
const api = useApi() as any
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
let psmas = await pricingModuleService.listPriceSetMoneyAmounts({
price_list_id: [priceListId],
})
expect(psmas.length).toEqual(1)
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/variants/${variant.id}/prices`,
adminHeaders
)
expect(deleteRes.status).toEqual(200)
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
price_list_id: [priceListId],
})
expect(psmas.length).toEqual(0)
})
},
})
@@ -1,17 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleProductFactory,
simpleRegionFactory,
} from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
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)
@@ -25,121 +21,109 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("DELETE /admin/price-lists/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id", () => {
let appContainer
let product
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer)
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]
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete price list prices by money amount ids", async () => {
await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
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 prices by money amount ids", async () => {
await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})
const data = {
name: "test price list",
description: "test",
type: "override",
status: "active",
prices: [
{
amount: 400,
variant_id: variant.id,
currency_code: "usd",
},
{
amount: 4000,
variant_id: variant.id,
currency_code: "usd",
},
],
}
const res = await api.post(`admin/price-lists`, data, adminHeaders)
const priceListId = res.data.price_list.id
let psmas = await pricingModuleService.listPriceSetMoneyAmounts(
{
price_list_id: [priceListId],
},
{ relations: ["money_amount"] }
)
expect(psmas.length).toEqual(2)
const deletePrice = psmas[0].money_amount
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/prices/batch`,
{
data: {
price_ids: [deletePrice?.id],
},
...adminHeaders,
}
)
expect(deleteRes.status).toEqual(200)
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
price_list_id: [priceListId],
})
expect(psmas.length).toEqual(1)
})
})
const api = useApi() as any
const data = {
name: "test price list",
description: "test",
type: "override",
status: "active",
prices: [
{
amount: 400,
variant_id: variant.id,
currency_code: "usd",
},
{
amount: 4000,
variant_id: variant.id,
currency_code: "usd",
},
],
}
const res = await api.post(`admin/price-lists`, data, adminHeaders)
const priceListId = res.data.price_list.id
let psmas = await pricingModuleService.listPriceSetMoneyAmounts(
{
price_list_id: [priceListId],
},
{ relations: ["money_amount"] }
)
expect(psmas.length).toEqual(2)
const deletePrice = psmas[0].money_amount
const deleteRes = await api.delete(
`/admin/price-lists/${priceListId}/prices/batch`,
{
data: {
price_ids: [deletePrice?.id],
},
...adminHeaders,
}
)
expect(deleteRes.status).toEqual(200)
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
price_list_id: [priceListId],
})
expect(psmas.length).toEqual(1)
})
},
})
@@ -1,17 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleProductFactory,
simpleRegionFactory,
} from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
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)
@@ -25,120 +21,108 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("DELETE /admin/price-lists/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id", () => {
let appContainer
let product
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
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]
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
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 api = useApi() as any
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
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
expect(afterDelete.response.status).toEqual(404)
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
price_list_id: [priceListId],
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)
})
})
expect(psmas.length).toEqual(0)
})
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories"
import {
@@ -8,10 +5,9 @@ import {
PriceListStatus,
PriceListType,
} from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
@@ -25,179 +21,164 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("GET /admin/price-lists/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /admin/price-lists/:id", () => {
let appContainer
let product
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
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",
},
],
})
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]
})
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: [],
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
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: [
const [priceList] = await pricingModuleService.createPriceLists([
{
amount: 5000,
currency_code: "usd",
price_set_id: priceSet.id,
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: [
await pricingModuleService.createPriceLists([
{
amount: 5000,
currency_code: "usd",
price_set_id: priceSet.id,
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 api = useApi() as any
const response = await api.get(
`/admin/price-lists/${priceList.id}`,
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: "test price list",
description: "test",
type: "override",
status: "active",
starts_at: expect.any(String),
ends_at: expect.any(String),
customer_groups: [],
prices: [
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,
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),
}),
],
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 api = useApi() as any
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)
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",
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,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories"
import {
@@ -8,10 +5,9 @@ import {
PriceListStatus,
PriceListType,
} from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
@@ -25,248 +21,235 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("GET /admin/price-lists/:id/products", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let product2
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /admin/price-lists/:id/products", () => {
let appContainer
let product
let product2
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
beforeEach(async () => {
await adminSeeder(dbConnection)
product = await simpleProductFactory(dbConnection, {
id: "test-product-with-variant",
title: "uniquely fun product",
variants: [
{
options: [{ option_id: "test-product-option-1", value: "test" }],
},
],
options: [
{
id: "test-product-option-1",
title: "Test option 1",
},
],
})
product = await simpleProductFactory(dbConnection, {
id: "test-product-with-variant",
title: "uniquely fun product",
variants: [
{
options: [{ option_id: "test-product-option-1", value: "test" }],
},
],
options: [
{
id: "test-product-option-1",
title: "Test option 1",
},
],
})
variant = product.variants[0]
variant = product.variants[0]
product2 = await simpleProductFactory(dbConnection, {
id: "test-product-with-variant-2",
title: "uniquely fun product 2",
variants: [
{
options: [
{ option_id: "test-product-option-2", value: "test 2" },
],
},
],
options: [
{
id: "test-product-option-2",
title: "Test option 2",
},
],
})
})
product2 = await simpleProductFactory(dbConnection, {
id: "test-product-with-variant-2",
title: "uniquely fun product 2",
variants: [
{
options: [{ option_id: "test-product-option-2", value: "test 2" }],
},
],
options: [
{
id: "test-product-option-2",
title: "Test option 2",
},
],
})
})
it("should list all products in a price list", async () => {
const priceSet = await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
rules: [],
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should list all products in a price list", 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: [
const [priceList] = await pricingModuleService.createPriceLists([
{
amount: 5000,
currency_code: "usd",
price_set_id: priceSet.id,
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 api = useApi() as any
let response = await api.get(
`/admin/price-lists/${priceList.id}/products`,
adminHeaders
)
let response = await api.get(
`/admin/price-lists/${priceList.id}/products`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
title: expect.any(String),
handle: expect.any(String),
subtitle: null,
description: null,
is_giftcard: false,
status: "draft",
thumbnail: null,
weight: null,
length: null,
height: null,
width: null,
origin_country: null,
hs_code: null,
mid_code: null,
material: null,
collection_id: null,
collection: null,
type_id: null,
type: null,
discountable: true,
external_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
metadata: null,
}),
])
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
title: expect.any(String),
handle: expect.any(String),
subtitle: null,
description: null,
is_giftcard: false,
status: "draft",
thumbnail: null,
weight: null,
length: null,
height: null,
width: null,
origin_country: null,
hs_code: null,
mid_code: null,
material: null,
collection_id: null,
collection: null,
type_id: null,
type: null,
discountable: true,
external_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
metadata: null,
}),
])
response = await api.get(
`/admin/products?price_list_id[]=${priceList.id}`,
adminHeaders
)
response = await api.get(
`/admin/products?price_list_id[]=${priceList.id}`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
title: expect.any(String),
handle: expect.any(String),
subtitle: null,
description: null,
is_giftcard: false,
status: "draft",
thumbnail: null,
weight: null,
length: null,
height: null,
width: null,
origin_country: null,
hs_code: null,
mid_code: null,
material: null,
collection_id: null,
collection: null,
type_id: null,
type: null,
discountable: true,
external_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
metadata: null,
}),
])
})
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
title: expect.any(String),
handle: expect.any(String),
subtitle: null,
description: null,
is_giftcard: false,
status: "draft",
thumbnail: null,
weight: null,
length: null,
height: null,
width: null,
origin_country: null,
hs_code: null,
mid_code: null,
material: null,
collection_id: null,
collection: null,
type_id: null,
type: null,
discountable: true,
external_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
metadata: null,
}),
])
})
it("should list all products constrained by search query in a price list", async () => {
const priceSet = await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
rules: [],
})
it("should list all products constrained by search query in a price list", 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: [
const [priceList] = await pricingModuleService.createPriceLists([
{
amount: 5000,
currency_code: "usd",
price_set_id: priceSet.id,
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 api = useApi() as any
let response = await api.get(
`/admin/price-lists/${priceList.id}/products?q=shouldnotreturnanything`,
adminHeaders
)
let response = await api.get(
`/admin/price-lists/${priceList.id}/products?q=shouldnotreturnanything`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(0)
expect(response.data.products).toEqual([])
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(0)
expect(response.data.products).toEqual([])
response = await api.get(
`/admin/price-lists/${priceList.id}/products?q=uniquely`,
adminHeaders
)
response = await api.get(
`/admin/price-lists/${priceList.id}/products?q=uniquely`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
}),
])
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
}),
])
response = await api.get(
`/admin/price-lists/${priceList.id}/products?q=`,
adminHeaders
)
response = await api.get(
`/admin/price-lists/${priceList.id}/products?q=`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
}),
])
})
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: expect.any(String),
}),
])
})
})
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories"
import {
@@ -8,10 +5,9 @@ import {
PriceListStatus,
PriceListType,
} from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
@@ -25,145 +21,132 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("GET /admin/price-lists", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /admin/price-lists", () => {
let appContainer
let product
let variant
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
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",
},
],
})
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]
})
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: [],
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
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: [
const [priceList] = await pricingModuleService.createPriceLists([
{
amount: 5000,
currency_code: "usd",
price_set_id: priceSet.id,
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 api = useApi() as any
const response = await api.get(`/admin/price-lists`, adminHeaders)
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(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,
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),
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),
}),
],
}),
],
}),
])
})
])
})
})
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleCustomerGroupFactory,
simpleProductFactory,
@@ -12,11 +9,10 @@ import {
PriceListStatus,
PriceListType,
} from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
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)
@@ -30,251 +26,240 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("POST /admin/price-lists/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let variant2
let pricingModuleService: IPricingModuleService
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 () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer)
await simpleCustomerGroupFactory(dbConnection, {
id: "customer-group-2",
name: "Test Group 2",
})
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,
})
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",
},
],
})
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]
})
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: [],
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
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: [
const [priceList] = await pricingModuleService.createPriceLists([
{
amount: 3000,
currency_code: "usd",
price_set_id: var2PriceSet.id,
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",
},
],
})
await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
})
const api = useApi() as any
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,
},
],
}
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)
await api.post(`admin/price-lists/${priceList.id}`, data, adminHeaders)
const response = await api.get(
`/admin/price-lists/${priceList.id}`,
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(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,
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,
}),
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),
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,
}),
]),
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,
},
],
})
)
})
)
})
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 api = useApi() as any
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,
},
],
})
)
})
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {
simpleCustomerFactory,
simpleCustomerGroupFactory,
@@ -13,12 +10,10 @@ import {
PriceListStatus,
PriceListType,
} from "@medusajs/types"
import { AxiosInstance } from "axios"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
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)
@@ -32,256 +27,239 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
describe.skip("GET /store/products/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let product
let variant
let priceSetId
let pricingModuleService: IPricingModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /store/products/:id", () => {
let appContainer
let product
let variant
let priceSetId
let pricingModuleService: IPricingModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
beforeAll(async () => {
appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService")
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer)
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",
status: "published",
variants: [
{
options: [{ option_id: "test-product-option-1", value: "test" }],
},
],
options: [
{
id: "test-product-option-1",
title: "Test option 1",
},
],
})
variant = product.variants[0]
const priceSet = await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
await simpleRegionFactory(dbConnection, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
},
{
amount: 4000,
currency_code: "usd",
},
],
rules: [],
})
tax_rate: 0,
})
priceSetId = priceSet.id
})
product = await simpleProductFactory(dbConnection, {
id: "test-product-with-variant",
status: "published",
variants: [
{
options: [{ option_id: "test-product-option-1", value: "test" }],
},
],
options: [
{
id: "test-product-option-1",
title: "Test option 1",
},
],
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
variant = product.variants[0]
it("should get product and its prices from price-list created through the price list workflow", async () => {
const api = useApi()! as AxiosInstance
const priceSet = await createVariantPriceSet({
container: appContainer,
variantId: variant.id,
prices: [
{
amount: 3000,
currency_code: "usd",
},
{
amount: 4000,
currency_code: "usd",
},
],
rules: [],
})
const priceListResponse = await api.post(
`/admin/price-lists`,
{
name: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.SALE,
prices: [
{
amount: 2500,
currency_code: "usd",
variant_id: variant.id,
},
],
},
adminHeaders
)
let response = await api.get(
`/store/products/${product.id}?currency_code=usd`
)
expect(response.status).toEqual(200)
expect(response.data.product.variants[0].prices).toHaveLength(2)
expect(response.data.product.variants[0].prices).toEqual([
expect.objectContaining({
currency_code: "usd",
amount: 3000,
min_quantity: null,
max_quantity: null,
price_list_id: null,
}),
expect.objectContaining({
currency_code: "usd",
amount: 2500,
min_quantity: null,
max_quantity: null,
price_list_id: priceListResponse.data.price_list.id,
}),
])
expect(response.data.product.variants[0]).toEqual(
expect.objectContaining({
original_price: 3000,
calculated_price: 2500,
calculated_price_type: "sale",
priceSetId = priceSet.id
})
)
})
it("should not list prices from price-list with customer groups if not logged in", async () => {
const api = useApi()! as AxiosInstance
const { id: customerGroupId } = await simpleCustomerGroupFactory(
dbConnection
)
const priceListResponse = await api.post(
`/admin/price-lists`,
{
name: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.SALE,
prices: [
it("should get product and its prices from price-list created through the price list workflow", async () => {
const priceListResponse = await api.post(
`/admin/price-lists`,
{
amount: 2500,
currency_code: "usd",
variant_id: variant.id,
name: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.SALE,
prices: [
{
amount: 2500,
currency_code: "usd",
variant_id: variant.id,
},
],
},
],
customer_groups: [{ id: customerGroupId }],
},
adminHeaders
)
adminHeaders
)
let response = await api.get(
`/store/products/${product.id}?currency_code=usd`
)
let response = await api.get(
`/store/products/${product.id}?currency_code=usd`
)
expect(response.status).toEqual(200)
expect(response.data.product.variants[0].prices).toEqual([
expect.objectContaining({
currency_code: "usd",
amount: 3000,
min_quantity: null,
max_quantity: null,
price_list_id: null,
}),
])
expect(response.data.product.variants[0]).toEqual(
expect.objectContaining({
original_price: 3000,
calculated_price: 3000,
calculated_price_type: null,
expect(response.status).toEqual(200)
expect(response.data.product.variants[0].prices).toHaveLength(2)
expect(response.data.product.variants[0].prices).toEqual([
expect.objectContaining({
currency_code: "usd",
amount: 3000,
min_quantity: null,
max_quantity: null,
price_list_id: null,
}),
expect.objectContaining({
currency_code: "usd",
amount: 2500,
min_quantity: null,
max_quantity: null,
price_list_id: priceListResponse.data.price_list.id,
}),
])
expect(response.data.product.variants[0]).toEqual(
expect.objectContaining({
original_price: 3000,
calculated_price: 2500,
calculated_price_type: "sale",
})
)
})
)
})
it("should list prices from price-list with customer groups", async () => {
const api = useApi()! as AxiosInstance
it("should not list prices from price-list with customer groups if not logged in", async () => {
const { id: customerGroupId } = await simpleCustomerGroupFactory(
dbConnection
)
await simpleCustomerFactory(dbConnection, {
id: "test-customer-5-pl",
email: "test5@email-pl.com",
first_name: "John",
last_name: "Deere",
password_hash:
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
has_account: true,
groups: [{ id: "customer-group-1" }],
})
const authResponse = await api.post("/store/auth", {
email: "test5@email-pl.com",
password: "test",
})
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
const priceListResponse = await api.post(
`/admin/price-lists`,
{
name: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.SALE,
prices: [
const priceListResponse = await api.post(
`/admin/price-lists`,
{
amount: 2500,
currency_code: "usd",
variant_id: variant.id,
name: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.SALE,
prices: [
{
amount: 2500,
currency_code: "usd",
variant_id: variant.id,
},
],
customer_groups: [{ id: customerGroupId }],
},
],
customer_groups: [{ id: "customer-group-1" }],
},
adminHeaders
)
adminHeaders
)
let response = await api.get(
`/store/products/${product.id}?currency_code=usd`,
{
headers: {
Cookie: authCookie,
},
}
)
let response = await api.get(
`/store/products/${product.id}?currency_code=usd`
)
expect(response.status).toEqual(200)
expect(response.data.product.variants[0].prices).toHaveLength(2)
expect(response.data.product.variants[0].prices).toEqual([
expect.objectContaining({
currency_code: "usd",
amount: 3000,
min_quantity: null,
max_quantity: null,
price_list_id: null,
}),
expect.objectContaining({
currency_code: "usd",
amount: 2500,
min_quantity: null,
max_quantity: null,
price_list_id: priceListResponse.data.price_list.id,
}),
])
expect(response.data.product.variants[0]).toEqual(
expect.objectContaining({
original_price: 3000,
calculated_price: 2500,
calculated_price_type: "sale",
expect(response.status).toEqual(200)
expect(response.data.product.variants[0].prices).toEqual([
expect.objectContaining({
currency_code: "usd",
amount: 3000,
min_quantity: null,
max_quantity: null,
price_list_id: null,
}),
])
expect(response.data.product.variants[0]).toEqual(
expect.objectContaining({
original_price: 3000,
calculated_price: 3000,
calculated_price_type: null,
})
)
})
)
})
it("should list prices from price-list with customer groups", async () => {
await simpleCustomerFactory(dbConnection, {
id: "test-customer-5-pl",
email: "test5@email-pl.com",
first_name: "John",
last_name: "Deere",
password_hash:
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
has_account: true,
groups: [{ id: "customer-group-1" }],
})
const authResponse = await api.post("/store/auth", {
email: "test5@email-pl.com",
password: "test",
})
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
const priceListResponse = await api.post(
`/admin/price-lists`,
{
name: "test price list",
description: "test",
status: PriceListStatus.ACTIVE,
type: PriceListType.SALE,
prices: [
{
amount: 2500,
currency_code: "usd",
variant_id: variant.id,
},
],
customer_groups: [{ id: "customer-group-1" }],
},
adminHeaders
)
let response = await api.get(
`/store/products/${product.id}?currency_code=usd`,
{
headers: {
Cookie: authCookie,
},
}
)
expect(response.status).toEqual(200)
expect(response.data.product.variants[0].prices).toHaveLength(2)
expect(response.data.product.variants[0].prices).toEqual([
expect.objectContaining({
currency_code: "usd",
amount: 3000,
min_quantity: null,
max_quantity: null,
price_list_id: null,
}),
expect.objectContaining({
currency_code: "usd",
amount: 2500,
min_quantity: null,
max_quantity: null,
price_list_id: priceListResponse.data.price_list.id,
}),
])
expect(response.data.product.variants[0]).toEqual(
expect.objectContaining({
original_price: 3000,
calculated_price: 2500,
calculated_price_type: "sale",
})
)
})
})
},
})