fix(dashboard, medusa): validate provider for top level tax regions (#12450)

* fix(dashboard, medusa): validate provider for top level tax regions

* chore: changesets, message

* chore: add test case for province

* fix: remove comment
This commit is contained in:
Frane Polić
2025-05-12 18:04:48 +02:00
committed by GitHub
parent 92af52d133
commit 32e0194772
6 changed files with 106 additions and 17 deletions
@@ -20,12 +20,22 @@ medusaIntegrationTestRunner({
let taxRegion
beforeEach(async () => {
const parentRegion = await api.post(
"/admin/tax-regions",
{
country_code: "us",
provider_id: "tp_system",
},
adminHeaders
)
taxRegion = (
await api.post(
"/admin/tax-regions",
{
country_code: "us",
province_code: "tx",
parent_id: parentRegion.data.tax_region.id,
metadata: { test: "created" },
},
adminHeaders
@@ -83,6 +93,49 @@ medusaIntegrationTestRunner({
)
})
it("should create a province tax region without a provider", async () => {
const response = await api.post(
`/admin/tax-regions`,
{
country_code: "us",
parent_id: taxRegion.id,
province_code: "ny",
},
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.tax_region).toEqual(
expect.objectContaining({
id: expect.any(String),
country_code: "us",
province_code: "ny",
provider_id: null,
})
)
})
it("should fail to create a country tax region without a provider", async () => {
const {
response: { status, data },
} = await api
.post(
`/admin/tax-regions`,
{
country_code: "uk",
},
adminHeaders
)
.catch((err) => err)
expect(status).toEqual(400)
expect(data).toEqual({
message:
"Invalid request: Provider is required when creating a non-province tax region.",
type: "invalid_data",
})
})
it("should throw if tax region does not exist", async () => {
const {
response: { status, data },