feat(medusa): add currency to region responses (#5857)
Resolves https://github.com/medusajs/medusa/issues/5837
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/regions Remove region from country on delete successfully creates a region with countries from a previously deleted region 1`] = `
|
||||
exports[`/admin/regions Remove region from country on delete should successfully creates a region with countries from a previously deleted region 1`] = `
|
||||
Object {
|
||||
"deleted": true,
|
||||
"id": "test-region",
|
||||
@@ -8,7 +8,7 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/regions Remove region from country on delete successfully creates a region with countries from a previously deleted region 2`] = `
|
||||
exports[`/admin/regions Remove region from country on delete should successfully creates a region with countries from a previously deleted region 2`] = `
|
||||
Object {
|
||||
"automatic_taxes": true,
|
||||
"countries": Array [
|
||||
@@ -23,6 +23,12 @@ Object {
|
||||
},
|
||||
],
|
||||
"created_at": Any<String>,
|
||||
"currency": Object {
|
||||
"code": "usd",
|
||||
"name": "US Dollar",
|
||||
"symbol": "$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"fulfillment_providers": Array [
|
||||
|
||||
@@ -55,15 +55,11 @@ describe("/admin/regions", () => {
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("successfully creates a region with countries from a previously deleted region", async () => {
|
||||
it("should successfully creates a region with countries from a previously deleted region", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.delete(`/admin/regions/test-region`, {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
})
|
||||
.delete(`/admin/regions/test-region`, adminReqConfig)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
@@ -85,11 +81,7 @@ describe("/admin/regions", () => {
|
||||
fulfillment_providers: ["test-ful"],
|
||||
countries: ["us"],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(newReg.status).toEqual(200)
|
||||
@@ -153,15 +145,28 @@ describe("/admin/regions", () => {
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("only returns non-deleted regions", async () => {
|
||||
it("should list the regions with expand currency relation", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
"/admin/regions?limit=1&offset=1&expand=currency",
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.regions[0].currency).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should only return non-deleted regions", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get(`/admin/regions`, {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
})
|
||||
.get(`/admin/regions`, adminReqConfig)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
@@ -183,29 +188,21 @@ describe("/admin/regions", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("returns count of total regions", async () => {
|
||||
it("should return count of total regions", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(`/admin/regions?limit=2`, {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
})
|
||||
const response = await api.get(`/admin/regions?limit=2`, adminReqConfig)
|
||||
|
||||
expect(response.data.regions).toHaveLength(2)
|
||||
expect(response.data.count).toEqual(3)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("filters correctly on update", async () => {
|
||||
it("should filter correctly on update", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get(`/admin/regions?updated_at[gt]=10-10-2005`, {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
})
|
||||
.get(`/admin/regions?updated_at[gt]=10-10-2005`, adminReqConfig)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
@@ -225,6 +222,59 @@ describe("/admin/regions", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/regions/:id", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
await manager.insert(Region, {
|
||||
id: "region-id",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should retrieve the region from ID", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/regions/region-id?expand=currency`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.region).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "region-id",
|
||||
currency: expect.objectContaining({
|
||||
code: "usd",
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when region ID is invalid", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const error = await api
|
||||
.get(`/admin/regions/invalid-region-id`, adminReqConfig)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.response.status).toEqual(404)
|
||||
|
||||
expect(error.response.data).toEqual({
|
||||
type: "not_found",
|
||||
message: "Region with invalid-region-id was not found",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("DELETE /admin/regions/:id", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
@@ -246,7 +296,7 @@ describe("/admin/regions", () => {
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("successfully deletes a region with a fulfillment provider", async () => {
|
||||
it("should successfully deletes a region with a fulfillment provider", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// add fulfillment provider to the region
|
||||
@@ -255,19 +305,11 @@ describe("/admin/regions", () => {
|
||||
{
|
||||
fulfillment_providers: ["test-ful"],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const response = await api
|
||||
.delete(`/admin/regions/test-region`, {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
})
|
||||
.delete(`/admin/regions/test-region`, adminReqConfig)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
@@ -280,7 +322,7 @@ describe("/admin/regions", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("fails to create when countries exists in different region", async () => {
|
||||
it("should fails to create when countries exists in different region", async () => {
|
||||
const api = useApi()
|
||||
|
||||
try {
|
||||
@@ -294,11 +336,7 @@ describe("/admin/regions", () => {
|
||||
fulfillment_providers: ["test-ful"],
|
||||
countries: ["us"],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
} catch (error) {
|
||||
expect(error.response.status).toEqual(422)
|
||||
|
||||
Reference in New Issue
Block a user