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
@@ -1,20 +1,17 @@
import { Modules } from "@medusajs/modules-sdk"
import { IStoreModuleService } from "@medusajs/types"
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
import { moduleIntegrationTestRunner } from "medusa-test-utils"
import { createStoreFixture } from "../__fixtures__"
jest.setTimeout(100000)
moduleIntegrationTestRunner({
moduleIntegrationTestRunner<IStoreModuleService>({
moduleName: Modules.STORE,
testSuite: ({
MikroOrmWrapper,
service,
}: SuiteOptions<IStoreModuleService>) => {
testSuite: ({ service }) => {
describe("Store Module Service", () => {
describe("creating a store", () => {
it("should get created successfully", async function () {
const store = await service.create(createStoreFixture)
const store = await service.createStores(createStoreFixture)
expect(store).toEqual(
expect.objectContaining({
@@ -32,7 +29,7 @@ moduleIntegrationTestRunner({
it("should fail to get created if default currency code is not in list of supported currency codes", async function () {
const err = await service
.create({ ...createStoreFixture, default_currency_code: "jpy" })
.createStores({ ...createStoreFixture, default_currency_code: "jpy" })
.catch((err) => err.message)
expect(err).toEqual("Store does not have currency: jpy")
@@ -40,7 +37,7 @@ moduleIntegrationTestRunner({
describe("upserting a store", () => {
it("should get created if it does not exist", async function () {
const store = await service.upsert(createStoreFixture)
const store = await service.upsertStores(createStoreFixture)
expect(store).toEqual(
expect.objectContaining({
@@ -55,8 +52,10 @@ moduleIntegrationTestRunner({
})
it("should get created if it does not exist", async function () {
const createdStore = await service.upsert(createStoreFixture)
const upsertedStore = await service.upsert({ name: "Upserted store" })
const createdStore = await service.upsertStores(createStoreFixture)
const upsertedStore = await service.upsertStores({
name: "Upserted store",
})
expect(upsertedStore).toEqual(
expect.objectContaining({
@@ -69,17 +68,17 @@ moduleIntegrationTestRunner({
describe("updating a store", () => {
it("should update the name successfully", async function () {
const createdStore = await service.create(createStoreFixture)
const updatedStore = await service.update(createdStore.id, {
title: "Updated store",
const createdStore = await service.createStores(createStoreFixture)
const updatedStore = await service.updateStores(createdStore.id, {
name: "Updated store",
})
expect(updatedStore.title).toEqual("Updated store")
expect(updatedStore.name).toEqual("Updated store")
})
it("should fail updating default currency code to an unsupported one", async function () {
const createdStore = await service.create(createStoreFixture)
const createdStore = await service.createStores(createStoreFixture)
const updateErr = await service
.update(createdStore.id, {
.updateStores(createdStore.id, {
default_currency_code: "jpy",
})
.catch((err) => err.message)
@@ -88,9 +87,9 @@ moduleIntegrationTestRunner({
})
it("should fail updating default currency code to an unsupported one if the supported currencies are also updated", async function () {
const createdStore = await service.create(createStoreFixture)
const createdStore = await service.createStores(createStoreFixture)
const updateErr = await service
.update(createdStore.id, {
.updateStores(createdStore.id, {
supported_currency_codes: ["mkd"],
default_currency_code: "jpy",
})
@@ -100,12 +99,12 @@ moduleIntegrationTestRunner({
})
it("should fail updating supported currencies if one of them is used as a default one", async function () {
const createdStore = await service.create({
const createdStore = await service.createStores({
...createStoreFixture,
default_currency_code: "eur",
})
const updateErr = await service
.update(createdStore.id, {
.updateStores(createdStore.id, {
supported_currency_codes: ["jpy"],
})
.catch((err) => err.message)
@@ -118,26 +117,26 @@ moduleIntegrationTestRunner({
describe("deleting a store", () => {
it("should successfully delete existing stores", async function () {
const createdStore = await service.create([
const createdStore = await service.createStores([
createStoreFixture,
createStoreFixture,
])
await service.delete([createdStore[0].id, createdStore[1].id])
await service.deleteStores([createdStore[0].id, createdStore[1].id])
const storeInDatabase = await service.list()
const storeInDatabase = await service.listStores()
expect(storeInDatabase).toHaveLength(0)
})
})
describe("retrieving a store", () => {
it("should successfully return all existing stores", async function () {
await service.create([
await service.createStores([
createStoreFixture,
{ ...createStoreFixture, name: "Another store" },
])
const storesInDatabase = await service.list()
const storesInDatabase = await service.listStores()
expect(storesInDatabase).toHaveLength(2)
expect(storesInDatabase.map((s) => s.name)).toEqual(
expect.arrayContaining(["Test store", "Another store"])