fix(utils): auto generated update method return (#13225)

* fix(utils): auto generated update method return

* tests

* cleanup

* rm unused function

* Update .changeset/young-mangos-suffer.md

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Carlos R. L. Rodrigues
2025-08-18 08:26:36 -03:00
committed by GitHub
parent 2f1c39e17e
commit fd4e791428
3 changed files with 131 additions and 7 deletions

View File

@@ -0,0 +1,122 @@
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
jest.setTimeout(100000)
process.env.ENABLE_INDEX_MODULE = "true"
medusaIntegrationTestRunner({
testSuite: ({ getContainer, dbConnection, api, dbConfig }) => {
let appContainer
beforeAll(() => {
appContainer = getContainer()
})
afterAll(() => {
process.env.ENABLE_INDEX_MODULE = "false"
})
describe("auto-generated CRUD methods", () => {
it("should create brands", async () => {
const brandModule = appContainer.resolve("brand")
const brand = await brandModule.createBrands({
name: "Medusa Brand",
})
expect(brand).toEqual(
expect.objectContaining({
id: expect.any(String),
name: "Medusa Brand",
})
)
const multipleBrands = await brandModule.createBrands([
{
name: "Medusa Brand 2",
},
{
name: "Medusa Brand 3",
},
])
expect(multipleBrands).toEqual([
expect.objectContaining({
id: expect.stringMatching("brand_"),
name: "Medusa Brand 2",
}),
expect.objectContaining({
id: expect.stringMatching("brand_"),
name: "Medusa Brand 3",
}),
])
})
it("should update brands", async () => {
const brandModule = appContainer.resolve("brand")
const multipleBrands = await brandModule.createBrands([
{
name: "Medusa Brand 2",
},
{
name: "Medusa Brand 3",
},
])
const brand = await brandModule.updateBrands({
id: multipleBrands[0].id,
name: "Medusa Brand",
})
expect(brand).toEqual(
expect.objectContaining({
id: expect.any(String),
name: "Medusa Brand",
})
)
const multipleBrandsUpdated = await brandModule.updateBrands([
{
id: multipleBrands[0].id,
name: "Medusa Brand 22",
},
{
id: multipleBrands[1].id,
name: "Medusa Brand 33",
},
])
expect(multipleBrandsUpdated).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: "Medusa Brand 22",
}),
expect.objectContaining({
id: expect.any(String),
name: "Medusa Brand 33",
}),
])
)
const multipleBrandsUpdatedWithSelector =
await brandModule.updateBrands({
selector: {
name: { $like: "Medusa Brand 22" },
},
data: {
name: "Medusa Brand **",
},
})
expect(multipleBrandsUpdatedWithSelector).toEqual([
expect.objectContaining({
id: expect.any(String),
name: "Medusa Brand **",
}),
])
})
})
},
})