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