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
@@ -16,13 +16,8 @@ medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/promotions", () => {
let appContainer
let promotionModuleService: IPromotionModuleService
beforeAll(async () => {
appContainer = getContainer()
promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION
)
})
beforeEach(async () => {
@@ -29,7 +29,7 @@ medusaIntegrationTestRunner({
})
it("should delete promotion successfully", async () => {
const createdPromotion = await promotionModuleService.create({
const createdPromotion = await promotionModuleService.createPromotions({
code: "TEST",
type: "standard",
application_method: {
@@ -47,7 +47,7 @@ medusaIntegrationTestRunner({
expect(deleteRes.status).toEqual(200)
const promotions = await promotionModuleService.list({
const promotions = await promotionModuleService.listPromotions({
id: [createdPromotion.id],
})
@@ -30,7 +30,7 @@ medusaIntegrationTestRunner({
})
it("should get all promotions and its count", async () => {
await promotionModuleService.create([
await promotionModuleService.createPromotions([
{
code: "TEST",
type: PromotionType.STANDARD,
@@ -69,7 +69,7 @@ medusaIntegrationTestRunner({
})
it("should support search of promotions", async () => {
await promotionModuleService.create([
await promotionModuleService.createPromotions([
{
code: "first",
type: PromotionType.STANDARD,
@@ -103,7 +103,7 @@ medusaIntegrationTestRunner({
})
it("should get all promotions and its count filtered", async () => {
await promotionModuleService.create([
await promotionModuleService.createPromotions([
{
code: "TEST",
type: PromotionType.STANDARD,
@@ -47,7 +47,7 @@ medusaIntegrationTestRunner({
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders, appContainer)
standardPromotion = await promotionModule.create({
standardPromotion = await promotionModule.createPromotions({
code: "TEST_ACROSS",
type: PromotionType.STANDARD,
application_method: {
@@ -322,7 +322,7 @@ medusaIntegrationTestRunner({
})
it("should add buy rules to a buyget promotion successfully", async () => {
const buyGetPromotion = await promotionModule.create({
const buyGetPromotion = await promotionModule.createPromotions({
code: "TEST_BUYGET",
type: PromotionType.BUYGET,
application_method: {
@@ -414,7 +414,7 @@ medusaIntegrationTestRunner({
deleted: true,
})
const promotion = await promotionModule.retrieve(
const promotion = await promotionModule.retrievePromotion(
standardPromotion.id,
{ relations: ["rules"] }
)
@@ -455,7 +455,7 @@ medusaIntegrationTestRunner({
deleted: true,
})
const promotion = await promotionModule.retrieve(
const promotion = await promotionModule.retrievePromotion(
standardPromotion.id,
{ relations: ["application_method.target_rules"] }
)
@@ -482,7 +482,7 @@ medusaIntegrationTestRunner({
})
it("should remove buy rules from a promotion successfully", async () => {
const buyGetPromotion = await promotionModule.create({
const buyGetPromotion = await promotionModule.createPromotions({
code: "TEST_BUYGET",
type: PromotionType.BUYGET,
application_method: {
@@ -513,9 +513,12 @@ medusaIntegrationTestRunner({
deleted: true,
})
const promotion = await promotionModule.retrieve(buyGetPromotion.id, {
relations: ["application_method.buy_rules"],
})
const promotion = await promotionModule.retrievePromotion(
buyGetPromotion.id,
{
relations: ["application_method.buy_rules"],
}
)
expect(promotion.application_method!.buy_rules!.length).toEqual(0)
})
@@ -731,7 +734,7 @@ medusaIntegrationTestRunner({
})
it("should return all values based on rule types", async () => {
const [region1, region2] = await regionService.create([
const [region1, region2] = await regionService.createRegions([
{ name: "North America", currency_code: "usd" },
{ name: "Europe", currency_code: "eur" },
])
@@ -770,7 +773,7 @@ medusaIntegrationTestRunner({
])
)
const group = await customerService.createCustomerGroup({
const group = await customerService.createCustomerGroups({
name: "VIP",
})
@@ -787,7 +790,7 @@ medusaIntegrationTestRunner({
},
])
const salesChannel = await salesChannelService.create({
const salesChannel = await salesChannelService.createSalesChannels({
name: "Instagram",
})
@@ -826,7 +829,7 @@ medusaIntegrationTestRunner({
])
)
const [product1, product2] = await productService.create([
const [product1, product2] = await productService.createProducts([
{ title: "test product 1" },
{ title: "test product 2" },
])
@@ -845,7 +848,7 @@ medusaIntegrationTestRunner({
])
)
const category = await productService.createCategory({
const category = await productService.createProductCategories({
name: "test category 1",
parent_category_id: null,
})
@@ -860,7 +863,7 @@ medusaIntegrationTestRunner({
{ label: "test category 1", value: category.id },
])
const collection = await productService.createCollections({
const collection = await productService.createProductCollections({
title: "test collection 1",
})
@@ -874,7 +877,7 @@ medusaIntegrationTestRunner({
{ label: "test collection 1", value: collection.id },
])
const type = await productService.createTypes({
const type = await productService.createProductTypes({
value: "test type",
})
@@ -888,7 +891,7 @@ medusaIntegrationTestRunner({
{ label: "test type", value: type.id },
])
const [tag1, tag2] = await productService.createTags([
const [tag1, tag2] = await productService.createProductTags([
{ value: "test tag 1" },
{ value: "test tag 2" },
])
@@ -41,7 +41,7 @@ medusaIntegrationTestRunner({
})
it("should get the requested promotion by id or codde", async () => {
const createdPromotion = await promotionModuleService.create({
const createdPromotion = await promotionModuleService.createPromotions({
code: "TEST",
type: PromotionType.STANDARD,
application_method: {
@@ -78,7 +78,7 @@ medusaIntegrationTestRunner({
})
it("should get the requested promotion with filtered fields and relations", async () => {
const createdPromotion = await promotionModuleService.create({
const createdPromotion = await promotionModuleService.createPromotions({
code: "TEST",
type: PromotionType.STANDARD,
application_method: {
@@ -45,7 +45,7 @@ medusaIntegrationTestRunner({
})
it("should throw an error when both campaign and campaign_id params are passed", async () => {
const createdPromotion = await promotionModuleService.create({
const createdPromotion = await promotionModuleService.createPromotions({
code: "TEST",
type: PromotionType.STANDARD,
is_automatic: true,
@@ -79,7 +79,7 @@ medusaIntegrationTestRunner({
})
it("should update a promotion successfully", async () => {
const createdPromotion = await promotionModuleService.create({
const createdPromotion = await promotionModuleService.createPromotions({
code: "TEST",
type: PromotionType.STANDARD,
is_automatic: true,
@@ -117,7 +117,7 @@ medusaIntegrationTestRunner({
})
it("should update a buyget promotion successfully", async () => {
const createdPromotion = await promotionModuleService.create({
const createdPromotion = await promotionModuleService.createPromotions({
code: "PROMOTION_TEST",
type: PromotionType.BUYGET,
application_method: {