fix(tax): Add indexes to enforce unique constraint on tax region (#8067)
This commit is contained in:
1 parent
74c19308a0
commit
256912f392
4 files changed
+226
-3
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { ITaxModuleService } from "@medusajs/types"
|
||||
import { setupTaxStructure } from "../utils/setup-tax-structure"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { TaxModuleService } from "@services"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { setupTaxStructure } from "../utils/setup-tax-structure"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -62,6 +62,191 @@ moduleIntegrationTestRunner<ITaxModuleService>({
|
||||
})
|
||||
})
|
||||
|
||||
it("should create tax region", async () => {
|
||||
const region = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
expect(region).toEqual(
|
||||
expect.objectContaining({
|
||||
id: region.id,
|
||||
country_code: "us",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create two tax regions with the same country code but different province", async () => {
|
||||
const regionOne = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
province_code: "CA",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
const regionTwo = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
province_code: "NY",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
expect(regionOne).toEqual(
|
||||
expect.objectContaining({
|
||||
id: regionOne.id,
|
||||
country_code: "us",
|
||||
province_code: "ca",
|
||||
})
|
||||
)
|
||||
|
||||
expect(regionTwo).toEqual(
|
||||
expect.objectContaining({
|
||||
id: regionTwo.id,
|
||||
country_code: "us",
|
||||
province_code: "ny",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create two tax regions in a child-parent-like relationship", async () => {
|
||||
const regionOne = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
const regionTwo = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
parent_id: regionOne.id,
|
||||
province_code: "NY",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
expect(regionOne).toEqual(
|
||||
expect.objectContaining({
|
||||
id: regionOne.id,
|
||||
country_code: "us",
|
||||
province_code: null,
|
||||
})
|
||||
)
|
||||
|
||||
expect(regionTwo).toEqual(
|
||||
expect.objectContaining({
|
||||
id: regionTwo.id,
|
||||
country_code: "us",
|
||||
province_code: "ny",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create three tax regions in a child-parent-like relationship", async () => {
|
||||
const regionOne = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
const regionTwo = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
parent_id: regionOne.id,
|
||||
province_code: "NY",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
const regionThree = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
parent_id: regionOne.id,
|
||||
province_code: "NE",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
expect(regionOne).toEqual(
|
||||
expect.objectContaining({
|
||||
id: regionOne.id,
|
||||
country_code: "us",
|
||||
province_code: null,
|
||||
})
|
||||
)
|
||||
|
||||
expect(regionTwo).toEqual(
|
||||
expect.objectContaining({
|
||||
id: regionTwo.id,
|
||||
country_code: "us",
|
||||
province_code: "ny",
|
||||
})
|
||||
)
|
||||
|
||||
expect(regionThree).toEqual(
|
||||
expect.objectContaining({
|
||||
id: regionThree.id,
|
||||
country_code: "us",
|
||||
province_code: "ne",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw when creating a tax region with a country code of an existing region", async () => {
|
||||
await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
const error = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
}).catch(e => e)
|
||||
|
||||
expect(error.message).toEqual("Tax region with country_code: us, already exists.")
|
||||
})
|
||||
|
||||
it("should throw when creating a tax region with a country code and province code of an existing region", async () => {
|
||||
await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
province_code: "CA",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
})
|
||||
|
||||
const error = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
province_code: "CA",
|
||||
default_tax_rate: {
|
||||
name: "Test Rate",
|
||||
rate: 0.2,
|
||||
},
|
||||
}).catch(e => e)
|
||||
|
||||
expect(error.message).toEqual("Tax region with country_code: us, province_code: ca, already exists.")
|
||||
})
|
||||
|
||||
it("should create tax rates and update them", async () => {
|
||||
const region = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
|
||||
Reference in new issue
Block a user