chore(utils): Add default ordering to the internal service factory list/listAndCount (#6436)
**What** Default ordering. By default, only the top level entity ordering is applied using the primary keys, the relations are default ordered by the foreign keys. It include tests fixing for deterministic data ordering
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { Currency } from "@models"
|
||||
import { CurrencyService } from "@services"
|
||||
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { createMedusaContainer } from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import ContainerLoader from "../../../../src/loaders/container"
|
||||
import { ModulesSdkTypes } from "@medusajs/types"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Currency Service", () => {
|
||||
let service: CurrencyService
|
||||
let service: ModulesSdkTypes.InternalModuleService<any>
|
||||
let testManager: SqlEntityManager
|
||||
let repositoryManager: SqlEntityManager
|
||||
let data!: Currency[]
|
||||
@@ -57,14 +57,14 @@ describe("Currency Service", () => {
|
||||
const currenciesResult = await service.list()
|
||||
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
@@ -86,14 +86,14 @@ describe("Currency Service", () => {
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
@@ -120,8 +120,8 @@ describe("Currency Service", () => {
|
||||
expect(count).toEqual(2)
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
@@ -140,7 +140,7 @@ describe("Currency Service", () => {
|
||||
expect(count).toEqual(2)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
code: "USD",
|
||||
code: "CAD",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
@@ -214,8 +214,8 @@ describe("MoneyAmount Service", () => {
|
||||
expect(count).toEqual(3)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "money-amount-USD",
|
||||
amount: 500,
|
||||
id: "money-amount-CAD",
|
||||
amount: 600,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
+13
-11
@@ -46,10 +46,6 @@ describe("PricingModule Service - Currency", () => {
|
||||
const currenciesResult = await service.listCurrencies()
|
||||
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
@@ -58,6 +54,10 @@ describe("PricingModule Service - Currency", () => {
|
||||
code: "EUR",
|
||||
name: "Euro",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
@@ -79,10 +79,6 @@ describe("PricingModule Service - Currency", () => {
|
||||
|
||||
expect(count).toEqual(3)
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
@@ -91,6 +87,10 @@ describe("PricingModule Service - Currency", () => {
|
||||
code: "EUR",
|
||||
name: "Euro",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "USD",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
@@ -117,8 +117,10 @@ describe("PricingModule Service - Currency", () => {
|
||||
expect(count).toEqual(3)
|
||||
expect(currenciesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "CAD",
|
||||
name: "Canadian Dollar",
|
||||
code: "EUR",
|
||||
name: "Euro",
|
||||
symbol: "€",
|
||||
symbol_native: "€",
|
||||
}),
|
||||
])
|
||||
})
|
||||
@@ -137,7 +139,7 @@ describe("PricingModule Service - Currency", () => {
|
||||
expect(count).toEqual(3)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
code: "USD",
|
||||
code: "CAD",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ describe("PricingModule Service - MoneyAmount", () => {
|
||||
expect(count).toEqual(3)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "money-amount-USD",
|
||||
id: "money-amount-CAD",
|
||||
amount: null,
|
||||
},
|
||||
])
|
||||
|
||||
+8
-10
@@ -273,16 +273,14 @@ describe("PricingModule Service - PriceSetMoneyAmountRules", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const priceSetMoneyAmountRules =
|
||||
await service.listPriceSetMoneyAmountRules(
|
||||
{},
|
||||
{
|
||||
relations: ["price_set_money_amount", "rule_type"],
|
||||
}
|
||||
)
|
||||
|
||||
const created =
|
||||
priceSetMoneyAmountRules[priceSetMoneyAmountRules.length - 1]
|
||||
const [created] = await service.listPriceSetMoneyAmountRules(
|
||||
{
|
||||
value: ["New priceSetMoneyAmountRule"],
|
||||
},
|
||||
{
|
||||
relations: ["price_set_money_amount", "rule_type"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(created).toEqual(
|
||||
expect.objectContaining({
|
||||
|
||||
Reference in New Issue
Block a user