feat(core-flows,medusa): added api + workflows for rule types CRUD (#6684)
This commit is contained in:
@@ -107,6 +107,122 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/pricing/rule-types", () => {
|
||||
it("should throw an error if required params are not passed", async () => {
|
||||
const { response } = await api
|
||||
.post(
|
||||
`/admin/pricing/rule-types`,
|
||||
{
|
||||
rule_attribute: "rule_attr_test1",
|
||||
default_priority: 7,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(response.status).toEqual(400)
|
||||
expect(response.data.message).toEqual(
|
||||
"name must be a string, name should not be empty"
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a rule type successfully", async () => {
|
||||
const response = await api.post(
|
||||
`/admin/pricing/rule-types`,
|
||||
{
|
||||
name: "test",
|
||||
rule_attribute: "rule_attr_test",
|
||||
default_priority: 6,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.rule_type).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "test",
|
||||
rule_attribute: "rule_attr_test",
|
||||
default_priority: 6,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/pricing/rule-types/:id", () => {
|
||||
it("should throw an error if id does not exist", async () => {
|
||||
const { response } = await api
|
||||
.post(`/admin/pricing/rule-types/does-not-exist`, {}, adminHeaders)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(response.status).toEqual(404)
|
||||
expect(response.data.message).toEqual(
|
||||
`RuleType with id "does-not-exist" not found`
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a rule type successfully", async () => {
|
||||
const [ruleType] = ruleTypes
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/pricing/rule-types/${ruleType.id}`,
|
||||
{
|
||||
name: "test update",
|
||||
rule_attribute: "test_update",
|
||||
default_priority: 7,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.rule_type).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "test update",
|
||||
rule_attribute: "test_update",
|
||||
default_priority: 7,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("DELETE /admin/pricing/rule-types/:id", () => {
|
||||
it("should delete rule type successfully", async () => {
|
||||
const [ruleType] = ruleTypes
|
||||
const response = await api.delete(
|
||||
`/admin/pricing/rule-types/${ruleType.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
console.log("response.data -- ", response.data)
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
id: ruleType.id,
|
||||
object: "rule_type",
|
||||
deleted: true,
|
||||
})
|
||||
|
||||
const deletedRuleTypes = await pricingModule.listRuleTypes({
|
||||
id: [ruleType.id],
|
||||
})
|
||||
|
||||
expect(deletedRuleTypes.length).toEqual(0)
|
||||
})
|
||||
|
||||
it("should return 200 when id does not exist", async () => {
|
||||
const response = await api.delete(
|
||||
`/admin/pricing/rule-types/does-not-exist`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
id: "does-not-exist",
|
||||
object: "rule_type",
|
||||
deleted: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user