Skip to content

Commit

Permalink
feat(product, pricing, utils): Transaction issues and reference issues (
Browse files Browse the repository at this point in the history
#5533)

* feat(product, pricing, utils): Transaction issues and reference issues

* fixes decorators

* cleanup

* fix product module upsert

* fix missing active manager

* increase timeout

* revert package.json

* WIP

* try another node version based on findings with memory issues with jest introduced after 16.11 but fixed in 21

* re add bail

* fix variant options

* chore: bulk create pricing

* chore: workflow bulk

* Create big-chefs-dream.md

* fix missing update for upserty

* Add integration tests for product options upsert

* rm unnecessary return

* fix product prices workflow issue

* cleanup

* fix flag

* fix model

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
Co-authored-by: Carlos R. L. Rodrigues <rodrigolr@gmail.com>
Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
  • Loading branch information
4 people committed Nov 6, 2023
1 parent 57c3a24 commit f88d75b
Show file tree
Hide file tree
Showing 47 changed files with 621 additions and 472 deletions.
6 changes: 6 additions & 0 deletions .changeset/big-chefs-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/pricing": patch
"@medusajs/product": patch
---

feat(product, pricing, utils): Transaction issues and reference issues + refactoring
2 changes: 1 addition & 1 deletion .github/actions/setup-server/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
node-version:
description: "Node version"
required: false
default: "16.20.2"
default: "16.10.0"
cache-extension:
description: "Extension for fetching cached dependencies"
required: true
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Assert changed
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Assert changed
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down Expand Up @@ -223,7 +223,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down Expand Up @@ -275,7 +275,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codegen-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-freshness-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-new-announcement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-remove-announcement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/generate-references.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/oas-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16.20.2"
node-version: "16.10.0"
cache: "yarn"

- name: Post to Slack channel
Expand Down
1 change: 1 addition & 0 deletions integration-tests/environment-helpers/bootstrap-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = {

const shutdown = async () => {
await Promise.all([
container.dispose(),
expressServer.close(),
db?.destroy(),
pgConnection?.context?.destroy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const env = {
MEDUSA_FF_ISOLATE_PRODUCT_DOMAIN: true,
}

describe.skip("[Product & Pricing Module] POST /admin/products", () => {
describe("[Product & Pricing Module] POST /admin/products", () => {
let dbConnection
let appContainer
let shutdownServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const env = {
MEDUSA_FF_ISOLATE_PRODUCT_DOMAIN: true,
}

describe.skip("[Product & Pricing Module] POST /admin/products/:id/variants/:id", () => {
describe("[Product & Pricing Module] POST /admin/products/:id/variants/:id", () => {
let dbConnection
let appContainer
let shutdownServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const env = {
MEDUSA_FF_ISOLATE_PRODUCT_DOMAIN: true,
}

describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
describe("[Product & Pricing Module] POST /admin/products/:id", () => {
let dbConnection
let appContainer
let shutdownServer
Expand Down Expand Up @@ -172,9 +172,7 @@ describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
],
}

console.log("I am here first")
await api.post(`/admin/products/${product.id}`, data, adminHeaders)
console.log("I am here")

const response = await api.get(
`/admin/products/${product.id}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories"

jest.setTimeout(30000)
jest.setTimeout(100000)

describe("UpdateProduct workflow", function () {
let dbConnection
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/plugins/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
`/www/`,
`/dist/`,
`/node_modules/`,
"<rootDir>/node_modules",
`<rootDir>/node_modules/`,
`__tests__/fixtures`,
`__testfixtures__`,
`.cache`,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --silent=false --runInBand --bail --logHeapUsage --forceExit",
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --silent=false --runInBand --bail --detectOpenHandles --logHeapUsage --clearMocks --no-compilation-cache --forceExit",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/pricing/src/repositories/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PricingRepository
pricingContext: PricingContext = { context: {} },
sharedContext: Context = {}
): Promise<CalculatedPriceSetDTO[]> {
const manager = this.getActiveManager<SqlEntityManager>()
const manager = this.getActiveManager<SqlEntityManager>(sharedContext)
const knex = manager.getKnex()
const context = pricingContext.context || {}

Expand Down
8 changes: 3 additions & 5 deletions packages/pricing/src/services/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
import { Currency } from "@models"
import { CurrencyRepository } from "@repositories"

import { doNotForceTransaction, shouldForceTransaction } from "@medusajs/utils"

type InjectedDependencies = {
currencyRepository: DAL.RepositoryService
}
Expand Down Expand Up @@ -75,7 +73,7 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
return queryOptions
}

@InjectTransactionManager(shouldForceTransaction, "currencyRepository_")
@InjectTransactionManager("currencyRepository_")
async create(
data: PricingTypes.CreateCurrencyDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -86,7 +84,7 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
)) as TEntity[]
}

@InjectTransactionManager(shouldForceTransaction, "currencyRepository_")
@InjectTransactionManager("currencyRepository_")
async update(
data: PricingTypes.UpdateCurrencyDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -97,7 +95,7 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
)) as TEntity[]
}

@InjectTransactionManager(doNotForceTransaction, "currencyRepository_")
@InjectTransactionManager("currencyRepository_")
async delete(
ids: string[],
@MedusaContext() sharedContext: Context = {}
Expand Down
8 changes: 3 additions & 5 deletions packages/pricing/src/services/money-amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
import { MoneyAmount } from "@models"
import { MoneyAmountRepository } from "@repositories"

import { doNotForceTransaction, shouldForceTransaction } from "@medusajs/utils"

type InjectedDependencies = {
moneyAmountRepository: DAL.RepositoryService
}
Expand Down Expand Up @@ -73,7 +71,7 @@ export default class MoneyAmountService<
)) as [TEntity[], number]
}

@InjectTransactionManager(shouldForceTransaction, "moneyAmountRepository_")
@InjectTransactionManager("moneyAmountRepository_")
async create(
data: PricingTypes.CreateMoneyAmountDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -84,7 +82,7 @@ export default class MoneyAmountService<
)) as TEntity[]
}

@InjectTransactionManager(shouldForceTransaction, "moneyAmountRepository_")
@InjectTransactionManager("moneyAmountRepository_")
async update(
data: PricingTypes.UpdateMoneyAmountDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -95,7 +93,7 @@ export default class MoneyAmountService<
)) as TEntity[]
}

@InjectTransactionManager(doNotForceTransaction, "moneyAmountRepository_")
@InjectTransactionManager("moneyAmountRepository_")
async delete(
ids: string[],
@MedusaContext() sharedContext: Context = {}
Expand Down
8 changes: 3 additions & 5 deletions packages/pricing/src/services/price-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {
InjectTransactionManager,
MedusaContext,
ModulesSdkUtils,
doNotForceTransaction,
retrieveEntity,
shouldForceTransaction,
} from "@medusajs/utils"
import { PriceRule } from "@models"
import { PriceRuleRepository } from "@repositories"
Expand Down Expand Up @@ -65,7 +63,7 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
)) as [TEntity[], number]
}

@InjectTransactionManager(shouldForceTransaction, "priceRuleRepository_")
@InjectTransactionManager("priceRuleRepository_")
async create(
data: PricingTypes.CreatePriceRuleDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -76,7 +74,7 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
)) as TEntity[]
}

@InjectTransactionManager(shouldForceTransaction, "priceRuleRepository_")
@InjectTransactionManager("priceRuleRepository_")
async update(
data: PricingTypes.UpdatePriceRuleDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -87,7 +85,7 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
)) as TEntity[]
}

@InjectTransactionManager(doNotForceTransaction, "priceRuleRepository_")
@InjectTransactionManager("priceRuleRepository_")
async delete(
ids: string[],
@MedusaContext() sharedContext: Context = {}
Expand Down
17 changes: 3 additions & 14 deletions packages/pricing/src/services/price-set-money-amount-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
} from "@medusajs/utils"
import { PriceSetMoneyAmountRules } from "@models"

import { doNotForceTransaction, shouldForceTransaction } from "@medusajs/utils"

type InjectedDependencies = {
priceSetMoneyAmountRulesRepository: DAL.RepositoryService
}
Expand Down Expand Up @@ -79,10 +77,7 @@ export default class PriceSetMoneyAmountRulesService<
return queryOptions
}

@InjectTransactionManager(
shouldForceTransaction,
"priceSetMoneyAmountRulesRepository_"
)
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
async create(
data: PricingTypes.CreatePriceSetMoneyAmountRulesDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -93,10 +88,7 @@ export default class PriceSetMoneyAmountRulesService<
)) as TEntity[]
}

@InjectTransactionManager(
shouldForceTransaction,
"priceSetMoneyAmountRulesRepository_"
)
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
async update(
data: PricingTypes.UpdatePriceSetMoneyAmountRulesDTO[],
@MedusaContext() sharedContext: Context = {}
Expand All @@ -107,10 +99,7 @@ export default class PriceSetMoneyAmountRulesService<
)) as TEntity[]
}

@InjectTransactionManager(
doNotForceTransaction,
"priceSetMoneyAmountRulesRepository_"
)
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
async delete(
ids: string[],
@MedusaContext() sharedContext: Context = {}
Expand Down

0 comments on commit f88d75b

Please sign in to comment.