Files
medusa-store/integration-tests/modules/__tests__/customer-group/admin/update-customer-group.ts
Stevche Radevski 12b035cb18 chore(tests): Try to use the api integration tests for v2 (#6588)
Few things to keep in mind:
1. You need to set MEDUSA_FF_MEDUSA_V2 to true before running the tests to run with the v2 API
2. You can use the `breaking` function to differentiate between v1 and v2 differences. This can help us identify what was breaking pretty quickly afterwards
3. You will need to run specific tests for now instead of all if you want to target v2. I think that's fine though, as we don't really need these to run on every PR until we have feature parity (and by then, all tests would be both v1 and v2 compatible)


**note: Adrien** 
- add a new way to load modules only to run their loaders comparable to the way to run the migrations only
- improve tests runner to cleanup the data properly as well as re running all loaders and core defaults

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-03-07 08:05:43 +00:00

55 lines
1.5 KiB
TypeScript

import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customer-groups/:id", () => {
let appContainer
let customerModuleService: ICustomerModuleService
beforeAll(async () => {
appContainer = getContainer()
customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
})
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders, appContainer)
})
it("should update a customer group", async () => {
const customer = await customerModuleService.createCustomerGroup({
name: "VIP",
})
const response = await api.post(
`/admin/customer-groups/${customer.id}`,
{
name: "regular",
},
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.customer_group).toEqual(
expect.objectContaining({
id: expect.any(String),
name: "regular",
})
)
})
})
},
})