Feat(medusa-test-utils, authentication, customer, cart, payment, pricing, product, promotion): Add initModule util (#6200)
* use initModules instead of initialize when runnning auth module integration tests * rm unused module-config * correct db schema fix * update authentication integration tests w/ initModule * update cart integration tests w/ initModule * update customer integration tests w/ initModule * update payment integration tests w/ initModule * update pricing integration tests w/ initModule * update product integration tests w/ initModule * update promotion integration tests w/ initModule * add initModule to more product tests and return medusaApp from initModule * align moduleOptions naming * update dependencies
This commit is contained in:
@@ -1,33 +1,41 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
||||
import { initialize } from "../../../../src"
|
||||
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||
import { createAuthUsers } from "../../../__fixtures__/auth-user"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("AuthenticationModuleService - AuthProvider", () => {
|
||||
let service: IAuthenticationModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
await createAuthProviders(testManager)
|
||||
await createAuthUsers(testManager)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await MikroOrmWrapper.clearDatabase()
|
||||
})
|
||||
|
||||
@@ -3,27 +3,32 @@ import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||
import { createAuthUsers } from "../../../__fixtures__/auth-user"
|
||||
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
|
||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
||||
import { initialize } from "../../../../src"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("AuthenticationModuleService - AuthUser", () => {
|
||||
let service: IAuthenticationModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
await createAuthProviders(testManager)
|
||||
await createAuthUsers(testManager)
|
||||
})
|
||||
@@ -32,6 +37,10 @@ describe("AuthenticationModuleService - AuthUser", () => {
|
||||
await MikroOrmWrapper.clearDatabase()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
describe("listAuthUsers", () => {
|
||||
it("should list authUsers", async () => {
|
||||
const authUsers = await service.listAuthUsers()
|
||||
@@ -237,7 +246,7 @@ describe("AuthenticationModuleService - AuthUser", () => {
|
||||
{
|
||||
id: "test",
|
||||
provider_id: "manual",
|
||||
entity_id: "test"
|
||||
entity_id: "test",
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
|
||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||
import { initialize } from "../../../../src"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("AuthenticationModuleService - AuthProvider", () => {
|
||||
let service: IAuthenticationModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
if (service.__hooks?.onApplicationStart) {
|
||||
await service.__hooks.onApplicationStart()
|
||||
}
|
||||
@@ -33,6 +37,10 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
||||
MedusaModule.clearInstances()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
describe("listAuthProviders", () => {
|
||||
it("should list default AuthProviders registered by loaders", async () => {
|
||||
const authProviders = await service.listAuthProviders()
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
|
||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import Scrypt from "scrypt-kdf"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||
import { createAuthUsers } from "../../../__fixtures__/auth-user"
|
||||
import { initialize } from "../../../../src"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
const seedDefaultData = async (testManager) => {
|
||||
@@ -17,19 +17,27 @@ const seedDefaultData = async (testManager) => {
|
||||
describe("AuthenticationModuleService - AuthProvider", () => {
|
||||
let service: IAuthenticationModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
if(service.__hooks?.onApplicationStart) {
|
||||
if (service.__hooks?.onApplicationStart) {
|
||||
await service.__hooks.onApplicationStart()
|
||||
}
|
||||
})
|
||||
@@ -70,8 +78,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
||||
success: true,
|
||||
authUser: expect.objectContaining({
|
||||
entity_id: email,
|
||||
provider_metadata: {
|
||||
},
|
||||
provider_metadata: {},
|
||||
}),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
|
||||
export function getInitModuleConfig() {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_AUTHENTICATION_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const injectedDependencies = {}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.AUTHENTICATION]: {
|
||||
definition: ModulesDefinition[Modules.AUTHENTICATION],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
injectedDependencies,
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_AUTHENTICATION_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,32 @@
|
||||
import { ICartModuleService } from "@medusajs/types"
|
||||
import { CheckConstraintViolationException } from "@mikro-orm/core"
|
||||
import { initialize } from "../../../../src/initialize"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Cart Module Service", () => {
|
||||
let service: ICartModuleService
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.CART]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_CART_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
|
||||
export function getInitModuleConfig() {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_CART_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const injectedDependencies = {}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.CART]: {
|
||||
definition: ModulesDefinition[Modules.CART],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
injectedDependencies,
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_CART_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,31 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { initialize } from "../../../../src/initialize"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Customer Module Service", () => {
|
||||
let service: ICustomerModuleService
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.CUSTOMER]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_CUSTOMER_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
|
||||
export function getInitModuleConfig() {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_CUSTOMER_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const injectedDependencies = {}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.CUSTOMER]: {
|
||||
definition: ModulesDefinition[Modules.CUSTOMER],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
injectedDependencies,
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_CUSTOMER_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "workspace:^",
|
||||
"@medusajs/utils": "workspace:^",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"medusa-core-utils": "^1.2.1",
|
||||
|
||||
@@ -3,3 +3,4 @@ export { default as IdMap } from "./id-map"
|
||||
export * as JestUtils from "./jest"
|
||||
export { default as MockManager } from "./mock-manager"
|
||||
export { default as MockRepository } from "./mock-repository"
|
||||
export * from "./init-modules"
|
||||
|
||||
59
packages/medusa-test-utils/src/init-modules.ts
Normal file
59
packages/medusa-test-utils/src/init-modules.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { knex } from "knex"
|
||||
import {
|
||||
MedusaApp,
|
||||
MedusaModule,
|
||||
MedusaModuleConfig,
|
||||
ModuleJoinerConfig,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
|
||||
interface InitModulesOptions {
|
||||
injectedDependencies?: Record<string, unknown>
|
||||
databaseConfig: {
|
||||
clientUrl: string
|
||||
schema?: string
|
||||
}
|
||||
modulesConfig: MedusaModuleConfig
|
||||
joinerConfig?: ModuleJoinerConfig[]
|
||||
}
|
||||
|
||||
export async function initModules({
|
||||
injectedDependencies,
|
||||
databaseConfig,
|
||||
modulesConfig,
|
||||
joinerConfig,
|
||||
}: InitModulesOptions) {
|
||||
injectedDependencies ??= {}
|
||||
|
||||
let sharedPgConnection =
|
||||
injectedDependencies?.[ContainerRegistrationKeys.PG_CONNECTION]
|
||||
|
||||
if (!sharedPgConnection) {
|
||||
sharedPgConnection = knex<any, any>({
|
||||
client: "pg",
|
||||
searchPath: databaseConfig.schema,
|
||||
connection: {
|
||||
connectionString: databaseConfig.clientUrl,
|
||||
},
|
||||
})
|
||||
|
||||
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION] =
|
||||
sharedPgConnection
|
||||
}
|
||||
|
||||
const medusaApp = await MedusaApp({
|
||||
modulesConfig,
|
||||
servicesConfig: joinerConfig,
|
||||
injectedDependencies,
|
||||
})
|
||||
|
||||
async function shutdown() {
|
||||
await (sharedPgConnection as any).context?.destroy()
|
||||
MedusaModule.clearInstances()
|
||||
}
|
||||
|
||||
return {
|
||||
medusaApp,
|
||||
shutdown,
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,30 @@ import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src/initialize"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { createPaymentCollections } from "../../../__fixtures__/payment-collection"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Payment Module Service", () => {
|
||||
let service: IPaymentModuleService
|
||||
let repositoryManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PAYMENT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
|
||||
export function getInitModuleConfig() {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PAYMENT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const injectedDependencies = {}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.PAYMENT]: {
|
||||
definition: ModulesDefinition[Modules.PAYMENT],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
injectedDependencies,
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PAYMENT_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,11 @@ import {
|
||||
import { PriceListType } from "@medusajs/utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceSet } from "@models"
|
||||
import { initialize } from "../../../../src"
|
||||
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -55,17 +57,26 @@ describe("PricingModule Service - Calculate Price", () => {
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let data!: PriceSet[]
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Currency } from "@models"
|
||||
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
describe("PricingModule Service - Currency", () => {
|
||||
let service: IPricingModuleService
|
||||
@@ -12,17 +13,25 @@ describe("PricingModule Service - Currency", () => {
|
||||
let repositoryManager: SqlEntityManager
|
||||
let data!: Currency[]
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
data = await createCurrencies(testManager)
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Currency, MoneyAmount } from "@models"
|
||||
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
import { createPriceRules } from "../../../__fixtures__/price-rule"
|
||||
import { createPriceSetMoneyAmountRules } from "../../../__fixtures__/price-set-money-amount-rules"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -20,21 +21,27 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
let repositoryManager: SqlEntityManager
|
||||
let data!: MoneyAmount[]
|
||||
let currencyData!: Currency[]
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
currencyData = await createCurrencies(testManager)
|
||||
data = await createMoneyAmounts(testManager)
|
||||
})
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src"
|
||||
import { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
import { createPriceListRules } from "../../../__fixtures__/price-list-rules"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -13,18 +15,26 @@ describe("PriceListRule Service", () => {
|
||||
let service: IPricingModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = await MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
await createRuleTypes(testManager)
|
||||
await createPriceLists(testManager)
|
||||
|
||||
@@ -1,29 +1,39 @@
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { initialize } from "../../../../src"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("PriceList Service", () => {
|
||||
let service: IPricingModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
await MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
await createCurrencies(testManager)
|
||||
await createPriceSets(testManager)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CreatePriceRuleDTO, IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { initialize, PriceSetMoneyAmount } from "../../../../src"
|
||||
import { PriceSetMoneyAmount } from "../../../../src"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
|
||||
import { createPriceRules } from "../../../__fixtures__/price-rule"
|
||||
@@ -9,25 +9,36 @@ import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
|
||||
import { createPriceSetMoneyAmountRules } from "../../../__fixtures__/price-set-money-amount-rules"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("PricingModule Service - PriceRule", () => {
|
||||
let service: IPricingModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
await createCurrencies(testManager)
|
||||
await createMoneyAmounts(testManager)
|
||||
await createPriceSets(testManager)
|
||||
@@ -296,6 +307,7 @@ describe("PricingModule Service - PriceRule", () => {
|
||||
price_set: "price-set-1",
|
||||
money_amount: ma.id,
|
||||
title: "test",
|
||||
rules_count: 0,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
|
||||
import { createPriceSetMoneyAmountRules } from "../../../__fixtures__/price-set-money-amount-rules"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -16,17 +17,25 @@ describe("PricingModule Service - PriceSetMoneyAmountRules", () => {
|
||||
let service: IPricingModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = await MikroOrmWrapper.forkManager()
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
|
||||
await createCurrencies(testManager)
|
||||
|
||||
@@ -6,9 +6,12 @@ import {
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceSet } from "@models"
|
||||
|
||||
import { initialize, PriceSetRuleType } from "../../../../src"
|
||||
import { PriceSetRuleType } from "../../../../src"
|
||||
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -31,17 +34,25 @@ describe("PricingModule Service - PriceSet", () => {
|
||||
let service: IPricingModuleService
|
||||
let repositoryManager: SqlEntityManager
|
||||
let data!: PriceSet[]
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
const testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
await seedPriceData(testManager)
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { initialize } from "../../../../src"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
describe("PricingModuleService ruleType", () => {
|
||||
let service: IPricingModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
await createRuleTypes(testManager)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
|
||||
export function getInitModuleConfig() {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.PRODUCT]: true,
|
||||
[Modules.PRICING]: {
|
||||
definition: ModulesDefinition[Modules.PRICING],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { kebabCase } from "@medusajs/utils"
|
||||
import { knex } from "knex"
|
||||
import { initialize } from "../../src"
|
||||
import { EventBusService } from "../__fixtures__/event-bus"
|
||||
import * as CustomRepositories from "../__fixtures__/module"
|
||||
import {
|
||||
buildProductAndRelationsData,
|
||||
@@ -11,6 +9,8 @@ import {
|
||||
} from "../__fixtures__/product"
|
||||
import { productsData } from "../__fixtures__/product/data"
|
||||
import { DB_URL, TestDatabase } from "../utils"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { getInitModuleConfig } from "../utils/get-init-module-config"
|
||||
|
||||
const sharedPgConnection = knex<any, any>({
|
||||
client: "pg",
|
||||
@@ -30,26 +30,28 @@ const afterEach_ = async () => {
|
||||
}
|
||||
|
||||
describe("Product module", function () {
|
||||
const eventBus = new EventBusService()
|
||||
|
||||
describe("Using built-in data access layer", function () {
|
||||
let module: IProductModuleService
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const testManager = await beforeEach_()
|
||||
await createProductAndTags(testManager, productsData)
|
||||
|
||||
module = await initialize(
|
||||
{
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
@@ -72,24 +74,28 @@ describe("Product module", function () {
|
||||
|
||||
describe("Using custom data access layer", function () {
|
||||
let module
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
const initModulesConfig = getInitModuleConfig({
|
||||
repositories: CustomRepositories,
|
||||
})
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const testManager = await beforeEach_()
|
||||
|
||||
await createProductAndTags(testManager, productsData)
|
||||
|
||||
module = await initialize(
|
||||
{
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
repositories: CustomRepositories,
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
@@ -114,22 +120,27 @@ describe("Product module", function () {
|
||||
|
||||
describe("Using custom data access layer and manager", function () {
|
||||
let module
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
afterEach(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const testManager = await beforeEach_()
|
||||
await createProductAndTags(testManager, productsData)
|
||||
|
||||
MedusaModule.clearInstances()
|
||||
const initModulesConfig = getInitModuleConfig({
|
||||
manager: testManager,
|
||||
repositories: CustomRepositories,
|
||||
})
|
||||
|
||||
module = await initialize(
|
||||
{
|
||||
manager: testManager,
|
||||
repositories: CustomRepositories,
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
@@ -154,23 +165,28 @@ describe("Product module", function () {
|
||||
|
||||
describe("Using an existing connection", function () {
|
||||
let module: IProductModuleService
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
afterEach(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const testManager = await beforeEach_()
|
||||
await createProductAndTags(testManager, productsData)
|
||||
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
module = await initialize(
|
||||
{
|
||||
database: {
|
||||
connection: sharedPgConnection,
|
||||
},
|
||||
const initModulesConfig = getInitModuleConfig({
|
||||
database: {
|
||||
connection: sharedPgConnection,
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
@@ -191,23 +207,27 @@ describe("Product module", function () {
|
||||
describe("create", function () {
|
||||
let module: IProductModuleService
|
||||
let images = ["image-1"]
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
afterEach(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await beforeEach_()
|
||||
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
module = await initialize(
|
||||
{
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
const initModulesConfig = getInitModuleConfig({
|
||||
database: {
|
||||
connection: sharedPgConnection,
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
@@ -292,23 +312,24 @@ describe("Product module", function () {
|
||||
describe("softDelete", function () {
|
||||
let module: IProductModuleService
|
||||
let images = ["image-1"]
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
afterEach(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await beforeEach_()
|
||||
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
module = await initialize(
|
||||
{
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
@@ -367,23 +388,24 @@ describe("Product module", function () {
|
||||
describe("restore", function () {
|
||||
let module: IProductModuleService
|
||||
let images = ["image-1"]
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
afterEach(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await beforeEach_()
|
||||
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
module = await initialize(
|
||||
{
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
|
||||
@@ -1,37 +1,42 @@
|
||||
import { IProductModuleService, ProductTypes } from "@medusajs/types"
|
||||
import { Product, ProductCategory } from "@models"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { initialize } from "../../../../src"
|
||||
import { DB_URL, TestDatabase } from "../../../utils"
|
||||
import { getInitModuleConfig, TestDatabase } from "../../../utils"
|
||||
import { createProductCategories } from "../../../__fixtures__/product-category"
|
||||
import { productCategoriesRankData } from "../../../__fixtures__/product-category/data"
|
||||
import { EventBusService } from "../../../__fixtures__/event-bus"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
|
||||
describe("ProductModuleService product categories", () => {
|
||||
let service: IProductModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let productOne: Product
|
||||
let productTwo: Product
|
||||
let productCategoryOne: ProductCategory
|
||||
let productCategoryTwo: ProductCategory
|
||||
let productCategories: ProductCategory[]
|
||||
let eventBus
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestDatabase.setupDatabase()
|
||||
repositoryManager = await TestDatabase.forkManager()
|
||||
eventBus = new EventBusService()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
}, {
|
||||
eventBusModuleService: eventBus
|
||||
})
|
||||
|
||||
testManager = await TestDatabase.forkManager()
|
||||
|
||||
@@ -286,19 +291,17 @@ describe("ProductModuleService product categories", () => {
|
||||
})
|
||||
|
||||
it("should emit events through event bus", async () => {
|
||||
const eventBusSpy = jest.spyOn(EventBusService.prototype, 'emit')
|
||||
const eventBusSpy = jest.spyOn(EventBusService.prototype, "emit")
|
||||
|
||||
const category = await service.createCategory({
|
||||
name: "New Category",
|
||||
parent_category_id: productCategoryOne.id,
|
||||
})
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
"product-category.created",
|
||||
{
|
||||
id: category.id
|
||||
}
|
||||
)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith("product-category.created", {
|
||||
id: category.id,
|
||||
})
|
||||
})
|
||||
|
||||
it("should append rank from an existing category depending on parent", async () => {
|
||||
@@ -379,18 +382,15 @@ describe("ProductModuleService product categories", () => {
|
||||
})
|
||||
|
||||
it("should emit events through event bus", async () => {
|
||||
const eventBusSpy = jest.spyOn(EventBusService.prototype, 'emit')
|
||||
const eventBusSpy = jest.spyOn(EventBusService.prototype, "emit")
|
||||
await service.updateCategory(productCategoryZero.id, {
|
||||
name: "New Category",
|
||||
})
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
"product-category.updated",
|
||||
{
|
||||
id: productCategoryZero.id
|
||||
}
|
||||
)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith("product-category.updated", {
|
||||
id: productCategoryZero.id,
|
||||
})
|
||||
})
|
||||
|
||||
it("should update the name of the category successfully", async () => {
|
||||
@@ -551,16 +551,13 @@ describe("ProductModuleService product categories", () => {
|
||||
})
|
||||
|
||||
it("should emit events through event bus", async () => {
|
||||
const eventBusSpy = jest.spyOn(EventBusService.prototype, 'emit')
|
||||
const eventBusSpy = jest.spyOn(EventBusService.prototype, "emit")
|
||||
await service.deleteCategory(productCategoryOne.id)
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
"product-category.deleted",
|
||||
{
|
||||
id: productCategoryOne.id
|
||||
}
|
||||
)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith("product-category.deleted", {
|
||||
id: productCategoryOne.id,
|
||||
})
|
||||
})
|
||||
|
||||
it("should throw an error when an id does not exist", async () => {
|
||||
|
||||
@@ -1,39 +1,41 @@
|
||||
import { IProductModuleService, ProductTypes } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Product, ProductCollection } from "@models"
|
||||
|
||||
import { initialize } from "../../../../src"
|
||||
import { EventBusService } from "../../../__fixtures__/event-bus"
|
||||
import { createCollections } from "../../../__fixtures__/product"
|
||||
import { DB_URL, TestDatabase } from "../../../utils"
|
||||
import { getInitModuleConfig, TestDatabase } from "../../../utils"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
describe("ProductModuleService product collections", () => {
|
||||
let service: IProductModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let productOne: Product
|
||||
let productTwo: Product
|
||||
let productCollectionOne: ProductCollection
|
||||
let productCollectionTwo: ProductCollection
|
||||
let productCollections: ProductCollection[]
|
||||
let eventBus
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestDatabase.setupDatabase()
|
||||
repositoryManager = await TestDatabase.forkManager()
|
||||
eventBus = new EventBusService()
|
||||
|
||||
service = await initialize(
|
||||
{
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
|
||||
testManager = await TestDatabase.forkManager()
|
||||
|
||||
|
||||
@@ -1,28 +1,38 @@
|
||||
import { IProductModuleService, ProductTypes } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Product, ProductOption } from "@models"
|
||||
import { initialize } from "../../../../src"
|
||||
import { DB_URL, TestDatabase } from "../../../utils"
|
||||
import { getInitModuleConfig, TestDatabase } from "../../../utils"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
describe("ProductModuleService product options", () => {
|
||||
let service: IProductModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let optionOne: ProductOption
|
||||
let optionTwo: ProductOption
|
||||
let productOne: Product
|
||||
let productTwo: Product
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestDatabase.setupDatabase()
|
||||
repositoryManager = await TestDatabase.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = await TestDatabase.forkManager()
|
||||
productOne = testManager.create(Product, {
|
||||
|
||||
@@ -1,29 +1,38 @@
|
||||
import { initialize } from "../../../../src"
|
||||
import { DB_URL, TestDatabase } from "../../../utils"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { getInitModuleConfig, TestDatabase } from "../../../utils"
|
||||
import { IProductModuleService, ProductTypes } from "@medusajs/types"
|
||||
import { Product, ProductTag } from "@models"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { ProductTypes } from "@medusajs/types"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
|
||||
describe("ProductModuleService product tags", () => {
|
||||
let service: IProductModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let tagOne: ProductTag
|
||||
let tagTwo: ProductTag
|
||||
let productOne: Product
|
||||
let productTwo: Product
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestDatabase.setupDatabase()
|
||||
repositoryManager = await TestDatabase.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = await TestDatabase.forkManager()
|
||||
productOne = testManager.create(Product, {
|
||||
@@ -103,7 +112,7 @@ describe("ProductModuleService product tags", () => {
|
||||
{
|
||||
select: ["value", "products.id"],
|
||||
relations: ["products"],
|
||||
take: 1
|
||||
take: 1,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -111,9 +120,11 @@ describe("ProductModuleService product tags", () => {
|
||||
{
|
||||
id: tagOne.id,
|
||||
value: tagOne.value,
|
||||
products: [{
|
||||
id: productOne.id,
|
||||
}],
|
||||
products: [
|
||||
{
|
||||
id: productOne.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -149,11 +160,9 @@ describe("ProductModuleService product tags", () => {
|
||||
id: tagOne.id,
|
||||
}),
|
||||
])
|
||||
|
||||
;[tags, count] = await service.listAndCountTags({}, { take: 1 })
|
||||
|
||||
expect(count).toEqual(2)
|
||||
|
||||
;[tags, count] = await service.listAndCountTags({}, { take: 1, skip: 1 })
|
||||
|
||||
expect(count).toEqual(2)
|
||||
@@ -172,7 +181,7 @@ describe("ProductModuleService product tags", () => {
|
||||
{
|
||||
select: ["value", "products.id"],
|
||||
relations: ["products"],
|
||||
take: 1
|
||||
take: 1,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -181,9 +190,11 @@ describe("ProductModuleService product tags", () => {
|
||||
{
|
||||
id: tagOne.id,
|
||||
value: tagOne.value,
|
||||
products: [{
|
||||
id: productOne.id,
|
||||
}],
|
||||
products: [
|
||||
{
|
||||
id: productOne.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -196,28 +207,27 @@ describe("ProductModuleService product tags", () => {
|
||||
expect(tag).toEqual(
|
||||
expect.objectContaining({
|
||||
id: tagOne.id,
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should return requested attributes when requested through config", async () => {
|
||||
const tag = await service.retrieveTag(
|
||||
tagOne.id,
|
||||
{
|
||||
select: ["id", "value", "products.title"],
|
||||
relations: ["products"],
|
||||
}
|
||||
)
|
||||
const tag = await service.retrieveTag(tagOne.id, {
|
||||
select: ["id", "value", "products.title"],
|
||||
relations: ["products"],
|
||||
})
|
||||
|
||||
expect(tag).toEqual(
|
||||
expect.objectContaining({
|
||||
id: tagOne.id,
|
||||
value: tagOne.value,
|
||||
products: [{
|
||||
id: "product-1",
|
||||
title: "product 1",
|
||||
}],
|
||||
}),
|
||||
products: [
|
||||
{
|
||||
id: "product-1",
|
||||
title: "product 1",
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
@@ -230,7 +240,9 @@ describe("ProductModuleService product tags", () => {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("ProductTag with id: does-not-exist was not found")
|
||||
expect(error.message).toEqual(
|
||||
"ProductTag with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -238,12 +250,10 @@ describe("ProductModuleService product tags", () => {
|
||||
const tagId = "tag-1"
|
||||
|
||||
it("should delete the product tag given an ID successfully", async () => {
|
||||
await service.deleteTags(
|
||||
[tagId],
|
||||
)
|
||||
await service.deleteTags([tagId])
|
||||
|
||||
const tags = await service.listTags({
|
||||
id: tagId
|
||||
id: tagId,
|
||||
})
|
||||
|
||||
expect(tags).toHaveLength(0)
|
||||
@@ -254,12 +264,12 @@ describe("ProductModuleService product tags", () => {
|
||||
const tagId = "tag-1"
|
||||
|
||||
it("should update the value of the tag successfully", async () => {
|
||||
await service.updateTags(
|
||||
[{
|
||||
await service.updateTags([
|
||||
{
|
||||
id: tagId,
|
||||
value: "UK"
|
||||
}]
|
||||
)
|
||||
value: "UK",
|
||||
},
|
||||
])
|
||||
|
||||
const productTag = await service.retrieveTag(tagId)
|
||||
|
||||
@@ -273,31 +283,32 @@ describe("ProductModuleService product tags", () => {
|
||||
await service.updateTags([
|
||||
{
|
||||
id: "does-not-exist",
|
||||
value: "UK"
|
||||
}
|
||||
value: "UK",
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual('ProductTag with id "does-not-exist" not found')
|
||||
expect(error.message).toEqual(
|
||||
'ProductTag with id "does-not-exist" not found'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("createTags", () => {
|
||||
it("should create a tag successfully", async () => {
|
||||
const res = await service.createTags(
|
||||
[{
|
||||
value: "UK"
|
||||
}]
|
||||
)
|
||||
const res = await service.createTags([
|
||||
{
|
||||
value: "UK",
|
||||
},
|
||||
])
|
||||
|
||||
const productTag = await service.listTags({
|
||||
value: "UK"
|
||||
value: "UK",
|
||||
})
|
||||
|
||||
expect(productTag[0]?.value).toEqual("UK")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,27 +1,36 @@
|
||||
import { initialize } from "../../../../src"
|
||||
import { DB_URL, TestDatabase } from "../../../utils"
|
||||
import { getInitModuleConfig, TestDatabase } from "../../../utils"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { ProductType } from "@models"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { ProductTypes } from "@medusajs/types"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
|
||||
describe("ProductModuleService product types", () => {
|
||||
let service: IProductModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let typeOne: ProductType
|
||||
let typeTwo: ProductType
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestDatabase.setupDatabase()
|
||||
repositoryManager = await TestDatabase.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = await TestDatabase.forkManager()
|
||||
|
||||
@@ -87,7 +96,7 @@ describe("ProductModuleService product types", () => {
|
||||
},
|
||||
{
|
||||
select: ["value"],
|
||||
take: 1
|
||||
take: 1,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -130,12 +139,13 @@ describe("ProductModuleService product types", () => {
|
||||
id: typeOne.id,
|
||||
}),
|
||||
])
|
||||
|
||||
;[types, count] = await service.listAndCountTypes({}, { take: 1 })
|
||||
|
||||
expect(count).toEqual(2)
|
||||
|
||||
;[types, count] = await service.listAndCountTypes({}, { take: 1, skip: 1 })
|
||||
;[types, count] = await service.listAndCountTypes(
|
||||
{},
|
||||
{ take: 1, skip: 1 }
|
||||
)
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(types).toEqual([
|
||||
@@ -152,7 +162,7 @@ describe("ProductModuleService product types", () => {
|
||||
},
|
||||
{
|
||||
select: ["value"],
|
||||
take: 1
|
||||
take: 1,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -173,24 +183,19 @@ describe("ProductModuleService product types", () => {
|
||||
expect(type).toEqual(
|
||||
expect.objectContaining({
|
||||
id: typeOne.id,
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should return requested attributes when requested through config", async () => {
|
||||
const type = await service.retrieveType(
|
||||
typeOne.id,
|
||||
{
|
||||
select: ["id", "value"],
|
||||
}
|
||||
)
|
||||
const type = await service.retrieveType(typeOne.id, {
|
||||
select: ["id", "value"],
|
||||
})
|
||||
|
||||
expect(type).toEqual(
|
||||
{
|
||||
id: typeOne.id,
|
||||
value: typeOne.value,
|
||||
},
|
||||
)
|
||||
expect(type).toEqual({
|
||||
id: typeOne.id,
|
||||
value: typeOne.value,
|
||||
})
|
||||
})
|
||||
|
||||
it("should throw an error when a type with ID does not exist", async () => {
|
||||
@@ -202,7 +207,9 @@ describe("ProductModuleService product types", () => {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("ProductType with id: does-not-exist was not found")
|
||||
expect(error.message).toEqual(
|
||||
"ProductType with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -210,12 +217,10 @@ describe("ProductModuleService product types", () => {
|
||||
const typeId = "type-1"
|
||||
|
||||
it("should delete the product type given an ID successfully", async () => {
|
||||
await service.deleteTypes(
|
||||
[typeId],
|
||||
)
|
||||
await service.deleteTypes([typeId])
|
||||
|
||||
const types = await service.listTypes({
|
||||
id: typeId
|
||||
id: typeId,
|
||||
})
|
||||
|
||||
expect(types).toHaveLength(0)
|
||||
@@ -226,12 +231,12 @@ describe("ProductModuleService product types", () => {
|
||||
const typeId = "type-1"
|
||||
|
||||
it("should update the value of the type successfully", async () => {
|
||||
await service.updateTypes(
|
||||
[{
|
||||
await service.updateTypes([
|
||||
{
|
||||
id: typeId,
|
||||
value: "UK"
|
||||
}]
|
||||
)
|
||||
value: "UK",
|
||||
},
|
||||
])
|
||||
|
||||
const productType = await service.retrieveType(typeId)
|
||||
|
||||
@@ -245,31 +250,32 @@ describe("ProductModuleService product types", () => {
|
||||
await service.updateTypes([
|
||||
{
|
||||
id: "does-not-exist",
|
||||
value: "UK"
|
||||
}
|
||||
value: "UK",
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual('ProductType with id "does-not-exist" not found')
|
||||
expect(error.message).toEqual(
|
||||
'ProductType with id "does-not-exist" not found'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("createTypes", () => {
|
||||
it("should create a type successfully", async () => {
|
||||
const res = await service.createTypes(
|
||||
[{
|
||||
value: "UK"
|
||||
}]
|
||||
)
|
||||
const res = await service.createTypes([
|
||||
{
|
||||
value: "UK",
|
||||
},
|
||||
])
|
||||
|
||||
const productType = await service.listTypes({
|
||||
value: "UK"
|
||||
value: "UK",
|
||||
})
|
||||
|
||||
expect(productType[0]?.value).toEqual("UK")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,30 +1,38 @@
|
||||
import { initialize } from "../../../../src"
|
||||
import { DB_URL, TestDatabase } from "../../../utils"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { getInitModuleConfig, TestDatabase } from "../../../utils"
|
||||
import { IProductModuleService, ProductTypes } from "@medusajs/types"
|
||||
import { Product, ProductVariant } from "@models"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { ProductTypes } from "@medusajs/types"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
|
||||
describe("ProductModuleService product variants", () => {
|
||||
let service: IProductModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let variantOne: ProductVariant
|
||||
let variantTwo: ProductVariant
|
||||
let productOne: Product
|
||||
let productTwo: Product
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestDatabase.setupDatabase()
|
||||
repositoryManager = await TestDatabase.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
|
||||
testManager = await TestDatabase.forkManager()
|
||||
|
||||
productOne = testManager.create(Product, {
|
||||
@@ -140,18 +148,15 @@ describe("ProductModuleService product variants", () => {
|
||||
expect.objectContaining({
|
||||
id: "test-1",
|
||||
title: "variant 1",
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should return requested attributes when requested through config", async () => {
|
||||
const result = await service.retrieveVariant(
|
||||
variantOne.id,
|
||||
{
|
||||
select: ["id", "title", "product.title"] as any,
|
||||
relations: ["product"],
|
||||
}
|
||||
)
|
||||
const result = await service.retrieveVariant(variantOne.id, {
|
||||
select: ["id", "title", "product.title"] as any,
|
||||
relations: ["product"],
|
||||
})
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -162,7 +167,7 @@ describe("ProductModuleService product variants", () => {
|
||||
id: "product-1",
|
||||
title: "product 1",
|
||||
}),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
@@ -175,8 +180,9 @@ describe("ProductModuleService product variants", () => {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("ProductVariant with id: does-not-exist was not found")
|
||||
expect(error.message).toEqual(
|
||||
"ProductVariant with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
IProductModuleService,
|
||||
ProductTypes,
|
||||
@@ -18,7 +18,8 @@ import { EventBusService } from "../../../__fixtures__/event-bus"
|
||||
import { createCollections, createTypes } from "../../../__fixtures__/product"
|
||||
import { createProductCategories } from "../../../__fixtures__/product-category"
|
||||
import { buildProductAndRelationsData } from "../../../__fixtures__/product/data/create-product"
|
||||
import { DB_URL, TestDatabase } from "../../../utils"
|
||||
import { DB_URL, getInitModuleConfig, TestDatabase } from "../../../utils"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
const beforeEach_ = async () => {
|
||||
await TestDatabase.setupDatabase()
|
||||
@@ -57,7 +58,6 @@ describe("ProductModuleService products", function () {
|
||||
let productTypeOne: ProductType
|
||||
let productTypeTwo: ProductType
|
||||
let images = ["image-1"]
|
||||
let eventBus
|
||||
|
||||
const productCategoriesData = [
|
||||
{
|
||||
@@ -88,6 +88,24 @@ describe("ProductModuleService products", function () {
|
||||
},
|
||||
]
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
module = medusaApp.modules[Modules.PRODUCT]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const testManager = await beforeEach_()
|
||||
|
||||
@@ -149,21 +167,6 @@ describe("ProductModuleService products", function () {
|
||||
})
|
||||
|
||||
await testManager.persistAndFlush([productOne, productTwo])
|
||||
|
||||
MedusaModule.clearInstances()
|
||||
|
||||
eventBus = new EventBusService()
|
||||
module = await initialize(
|
||||
{
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
{
|
||||
eventBusModuleService: eventBus,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(afterEach_)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
import { EventBusService } from "../__fixtures__/event-bus"
|
||||
|
||||
export function getInitModuleConfig(
|
||||
additionalOptions: any = {},
|
||||
injectedDependencies: null | Record<string, any> = null
|
||||
) {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
...additionalOptions,
|
||||
}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.PRODUCT]: {
|
||||
definition: ModulesDefinition[Modules.PRODUCT],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
const defaultInjectedDependencies = {
|
||||
eventBusModuleService: new EventBusService(),
|
||||
}
|
||||
|
||||
return {
|
||||
injectedDependencies: injectedDependencies ?? defaultInjectedDependencies,
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PRODUCT_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
export * from "./database"
|
||||
export * from "./get-init-module-config"
|
||||
|
||||
@@ -1,26 +1,36 @@
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCampaigns } from "../../../__fixtures__/campaigns"
|
||||
import { createPromotions } from "../../../__fixtures__/promotion"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Promotion Module Service: Campaigns", () => {
|
||||
let service: IPromotionModuleService
|
||||
let repositoryManager: SqlEntityManager
|
||||
let shutdownFunc: () => void
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PROMOTION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PROMOTION_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,26 +1,36 @@
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { PromotionType } from "@medusajs/utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCampaigns } from "../../../__fixtures__/campaigns"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Promotion Service: computeActions", () => {
|
||||
let service: IPromotionModuleService
|
||||
let repositoryManager: SqlEntityManager
|
||||
let shutdownFunc: () => void
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PROMOTION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PROMOTION_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -5,27 +5,37 @@ import {
|
||||
PromotionType,
|
||||
} from "@medusajs/utils"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCampaigns } from "../../../__fixtures__/campaigns"
|
||||
import { createPromotions } from "../../../__fixtures__/promotion"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Promotion Service", () => {
|
||||
let service: IPromotionModuleService
|
||||
let repositoryManager: SqlEntityManager
|
||||
let shutdownFunc: () => void
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PROMOTION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PROMOTION_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src"
|
||||
import { createCampaigns } from "../../../__fixtures__/campaigns"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { initModules } from "medusa-test-utils/dist"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Promotion Service: campaign usage", () => {
|
||||
let service: IPromotionModuleService
|
||||
let repositoryManager: SqlEntityManager
|
||||
let shutdownFunc: () => void
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PROMOTION]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
await createCampaigns(repositoryManager)
|
||||
|
||||
service = await initialize({
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PROMOTION_DB_SCHEMA,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
|
||||
import { DB_URL } from "./database"
|
||||
|
||||
export function getInitModuleConfig() {
|
||||
const moduleOptions = {
|
||||
defaultAdapterOptions: {
|
||||
database: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PROMOTION_DB_SCHEMA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const injectedDependencies = {}
|
||||
|
||||
const modulesConfig_ = {
|
||||
[Modules.PROMOTION]: {
|
||||
definition: ModulesDefinition[Modules.PROMOTION],
|
||||
options: moduleOptions,
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
injectedDependencies,
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: {
|
||||
clientUrl: DB_URL,
|
||||
schema: process.env.MEDUSA_PROMOTION_DB_SCHEMA,
|
||||
},
|
||||
joinerConfig: [],
|
||||
}
|
||||
}
|
||||
@@ -37842,6 +37842,8 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "medusa-test-utils@workspace:packages/medusa-test-utils"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": "workspace:^"
|
||||
"@medusajs/utils": "workspace:^"
|
||||
"@mikro-orm/migrations": 5.9.7
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
cross-env: ^5.2.1
|
||||
|
||||
Reference in New Issue
Block a user