chore: Move price list tests to HTTP folder (#7632)

* chore: Move price list tests to HTTP folder

* chore: Remove several unused helpers
This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-06-06 17:17:41 +02:00
1 parent 9576de2be4
commit a62a8be016
8 files changed
+874 -2036

No files matched your search

@@ -1,241 +0,0 @@
const { ProductVariantMoneyAmount } = require("@medusajs/medusa")
const { MoneyAmount } = require("@medusajs/medusa")
const {
Region,
Product,
ProductVariant,
PriceList,
CustomerGroup,
Customer,
Image,
ShippingProfile,
ProductCollection,
ProductOption,
} = require("@medusajs/medusa")
module.exports = async (dataSource, data = {}) => {
const manager = dataSource.manager
const yesterday = ((today) => new Date(today.setDate(today.getDate() - 1)))(
new Date()
)
const tenDaysAgo = ((today) => new Date(today.setDate(today.getDate() - 10)))(
new Date()
)
const defaultProfile = await manager.findOne(ShippingProfile, {
where: { type: ShippingProfile.default },
})
const collection = manager.create(ProductCollection, {
id: "test-collection",
handle: "test-collection",
title: "Test collection",
})
await manager.save(collection)
await manager.insert(Region, {
id: "reg-europe",
name: "Test Region Europe",
currency_code: "eur",
tax_rate: 0,
})
await manager.insert(Region, {
id: "reg-us",
name: "Test Region US",
currency_code: "usd",
tax_rate: 0,
})
const customer = manager.create(Customer, {
id: "test-customer",
email: "john@doe.com",
first_name: "John",
last_name: "Doe",
password_hash:
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
has_account: true,
})
const customerGroup = manager.create(CustomerGroup, {
id: "test-group",
name: "test-group",
})
await manager.save(customerGroup)
customer.groups = [customerGroup]
await manager.save(customer)
const priceListActive = manager.create(PriceList, {
id: "pl",
name: "VIP sale",
description: "All year sale for VIP customers.",
type: "sale",
status: "active",
})
await manager.save(priceListActive)
const priceListExpired = manager.create(PriceList, {
id: "pl_expired",
name: "VIP summer sale",
description: "Summer sale for VIP customers.",
type: "sale",
status: "active",
starts_at: tenDaysAgo,
ends_at: yesterday,
})
await manager.save(priceListExpired)
const priceListWithCustomers = manager.create(PriceList, {
id: "pl_with_customers",
name: "VIP winter sale",
description: "Winter sale for VIP customers.",
type: "sale",
status: "active",
})
priceListWithCustomers.customer_groups = [customerGroup]
await manager.save(priceListWithCustomers)
const productMultiReg = manager.create(Product, {
id: "test-product",
handle: "test-product-reg",
title: "Multi Reg Test product",
profile_id: defaultProfile.id,
profiles: [{ id: defaultProfile.id }],
description: "test-product-description",
status: "published",
collection_id: "test-collection",
})
const image = manager.create(Image, {
id: "test-image",
url: "test-image.png",
})
productMultiReg.images = [image]
await manager.save(productMultiReg)
await manager.save(ProductOption, {
id: "test-option",
title: "test-option",
product_id: "test-product",
})
const variantMultiReg = manager.create(ProductVariant, {
id: "test-variant",
inventory_quantity: 10,
title: "Test variant",
variant_rank: 0,
sku: "test-sku",
ean: "test-ean",
upc: "test-upc",
barcode: "test-barcode",
product_id: "test-product",
options: [
{
id: "test-variant-option-reg",
value: "Default variant",
option_id: "test-option",
},
],
})
await manager.insert(MoneyAmount, {
id: "test-price-multi-usd",
currency_code: "usd",
amount: 100,
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma",
money_amount_id: "test-price-multi-usd",
variant_id: "test-variant",
})
await manager.insert(MoneyAmount, {
id: "test-price-discount-multi-usd",
currency_code: "usd",
amount: 80,
price_list_id: "pl",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma1",
money_amount_id: "test-price-discount-multi-usd",
variant_id: "test-variant",
})
await manager.insert(MoneyAmount, {
id: "test-price-discount-expired-multi-usd",
currency_code: "usd",
amount: 70,
price_list_id: "pl_expired",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma2",
money_amount_id: "test-price-discount-expired-multi-usd",
variant_id: "test-variant",
})
await manager.insert(MoneyAmount, {
id: "test-price-multi-eur",
currency_code: "eur",
amount: 100,
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma3",
money_amount_id: "test-price-multi-eur",
variant_id: "test-variant",
})
await manager.insert(MoneyAmount, {
id: "test-price-discount-multi-eur",
currency_code: "eur",
amount: 80,
price_list_id: "pl",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma4",
money_amount_id: "test-price-discount-multi-eur",
variant_id: "test-variant",
})
await manager.insert(MoneyAmount, {
id: "test-price-discount-multi-eur-with-customer",
currency_code: "eur",
amount: 40,
price_list_id: "pl_with_customers",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma5",
money_amount_id: "test-price-discount-multi-eur-with-customer",
variant_id: "test-variant",
})
await manager.insert(MoneyAmount, {
id: "test-price-discount-expired-multi-eur",
currency_code: "eur",
amount: 70,
price_list_id: "pl_expired",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma6",
money_amount_id: "test-price-discount-expired-multi-eur",
variant_id: "test-variant",
})
await manager.save(variantMultiReg)
}
@@ -1,113 +0,0 @@
const { Customer, Address, CustomerGroup } = require("@medusajs/medusa")
module.exports = async (dataSource, data = {}) => {
const manager = dataSource.manager
const testAddr = manager.create(Address, {
id: "test-address",
first_name: "Lebron",
last_name: "James",
})
await manager.save(testAddr)
const customer = manager.create(Customer, {
id: "test-customer-1",
email: "test1@email.com",
})
customer.billing_address = testAddr
customer.shipping_addresses = [testAddr]
await manager.save(customer)
await manager.insert(Customer, {
id: "test-customer-2",
email: "test2@email.com",
})
await manager.insert(Customer, {
id: "test-customer-3",
email: "test3@email.com",
})
await manager.insert(Customer, {
id: "test-customer-has_account",
email: "test4@email.com",
has_account: true,
})
const customer5 = manager.create(Customer, {
id: "test-customer-5",
email: "test5@email.com",
})
await manager.save(customer5)
const customer6 = manager.create(Customer, {
id: "test-customer-6",
email: "test6@email.com",
})
await manager.save(customer6)
const customer7 = manager.create(Customer, {
id: "test-customer-7",
email: "test7@email.com",
})
await manager.save(customer7)
const deletionCustomer = manager.create(Customer, {
id: "test-customer-delete-cg",
email: "test-deletetion-cg@email.com",
})
await manager.save(deletionCustomer)
await manager.insert(CustomerGroup, {
id: "customer-group-1",
name: "vip-customers",
})
await manager.insert(CustomerGroup, {
id: "customer-group-2",
name: "test-group-2",
metadata: { data1: "value1" },
})
await manager.insert(CustomerGroup, {
id: "customer-group-3",
name: "test-group-3",
})
await manager.insert(CustomerGroup, {
id: "test-group-4",
name: "test-group-4",
})
const c_group_5 = manager.create(CustomerGroup, {
id: "test-group-5",
name: "test-group-5",
})
await manager.save(c_group_5)
const c_group_6 = manager.create(CustomerGroup, {
id: "test-group-6",
name: "test-group-6",
})
await manager.save(c_group_6)
customer5.groups = [c_group_5]
await manager.save(customer5)
customer6.groups = [c_group_5]
await manager.save(customer6)
customer7.groups = [c_group_5, c_group_6]
await manager.save(customer7)
const c_group_delete = manager.create(CustomerGroup, {
id: "test-group-delete",
name: "test-group-delete",
})
await manager.save(c_group_delete)
deletionCustomer.groups = [c_group_delete]
await manager.save(deletionCustomer)
}
+17
View File
@@ -40,3 +40,20 @@ export const getProductFixture = (
],
...(overrides ?? {}),
})
export const getPricelistFixture = (overrides: Partial<any>) => {
return {
// BREAKING: `name` field was renamed to `title`
title: "Winter sales",
description: "Winter sale. 25% off selected items.",
type: "sale",
status: "active",
starts_at: "2022-07-01T00:00:00.000Z",
ends_at: "2022-07-31T00:00:00.000Z",
// BREAKING: There is no explicit customer_groups field in v2, we use rules instead
// BREAKING: Variant ID is required in prices
// BREAKING: Currency code is required in prices
prices: [],
...overrides,
}
}
@@ -1,101 +0,0 @@
const { ProductVariantMoneyAmount } = require("@medusajs/medusa")
const { Region, PriceList, MoneyAmount } = require("@medusajs/medusa")
module.exports = async (dataSource, data = {}) => {
const manager = dataSource.manager
const priceListNoCustomerGroups = manager.create(PriceList, {
id: "pl_no_customer_groups",
name: "VIP winter sale",
description: "Winter sale for VIP customers. 25% off selected items.",
type: "sale",
status: "active",
starts_at: "2022-07-01T00:00:00.000Z",
ends_at: "2022-07-31T00:00:00.000Z",
})
await manager.save(priceListNoCustomerGroups)
await manager.insert(Region, {
id: "region-pl",
name: "Test Region",
currency_code: "eur",
tax_rate: 0,
})
const moneyAmount1 = manager.create(MoneyAmount, {
id: "ma_test_1",
amount: 100,
currency_code: "usd",
min_quantity: 1,
max_quantity: 100,
price_list_id: "pl_no_customer_groups",
})
await manager.save(moneyAmount1)
const moneyAmount2 = manager.create(MoneyAmount, {
id: "ma_test_2",
amount: 80,
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
price_list_id: "pl_no_customer_groups",
})
await manager.save(moneyAmount2)
const moneyAmount3 = manager.create(MoneyAmount, {
id: "ma_test_3",
amount: 50,
currency_code: "usd",
min_quantity: 501,
max_quantity: 1000,
price_list_id: "pl_no_customer_groups",
})
await manager.save(moneyAmount3)
const moneyAmount4 = manager.create(MoneyAmount, {
id: "ma_test_4",
amount: 70,
currency_code: "usd",
})
await manager.save(moneyAmount4)
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma1-pl",
money_amount_id: "ma_test_1",
variant_id: "test-variant",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma2-pl",
money_amount_id: "ma_test_2",
variant_id: "test-variant",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma3-pl",
money_amount_id: "ma_test_3",
variant_id: "test-variant",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma4-pl",
money_amount_id: "ma_test_4",
variant_id: "test-variant",
})
const priceListWithMA = manager.create(PriceList, {
id: "pl_with_some_ma",
name: "Weeken sale",
description: "Desc. of the list",
type: "sale",
status: "active",
starts_at: "2022-07-01T00:00:00.000Z",
ends_at: "2022-07-31T00:00:00.000Z",
})
priceListWithMA.prices = [moneyAmount4]
await manager.save(priceListWithMA)
}
@@ -1,84 +0,0 @@
const {
Region,
ShippingProfile,
ShippingOption,
ShippingOptionRequirement,
ShippingProfileType,
} = require("@medusajs/medusa")
module.exports = async (dataSource, data = {}) => {
const manager = dataSource.manager
await manager.insert(Region, {
id: "region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
const defaultProfile = await manager.findOne(ShippingProfile, {
where: { type: ShippingProfileType.DEFAULT },
})
await manager.insert(ShippingOption, {
id: "test-out",
name: "Test out",
profile_id: defaultProfile.id,
region_id: "region",
provider_id: "test-ful",
data: {},
price_type: "flat_rate",
amount: 2000,
is_return: false,
})
await manager.insert(ShippingOption, {
id: "test-option-req",
name: "With req",
profile_id: defaultProfile.id,
region_id: "region",
provider_id: "test-ful",
data: {},
price_type: "flat_rate",
amount: 2000,
is_return: false,
})
await manager.insert(ShippingOption, {
id: "test-option-req-admin-only",
name: "With req",
profile_id: defaultProfile.id,
region_id: "region",
admin_only: true,
provider_id: "test-ful",
data: {},
price_type: "flat_rate",
amount: 2000,
is_return: false,
})
await manager.insert(ShippingOption, {
id: "test-option-req-return",
name: "With req",
profile_id: defaultProfile.id,
region_id: "region",
is_return: true,
provider_id: "test-ful",
data: {},
price_type: "flat_rate",
amount: 2000,
})
await manager.insert(ShippingOptionRequirement, {
id: "option-req",
shipping_option_id: "test-option-req",
type: "min_subtotal",
amount: 5,
})
await manager.insert(ShippingOptionRequirement, {
id: "option-req-2",
shipping_option_id: "test-option-req",
type: "max_subtotal",
amount: 10,
})
}