Files
William Bouchard 087887fefb feat(core-flows): support ad hoc returns (#13598)
* feat(core-flows): support ad hoc returns

* fix: missing transform

* handle edge case

* refactor

* replace gte for gt

* cleanup

* weird bug fix

* add test

* Create quick-nails-kick.md

* stop sending empty strings

* add code to refund reason

* fix build

* fix tests

* handle code in dashboard

* fix tests

* more tests failing

* add reference and reference id to credit lieng

* rework create refund form
2025-09-30 07:38:50 -04:00

161 lines
4.8 KiB
TypeScript

import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../helpers/create-admin-user"
jest.setTimeout(30000)
medusaIntegrationTestRunner({
testSuite: ({ dbConnection, api, getContainer }) => {
let refundReason1
let refundReason2
beforeEach(async () => {
const appContainer = getContainer()
await createAdminUser(dbConnection, adminHeaders, appContainer)
refundReason1 = (
await api.post(
"/admin/refund-reasons",
{ label: "reason 1 - too big", code: "too_big" },
adminHeaders
)
).data.refund_reason
refundReason2 = (
await api.post(
"/admin/refund-reasons",
{ label: "reason 2 - too small", code: "too_small" },
adminHeaders
)
).data.refund_reason
})
describe("GET /admin/refund-reasons", () => {
it("should list refund reasons and query count", async () => {
const response = await api
.get("/admin/refund-reasons", adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(5) // There are 3 default ones
expect(response.data.refund_reasons).toEqual(
expect.arrayContaining([
expect.objectContaining({ label: "Customer Care Adjustment", code: "customer_care_adjustment" }),
expect.objectContaining({ label: "Shipping Issue", code: "shipping_issue" }),
expect.objectContaining({ label: "Pricing Error", code: "pricing_error" }),
expect.objectContaining({ label: "reason 1 - too big", code: "too_big" }),
expect.objectContaining({ label: "reason 2 - too small", code: "too_small" }),
])
)
})
it("should list refund-reasons with specific query", async () => {
const response = await api.get(
"/admin/refund-reasons?q=1",
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.refund_reasons).toEqual(
expect.arrayContaining([
expect.objectContaining({
label: "reason 1 - too big",
}),
])
)
})
})
describe("POST /admin/refund-reasons", () => {
it("should create a refund reason", async () => {
const response = await api.post(
"/admin/refund-reasons",
{
label: "reason test",
code: "reason_test",
description: "test description",
},
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.refund_reason).toEqual(
expect.objectContaining({
label: "reason test",
code: "reason_test",
description: "test description",
})
)
})
})
describe("POST /admin/refund-reasons/:id", () => {
it("should correctly update refund reason", async () => {
const response = await api.post(
`/admin/refund-reasons/${refundReason1.id}`,
{
label: "reason test",
code: "reason_test",
description: "test description",
},
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.refund_reason).toEqual(
expect.objectContaining({
label: "reason test",
code: "reason_test",
description: "test description",
})
)
})
})
describe("GET /admin/refund-reasons/:id", () => {
it("should fetch a refund reason", async () => {
const response = await api.get(
`/admin/refund-reasons/${refundReason1.id}`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.refund_reason).toEqual(
expect.objectContaining({
id: refundReason1.id,
})
)
})
})
describe("DELETE /admin/refund-reasons/:id", () => {
it("should remove refund reasons", async () => {
const deleteResponse = await api.delete(
`/admin/refund-reasons/${refundReason1.id}`,
adminHeaders
)
expect(deleteResponse.data).toEqual({
id: refundReason1.id,
object: "refund_reason",
deleted: true,
})
await api
.get(`/admin/refund-reasons/${refundReason1.id}`, adminHeaders)
.catch((error) => {
expect(error.response.data.type).toEqual("not_found")
expect(error.response.data.message).toEqual(
`Refund reason with id: ${refundReason1.id.id} not found`
)
})
})
})
},
})