feat: Add currency module and remove currency models from region and pricing modules (#6536)
What: - Creates a new currency module - Removes currency model from the pricing module - Removes currency model from region module
This commit is contained in:
1 parent
06f706a51a
commit
dc025302a1
102 files changed
+1502
-2128
No files matched your search
-16
@@ -85,21 +85,6 @@ describe("PricingModule Service - Calculate Price", () => {
|
||||
|
||||
describe("calculatePrices", () => {
|
||||
beforeEach(async () => {
|
||||
const currencyData = [
|
||||
{
|
||||
symbol: "zł",
|
||||
name: "Polish Zloty",
|
||||
symbol_native: "zł",
|
||||
code: "PLN",
|
||||
},
|
||||
{
|
||||
symbol: "€",
|
||||
name: "Euro",
|
||||
symbol_native: "€",
|
||||
code: "EUR",
|
||||
},
|
||||
]
|
||||
|
||||
const moneyAmountsData = [
|
||||
{
|
||||
id: "money-amount-PLN",
|
||||
@@ -373,7 +358,6 @@ describe("PricingModule Service - Calculate Price", () => {
|
||||
] as unknown as CreatePriceRuleDTO[]
|
||||
|
||||
await seedPriceData(MikroOrmWrapper.forkManager(), {
|
||||
currencyData,
|
||||
moneyAmountsData,
|
||||
priceSetsData,
|
||||
priceSetMoneyAmountsData,
|
||||
|
||||
-277
@@ -1,277 +0,0 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Currency } from "@models"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { initModules } from "medusa-test-utils"
|
||||
|
||||
describe("PricingModule Service - Currency", () => {
|
||||
let service: IPricingModuleService
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let data!: Currency[]
|
||||
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
const initModulesConfig = getInitModuleConfig()
|
||||
|
||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||
|
||||
service = medusaApp.modules[Modules.PRICING]
|
||||
|
||||
shutdownFunc = shutdown
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await shutdownFunc()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
data = await createCurrencies(testManager)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await MikroOrmWrapper.clearDatabase()
|
||||
})
|
||||
|
||||
describe("listCurrencies", () => {
|
||||
it("list currencies", async () => {
|
||||
const currenciesResult = await service.listCurrencies()
|
||||
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "EUR",
|
||||
name: "Euro",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("list currencies by code", async () => {
|
||||
const currenciesResult = await service.listCurrencies({ code: ["USD"] })
|
||||
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("listAndCountCurrencies", () => {
|
||||
it("should return currencies and count", async () => {
|
||||
const [currenciesResult, count] = await service.listAndCountCurrencies()
|
||||
|
||||
expect(count).toEqual(3)
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "EUR",
|
||||
name: "Euro",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return currencies and count when filtered", async () => {
|
||||
const [currenciesResult, count] = await service.listAndCountCurrencies({
|
||||
code: ["USD"],
|
||||
})
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return currencies and count when using skip and take", async () => {
|
||||
const [currenciesResult, count] = await service.listAndCountCurrencies(
|
||||
{},
|
||||
{ skip: 1, take: 1 }
|
||||
)
|
||||
|
||||
expect(count).toEqual(3)
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "EUR",
|
||||
name: "Euro",
|
||||
symbol: "€",
|
||||
symbol_native: "€",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return requested fields", async () => {
|
||||
const [currenciesResult, count] = await service.listAndCountCurrencies(
|
||||
{},
|
||||
{
|
||||
take: 1,
|
||||
select: ["code"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(currenciesResult))
|
||||
|
||||
expect(count).toEqual(3)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
code: "CAD",
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrieveCurrency", () => {
|
||||
const code = "USD"
|
||||
const name = "US Dollar"
|
||||
|
||||
it("should return currency for the given code", async () => {
|
||||
const currency = await service.retrieveCurrency(code)
|
||||
|
||||
expect(currency).toEqual(
|
||||
expect.objectContaining({
|
||||
code,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when currency with code does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieveCurrency("does-not-exist")
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Currency with code: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when a code is not provided", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieveCurrency(undefined as unknown as string)
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("currency - code must be defined")
|
||||
})
|
||||
|
||||
it("should return currency based on config select param", async () => {
|
||||
const currency = await service.retrieveCurrency(code, {
|
||||
select: ["code", "name"],
|
||||
})
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(currency))
|
||||
|
||||
expect(serialized).toEqual({
|
||||
code,
|
||||
name,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("deleteCurrencies", () => {
|
||||
const code = "USD"
|
||||
|
||||
it("should delete the currencies given an code successfully", async () => {
|
||||
await service.deleteCurrencies([code])
|
||||
|
||||
const currencies = await service.listCurrencies({
|
||||
code: [code],
|
||||
})
|
||||
|
||||
expect(currencies).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("updateCurrencies", () => {
|
||||
const code = "USD"
|
||||
|
||||
it("should update the name of the currency successfully", async () => {
|
||||
await service.updateCurrencies([
|
||||
{
|
||||
code,
|
||||
name: "United States Pounds",
|
||||
},
|
||||
])
|
||||
|
||||
const currency = await service.retrieveCurrency(code)
|
||||
|
||||
expect(currency.name).toEqual("United States Pounds")
|
||||
})
|
||||
|
||||
it("should throw an error when a code does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.updateCurrencies([
|
||||
{
|
||||
code: "does-not-exist",
|
||||
name: "UK",
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
'Currency with code "does-not-exist" not found'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("createCurrencies", () => {
|
||||
it("should create a currency successfully", async () => {
|
||||
await service.createCurrencies([
|
||||
{
|
||||
code: "TES",
|
||||
name: "Test Dollars",
|
||||
symbol: "TES1",
|
||||
symbol_native: "TES2",
|
||||
},
|
||||
])
|
||||
|
||||
const [currency] = await service.listCurrencies({
|
||||
code: ["TES"],
|
||||
})
|
||||
|
||||
expect(currency).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "TES",
|
||||
name: "Test Dollars",
|
||||
symbol: "TES1",
|
||||
symbol_native: "TES2",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
+4
-18
@@ -1,7 +1,6 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Currency, MoneyAmount } from "@models"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { MoneyAmount } from "@models"
|
||||
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
|
||||
@@ -20,7 +19,6 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let data!: MoneyAmount[]
|
||||
let currencyData!: Currency[]
|
||||
let shutdownFunc: () => Promise<void>
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -42,7 +40,6 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
repositoryManager = MikroOrmWrapper.forkManager()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
currencyData = await createCurrencies(testManager)
|
||||
data = await createMoneyAmounts(testManager)
|
||||
})
|
||||
|
||||
@@ -90,8 +87,7 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
id: ["money-amount-USD"],
|
||||
},
|
||||
{
|
||||
select: ["id", "min_quantity", "currency.code"],
|
||||
relations: ["currency"],
|
||||
select: ["id", "min_quantity", "currency_code"],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -103,9 +99,6 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
amount: null,
|
||||
min_quantity: "1",
|
||||
currency_code: "USD",
|
||||
currency: {
|
||||
code: "USD",
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -153,8 +146,7 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
id: ["money-amount-USD"],
|
||||
},
|
||||
{
|
||||
select: ["id", "min_quantity", "currency.code", "amount"],
|
||||
relations: ["currency"],
|
||||
select: ["id", "min_quantity", "currency_code", "amount"],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -167,9 +159,6 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
amount: 500,
|
||||
min_quantity: "1",
|
||||
currency_code: "USD",
|
||||
currency: {
|
||||
code: "USD",
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -392,12 +381,9 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const moneyAmount = await service.retrieveMoneyAmount(id, {
|
||||
relations: ["currency"],
|
||||
})
|
||||
const moneyAmount = await service.retrieveMoneyAmount(id, {})
|
||||
|
||||
expect(moneyAmount.currency_code).toEqual("EUR")
|
||||
expect(moneyAmount.currency?.code).toEqual("EUR")
|
||||
})
|
||||
|
||||
it("should throw an error when a id does not exist", async () => {
|
||||
|
||||
-2
@@ -2,7 +2,6 @@ import { MikroOrmWrapper } from "../../../utils"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
@@ -35,7 +34,6 @@ describe("PriceList Service", () => {
|
||||
await MikroOrmWrapper.forkManager()
|
||||
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
await createCurrencies(testManager)
|
||||
await createPriceSets(testManager)
|
||||
await createPriceLists(testManager)
|
||||
await service.createRuleTypes([
|
||||
|
||||
-2
@@ -2,7 +2,6 @@ import { CreatePriceRuleDTO, IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceSetMoneyAmount } from "../../../../src"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
|
||||
import { createPriceRules } from "../../../__fixtures__/price-rule"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
@@ -39,7 +38,6 @@ describe("PricingModule Service - PriceRule", () => {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
testManager = MikroOrmWrapper.forkManager()
|
||||
|
||||
await createCurrencies(testManager)
|
||||
await createMoneyAmounts(testManager)
|
||||
await createPriceSets(testManager)
|
||||
await createRuleTypes(testManager)
|
||||
|
||||
-2
@@ -1,6 +1,5 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
|
||||
@@ -38,7 +37,6 @@ describe("PricingModule Service - PriceSetMoneyAmountRules", () => {
|
||||
repositoryManager = await MikroOrmWrapper.forkManager()
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
|
||||
await createCurrencies(testManager)
|
||||
await createMoneyAmounts(testManager)
|
||||
await createPriceSets(testManager)
|
||||
await createRuleTypes(testManager)
|
||||
|
||||
Reference in new issue
Block a user