Files
medusa-store/integration-tests/modules/__tests__/modules/crud.methods.spec.ts
Carlos R. L. Rodrigues fd4e791428 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>
2025-08-18 13:26:36 +02:00

123 lines
3.0 KiB
TypeScript

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 **",
}),
])
})
})
},
})