Chore/rm main entity concept (#7709)

**What**
Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate.
This pr also includes various fixes in different modules

Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2024-06-19 13:02:16 +00:00
committed by GitHub
co-authored by Stevche Radevski Oli Juhl
parent 2895ccfba8
commit 48963f55ef
533 changed files with 6469 additions and 9769 deletions
@@ -40,48 +40,50 @@ medusaIntegrationTestRunner({
describe("POST /store/carts/:id/promotions", () => {
it("should add line item adjustments to a cart based on promotions", async () => {
const appliedPromotion = await promotionModuleService.create({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_tshirt",
},
],
},
})
const appliedPromotion =
await promotionModuleService.createPromotions({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_tshirt",
},
],
},
})
const createdPromotion = await promotionModuleService.create({
code: "PROMOTION_TEST",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "across",
value: "1000",
apply_to_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_mat",
},
],
},
})
const createdPromotion =
await promotionModuleService.createPromotions({
code: "PROMOTION_TEST",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "across",
value: "1000",
apply_to_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_mat",
},
],
},
})
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "usd",
items: [
// Adjustment to add
@@ -152,41 +154,42 @@ medusaIntegrationTestRunner({
})
it("should add shipping method adjustments to a cart based on promotions", async () => {
const [appliedPromotion] = await promotionModuleService.create([
{
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
rules: [
{
attribute: "customer_id",
operator: "in",
values: ["cus_test"],
},
{
attribute: "currency_code",
operator: "in",
values: ["eur"],
},
],
application_method: {
type: "fixed",
target_type: "shipping_methods",
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
const [appliedPromotion] =
await promotionModuleService.createPromotions([
{
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
rules: [
{
attribute: "name",
attribute: "customer_id",
operator: "in",
values: ["express"],
values: ["cus_test"],
},
{
attribute: "currency_code",
operator: "in",
values: ["eur"],
},
],
application_method: {
type: "fixed",
target_type: "shipping_methods",
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "name",
operator: "in",
values: ["express"],
},
],
},
},
},
])
])
const [newPromotion] = await promotionModuleService.create([
const [newPromotion] = await promotionModuleService.createPromotions([
{
code: "PROMOTION_NEW",
type: PromotionType.STANDARD,
@@ -220,7 +223,7 @@ medusaIntegrationTestRunner({
},
])
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "eur",
customer_id: "cus_test",
items: [
@@ -18,13 +18,13 @@ import {
ICartModuleService,
ICustomerModuleService,
IFulfillmentModuleService,
IInventoryServiceNext,
IInventoryService,
IPaymentModuleService,
IPricingModuleService,
IProductModuleService,
IRegionModuleService,
ISalesChannelModuleService,
IStockLocationServiceNext,
IStockLocationService,
} from "@medusajs/types"
import { ContainerRegistrationKeys, RuleOperator } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
@@ -50,10 +50,9 @@ medusaIntegrationTestRunner({
let productModule: IProductModuleService
let pricingModule: IPricingModuleService
let paymentModule: IPaymentModuleService
let inventoryModule: IInventoryServiceNext
let stockLocationModule: IStockLocationServiceNext
let stockLocationModule: IStockLocationService
let inventoryModule: IInventoryService
let fulfillmentModule: IFulfillmentModuleService
let locationModule: IStockLocationServiceNext
let remoteLink, remoteQuery
let defaultRegion
@@ -78,9 +77,6 @@ medusaIntegrationTestRunner({
fulfillmentModule = appContainer.resolve(
ModuleRegistrationName.FULFILLMENT
)
locationModule = appContainer.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
remoteQuery = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_QUERY
@@ -97,20 +93,20 @@ medusaIntegrationTestRunner({
describe("CreateCartWorkflow", () => {
it("should create a cart", async () => {
const region = await regionModuleService.create({
const region = await regionModuleService.createRegions({
name: "US",
currency_code: "usd",
})
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -121,7 +117,7 @@ medusaIntegrationTestRunner({
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -134,7 +130,7 @@ medusaIntegrationTestRunner({
},
])
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -185,7 +181,7 @@ medusaIntegrationTestRunner({
},
})
const cart = await cartModuleService.retrieve(result.id, {
const cart = await cartModuleService.retrieveCart(result.id, {
relations: ["items"],
})
@@ -207,20 +203,20 @@ medusaIntegrationTestRunner({
})
it("should revert if the cart creation fails", async () => {
const region = await regionModuleService.create({
const region = await regionModuleService.createRegions({
name: "US",
currency_code: "usd",
})
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -231,7 +227,7 @@ medusaIntegrationTestRunner({
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -244,7 +240,7 @@ medusaIntegrationTestRunner({
},
])
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -314,7 +310,7 @@ medusaIntegrationTestRunner({
})
it("should throw when no regions exist", async () => {
await regionModuleService.delete(defaultRegion.id)
await regionModuleService.deleteRegions(defaultRegion.id)
const { errors } = await createCartWorkflow(appContainer).run({
input: {
@@ -332,15 +328,15 @@ medusaIntegrationTestRunner({
})
it("should throw if variants are out of stock", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -379,12 +375,12 @@ medusaIntegrationTestRunner({
adminHeaders
)
const region = await regionModuleService.create({
const region = await regionModuleService.createRegions({
name: "US",
currency_code: "usd",
})
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -448,7 +444,7 @@ medusaIntegrationTestRunner({
})
it("should throw if sales channel is disabled", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
is_disabled: true,
})
@@ -500,7 +496,7 @@ medusaIntegrationTestRunner({
},
])
const customers = await customerModule.list({
const customers = await customerModule.listCustomers({
email: "tony@stark-industries.com",
})
@@ -517,7 +513,7 @@ medusaIntegrationTestRunner({
},
})
const customer = await customerModule.create({
const customer = await customerModule.createCustomers({
email: "tony@stark-industries.com",
})
@@ -539,7 +535,7 @@ medusaIntegrationTestRunner({
},
])
const customers = await customerModule.list({
const customers = await customerModule.listCustomers({
email: "tony@stark-industries.com",
})
@@ -550,20 +546,20 @@ medusaIntegrationTestRunner({
describe("AddToCartWorkflow", () => {
it("should add item to cart", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
let cart = await cartModuleService.create({
let cart = await cartModuleService.createCarts({
currency_code: "usd",
sales_channel_id: salesChannel.id,
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -574,7 +570,7 @@ medusaIntegrationTestRunner({
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -587,7 +583,7 @@ medusaIntegrationTestRunner({
},
])
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -623,7 +619,7 @@ medusaIntegrationTestRunner({
},
])
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id", "region_id", "currency_code", "sales_channel_id"],
})
@@ -639,7 +635,7 @@ medusaIntegrationTestRunner({
},
})
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
relations: ["items"],
})
@@ -659,20 +655,20 @@ medusaIntegrationTestRunner({
})
it("should throw if no price sets for variant exist", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
let cart = await cartModuleService.create({
let cart = await cartModuleService.createCarts({
currency_code: "usd",
sales_channel_id: salesChannel.id,
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -683,7 +679,7 @@ medusaIntegrationTestRunner({
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -742,7 +738,7 @@ medusaIntegrationTestRunner({
})
it("should throw if variant does not exist", async () => {
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "usd",
})
@@ -774,15 +770,15 @@ medusaIntegrationTestRunner({
describe("updateLineItemInCartWorkflow", () => {
it("should update item in cart", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -793,7 +789,7 @@ medusaIntegrationTestRunner({
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -806,7 +802,7 @@ medusaIntegrationTestRunner({
},
])
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -842,7 +838,7 @@ medusaIntegrationTestRunner({
},
])
let cart = await cartModuleService.create({
let cart = await cartModuleService.createCarts({
currency_code: "usd",
sales_channel_id: salesChannel.id,
items: [
@@ -855,7 +851,7 @@ medusaIntegrationTestRunner({
],
})
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id", "region_id", "currency_code"],
relations: ["items", "items.variant_id", "items.metadata"],
})
@@ -901,15 +897,15 @@ medusaIntegrationTestRunner({
},
})
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -920,7 +916,7 @@ medusaIntegrationTestRunner({
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -933,7 +929,7 @@ medusaIntegrationTestRunner({
},
])
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -969,7 +965,7 @@ medusaIntegrationTestRunner({
},
])
let cart = await cartModuleService.create({
let cart = await cartModuleService.createCarts({
currency_code: "usd",
items: [
{
@@ -981,7 +977,7 @@ medusaIntegrationTestRunner({
],
})
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id", "region_id", "currency_code"],
relations: ["items", "items.variant_id", "items.metadata"],
})
@@ -1031,7 +1027,7 @@ medusaIntegrationTestRunner({
describe("deleteLineItems", () => {
it("should delete items in cart", async () => {
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "usd",
items: [
{
@@ -1072,7 +1068,7 @@ medusaIntegrationTestRunner({
},
})
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "usd",
items: [
{
@@ -1115,7 +1111,7 @@ medusaIntegrationTestRunner({
describe("createPaymentCollectionForCart", () => {
it("should create a payment collection and link it to cart", async () => {
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "dkk",
region_id: defaultRegion.id,
items: [
@@ -1181,12 +1177,12 @@ medusaIntegrationTestRunner({
}
)
const region = await regionModuleService.create({
const region = await regionModuleService.createRegions({
name: "US",
currency_code: "usd",
})
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "usd",
region_id: region.id,
items: [
@@ -1253,7 +1249,7 @@ medusaIntegrationTestRunner({
describe("refreshPaymentCollectionForCart", () => {
it("should refresh a payment collection for a cart", async () => {
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "dkk",
region_id: defaultRegion.id,
items: [
@@ -1320,12 +1316,12 @@ medusaIntegrationTestRunner({
describe("compensation", () => {
it("should revert payment collection amount and create a new payment session", async () => {
const region = await regionModuleService.create({
const region = await regionModuleService.createRegions({
name: "US",
currency_code: "usd",
})
const testCart = await cartModuleService.create({
const testCart = await cartModuleService.createCarts({
currency_code: "usd",
region_id: region.id,
items: [
@@ -1431,7 +1427,7 @@ medusaIntegrationTestRunner({
let priceSet
beforeEach(async () => {
cart = await cartModuleService.create({
cart = await cartModuleService.createCarts({
currency_code: "usd",
shipping_address: {
country_code: "us",
@@ -1444,7 +1440,7 @@ medusaIntegrationTestRunner({
type: "default",
})
fulfillmentSet = await fulfillmentModule.create({
fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -1455,7 +1451,7 @@ medusaIntegrationTestRunner({
],
})
priceSet = await pricingModule.create({
priceSet = await pricingModule.createPriceSets({
prices: [{ amount: 3000, currency_code: "usd" }],
})
})
@@ -1500,7 +1496,7 @@ medusaIntegrationTestRunner({
},
})
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
relations: ["shipping_methods"],
})
@@ -1592,15 +1588,15 @@ medusaIntegrationTestRunner({
describe("listShippingOptionsForCartWorkflow", () => {
it("should list shipping options for cart", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await locationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Europe",
})
let cart = await cartModuleService.create({
let cart = await cartModuleService.createCarts({
currency_code: "usd",
sales_channel_id: salesChannel.id,
shipping_address: {
@@ -1616,7 +1612,7 @@ medusaIntegrationTestRunner({
type: "default",
})
const fulfillmentSet = await fulfillmentModule.create({
const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -1645,7 +1641,7 @@ medusaIntegrationTestRunner({
},
})
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -1681,7 +1677,7 @@ medusaIntegrationTestRunner({
},
])
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id"],
relations: ["shipping_address"],
})
@@ -1711,15 +1707,15 @@ medusaIntegrationTestRunner({
})
it("should list no shipping options for cart, if sales channel is not associated with location", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await locationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Europe",
})
let cart = await cartModuleService.create({
let cart = await cartModuleService.createCarts({
currency_code: "usd",
sales_channel_id: salesChannel.id,
shipping_address: {
@@ -1735,7 +1731,7 @@ medusaIntegrationTestRunner({
type: "default",
})
const fulfillmentSet = await fulfillmentModule.create({
const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -1764,7 +1760,7 @@ medusaIntegrationTestRunner({
},
})
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [
{
amount: 3000,
@@ -1792,7 +1788,7 @@ medusaIntegrationTestRunner({
},
])
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id"],
relations: ["shipping_address"],
})
@@ -1816,15 +1812,15 @@ medusaIntegrationTestRunner({
})
it("should throw when shipping options are missing prices", async () => {
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await locationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Europe",
})
let cart = await cartModuleService.create({
let cart = await cartModuleService.createCarts({
currency_code: "usd",
sales_channel_id: salesChannel.id,
shipping_address: {
@@ -1840,7 +1836,7 @@ medusaIntegrationTestRunner({
type: "default",
})
const fulfillmentSet = await fulfillmentModule.create({
const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -1888,7 +1884,7 @@ medusaIntegrationTestRunner({
},
])
cart = await cartModuleService.retrieve(cart.id, {
cart = await cartModuleService.retrieveCart(cart.id, {
select: ["id"],
relations: ["shipping_address"],
})
@@ -98,16 +98,16 @@ medusaIntegrationTestRunner({
describe("POST /store/carts", () => {
it("should create a cart", async () => {
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Webshop",
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -123,7 +123,7 @@ medusaIntegrationTestRunner({
},
])
const [priceSet, priceSetTwo] = await pricingModule.create([
const [priceSet, priceSetTwo] = await pricingModule.createPriceSets([
{
prices: [
{
@@ -209,7 +209,7 @@ medusaIntegrationTestRunner({
it("should create cart with customer from email and tax lines", async () => {
await setupTaxStructure(taxModule)
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product default tax",
variants: [
@@ -218,11 +218,11 @@ medusaIntegrationTestRunner({
},
])
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Webshop",
})
const [priceSet] = await pricingModule.create([
const [priceSet] = await pricingModule.createPriceSets([
{ prices: [{ amount: 3000, currency_code: "usd" }] },
])
@@ -281,7 +281,7 @@ medusaIntegrationTestRunner({
})
it("should create cart with any region", async () => {
await regionModule.create({
await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
@@ -305,11 +305,11 @@ medusaIntegrationTestRunner({
})
it("should create cart with default store sales channel", async () => {
const sc = await scModule.create({
const sc = await scModule.createSalesChannels({
name: "Webshop",
})
await storeService.update(store.id, {
await storeService.updateStores(store.id, {
default_sales_channel_id: sc.id,
})
@@ -330,7 +330,7 @@ medusaIntegrationTestRunner({
})
it("should create cart with region currency code", async () => {
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
@@ -381,15 +381,15 @@ medusaIntegrationTestRunner({
})
it("throws if publishable key is not associated with sales channel", async () => {
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Retail Store",
})
const salesChannel2 = await scModule.create({
const salesChannel2 = await scModule.createSalesChannels({
name: "Webshop",
})
const pubKey = await apiKeyModule.create({
const pubKey = await apiKeyModule.createApiKeys({
title: "Test key",
type: "publishable",
created_by: "test",
@@ -426,15 +426,15 @@ medusaIntegrationTestRunner({
})
it("throws if publishable key has multiple associated sales channels", async () => {
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Retail Store",
})
const salesChannel2 = await scModule.create({
const salesChannel2 = await scModule.createSalesChannels({
name: "Webshop",
})
const pubKey = await apiKeyModule.create({
const pubKey = await apiKeyModule.createApiKeys({
title: "Test key",
type: "publishable",
created_by: "test",
@@ -469,11 +469,11 @@ medusaIntegrationTestRunner({
})
it("should create cart with sales channel if pub key does not have any scopes defined", async () => {
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Retail Store",
})
const pubKey = await apiKeyModule.create({
const pubKey = await apiKeyModule.createApiKeys({
title: "Test key",
type: "publishable",
created_by: "test",
@@ -498,11 +498,11 @@ medusaIntegrationTestRunner({
})
it("should create cart with sales channel associated with pub key", async () => {
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Retail Store",
})
const pubKey = await apiKeyModule.create({
const pubKey = await apiKeyModule.createApiKeys({
title: "Test key",
type: "publishable",
created_by: "test",
@@ -545,7 +545,7 @@ medusaIntegrationTestRunner({
it("should update a cart with promo codes with a replace action", async () => {
await setupTaxStructure(taxModule)
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
@@ -558,7 +558,7 @@ medusaIntegrationTestRunner({
},
]
const appliedPromotion = await promotionModule.create({
const appliedPromotion = await promotionModule.createPromotions({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
application_method: {
@@ -573,7 +573,7 @@ medusaIntegrationTestRunner({
},
})
const createdPromotion = await promotionModule.create({
const createdPromotion = await promotionModule.createPromotions({
code: "PROMOTION_TEST",
type: PromotionType.STANDARD,
application_method: {
@@ -587,7 +587,7 @@ medusaIntegrationTestRunner({
},
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
email: "tony@stark.com",
region_id: region.id,
@@ -686,13 +686,13 @@ medusaIntegrationTestRunner({
it("should not generate tax lines if region is not present or automatic taxes is false", async () => {
await setupTaxStructure(taxModule)
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
automatic_taxes: false,
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
email: "tony@stark.com",
shipping_address: {
@@ -732,7 +732,7 @@ medusaIntegrationTestRunner({
})
)
await cartModule.update(cart.id, {
await cartModule.updateCarts(cart.id, {
region_id: region.id,
})
@@ -758,16 +758,16 @@ medusaIntegrationTestRunner({
it("should update a cart's region, sales channel, customer data and tax lines", async () => {
await setupTaxStructure(taxModule)
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "us",
currency_code: "usd",
})
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Webshop",
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "eur",
email: "tony@stark.com",
shipping_address: {
@@ -795,7 +795,7 @@ medusaIntegrationTestRunner({
type: "default",
})
const fulfillmentSet = await fulfillmentModule.create({
const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -967,12 +967,12 @@ medusaIntegrationTestRunner({
it("should remove invalid shipping methods", async () => {
await setupTaxStructure(taxModule)
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
region_id: region.id,
currency_code: "eur",
email: "tony@stark.com",
@@ -992,7 +992,7 @@ medusaIntegrationTestRunner({
type: "default",
})
const fulfillmentSet = await fulfillmentModule.create({
const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -1101,12 +1101,12 @@ medusaIntegrationTestRunner({
describe("POST /store/carts/:id", () => {
it("should create and update a cart", async () => {
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Webshop",
})
@@ -1151,16 +1151,16 @@ medusaIntegrationTestRunner({
describe("GET /store/carts", () => {
it("should get cart", async () => {
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Webshop",
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
items: [
{
@@ -1250,22 +1250,22 @@ medusaIntegrationTestRunner({
beforeEach(async () => {
await setupTaxStructure(taxModule)
region = await regionModule.create({
region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
})
it("should add item to cart", async () => {
const customer = await customerModule.create({
const customer = await customerModule.createCustomers({
email: "tony@stark-industries.com",
})
const salesChannel = await scModule.create({
const salesChannel = await scModule.createSalesChannels({
name: "Webshop",
})
const [productWithSpecialTax] = await productModule.create([
const [productWithSpecialTax] = await productModule.createProducts([
{
// This product ID is setup in the tax structure fixture (setupTaxStructure)
id: "product_id_1",
@@ -1274,7 +1274,7 @@ medusaIntegrationTestRunner({
} as any,
])
const [productWithDefaultTax] = await productModule.create([
const [productWithDefaultTax] = await productModule.createProducts([
{
title: "Test product default tax",
variants: [
@@ -1283,7 +1283,7 @@ medusaIntegrationTestRunner({
},
])
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
customer_id: customer.id,
sales_channel_id: salesChannel.id,
@@ -1308,7 +1308,7 @@ medusaIntegrationTestRunner({
],
})
const appliedPromotion = await promotionModule.create({
const appliedPromotion = await promotionModule.createPromotions({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
application_method: {
@@ -1337,14 +1337,15 @@ medusaIntegrationTestRunner({
},
])
const [priceSet, priceSetDefaultTax] = await pricingModule.create([
{
prices: [{ amount: 3000, currency_code: "usd" }],
},
{
prices: [{ amount: 2000, currency_code: "usd" }],
},
])
const [priceSet, priceSetDefaultTax] =
await pricingModule.createPriceSets([
{
prices: [{ amount: 3000, currency_code: "usd" }],
},
{
prices: [{ amount: 2000, currency_code: "usd" }],
},
])
await remoteLink.create([
{
@@ -1520,12 +1521,12 @@ medusaIntegrationTestRunner({
describe("POST /store/payment-collections", () => {
it("should create a payment collection for the cart", async () => {
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
region_id: region.id,
})
@@ -1547,12 +1548,12 @@ medusaIntegrationTestRunner({
})
it("should return an existing payment collection for the cart", async () => {
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
region_id: region.id,
})
@@ -1580,17 +1581,17 @@ medusaIntegrationTestRunner({
})
it("should create a new payment collection for a new cart", async () => {
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
})
const firstCart = await cartModule.create({
const firstCart = await cartModule.createCarts({
currency_code: "usd",
region_id: region.id,
})
const secondCart = await cartModule.create({
const secondCart = await cartModule.createCarts({
currency_code: "usd",
region_id: region.id,
})
@@ -1622,13 +1623,13 @@ medusaIntegrationTestRunner({
it("should update a carts tax lines when region.automatic_taxes is false", async () => {
await setupTaxStructure(taxModule)
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
automatic_taxes: false,
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
region_id: region.id,
shipping_address: {
@@ -1679,13 +1680,13 @@ medusaIntegrationTestRunner({
it("should throw error when shipping is not present", async () => {
await setupTaxStructure(taxModule)
const region = await regionModule.create({
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
automatic_taxes: false,
})
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
region_id: region.id,
items: [
@@ -1713,7 +1714,7 @@ medusaIntegrationTestRunner({
describe("POST /store/carts/:id/shipping-methods", () => {
it("should add a shipping methods to a cart", async () => {
const cart = await cartModule.create({
const cart = await cartModule.createCarts({
currency_code: "usd",
shipping_address: { country_code: "us" },
items: [],
@@ -1725,7 +1726,7 @@ medusaIntegrationTestRunner({
type: "default",
})
const fulfillmentSet = await fulfillmentModule.create({
const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -1736,7 +1737,7 @@ medusaIntegrationTestRunner({
],
})
const priceSet = await pricingModule.create({
const priceSet = await pricingModule.createPriceSets({
prices: [{ amount: 3000, currency_code: "usd" }],
})
@@ -1809,7 +1810,7 @@ medusaIntegrationTestRunner({
beforeEach(async () => {
await setupTaxStructure(taxModule)
region = await regionService.create({
region = await regionService.createRegions({
name: "Test region",
countries: ["US"],
currency_code: "usd",
@@ -1861,7 +1862,7 @@ medusaIntegrationTestRunner({
type: "default",
})
fulfillmentSet = await fulfillmentModule.create({
fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
name: "Test",
type: "test-type",
service_zones: [
@@ -40,49 +40,51 @@ medusaIntegrationTestRunner({
describe("DELETE /store/carts/:id/promotions", () => {
it("should remove line item adjustments from a cart based on promotions", async () => {
const appliedPromotion = await promotionModuleService.create({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_tshirt",
},
],
},
})
const appliedPromotion =
await promotionModuleService.createPromotions({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_tshirt",
},
],
},
})
const appliedPromotionToRemove = await promotionModuleService.create({
code: "PROMOTION_APPLIED_TO_REMOVE",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_tshirt",
},
],
},
})
const appliedPromotionToRemove =
await promotionModuleService.createPromotions({
code: "PROMOTION_APPLIED_TO_REMOVE",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: "prod_tshirt",
},
],
},
})
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "usd",
items: [
{
@@ -170,71 +172,73 @@ medusaIntegrationTestRunner({
})
it("should add shipping method adjustments to a cart based on promotions", async () => {
const appliedPromotion = await promotionModuleService.create({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
rules: [
{
attribute: "customer_id",
operator: "in",
values: ["cus_test"],
},
{
attribute: "currency_code",
operator: "in",
values: ["eur"],
},
],
application_method: {
type: "fixed",
target_type: "shipping_methods",
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
const appliedPromotion =
await promotionModuleService.createPromotions({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
rules: [
{
attribute: "name",
attribute: "customer_id",
operator: "in",
values: ["express"],
values: ["cus_test"],
},
{
attribute: "currency_code",
operator: "in",
values: ["eur"],
},
],
},
})
application_method: {
type: "fixed",
target_type: "shipping_methods",
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "name",
operator: "in",
values: ["express"],
},
],
},
})
const appliedPromotionToRemove = await promotionModuleService.create({
code: "PROMOTION_APPLIED_TO_REMOVE",
type: PromotionType.STANDARD,
rules: [
{
attribute: "customer_id",
operator: "in",
values: ["cus_test"],
},
{
attribute: "currency_code",
operator: "in",
values: ["eur"],
},
],
application_method: {
type: "fixed",
target_type: "shipping_methods",
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
const appliedPromotionToRemove =
await promotionModuleService.createPromotions({
code: "PROMOTION_APPLIED_TO_REMOVE",
type: PromotionType.STANDARD,
rules: [
{
attribute: "name",
attribute: "customer_id",
operator: "in",
values: ["express"],
values: ["cus_test"],
},
{
attribute: "currency_code",
operator: "in",
values: ["eur"],
},
],
},
})
application_method: {
type: "fixed",
target_type: "shipping_methods",
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "name",
operator: "in",
values: ["express"],
},
],
},
})
const cart = await cartModuleService.create({
const cart = await cartModuleService.createCarts({
currency_code: "eur",
customer_id: "cus_test",
items: [