fix(medusa): Expose list-currencies endpoint by removing feature flag guard (#2216)
This commit is contained in:
committed by
GitHub
parent
f863d28b9a
commit
5d75e16b1f
@@ -1,6 +1,136 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/currencies GET /admin/currencies should retrieve the currencies 1`] = `
|
||||
Object {
|
||||
"count": 120,
|
||||
"currencies": Array [
|
||||
Object {
|
||||
"code": "aed",
|
||||
"name": "United Arab Emirates Dirham",
|
||||
"symbol": "AED",
|
||||
"symbol_native": "د.إ.",
|
||||
},
|
||||
Object {
|
||||
"code": "afn",
|
||||
"name": "Afghan Afghani",
|
||||
"symbol": "Af",
|
||||
"symbol_native": "؋",
|
||||
},
|
||||
Object {
|
||||
"code": "all",
|
||||
"name": "Albanian Lek",
|
||||
"symbol": "ALL",
|
||||
"symbol_native": "Lek",
|
||||
},
|
||||
Object {
|
||||
"code": "amd",
|
||||
"name": "Armenian Dram",
|
||||
"symbol": "AMD",
|
||||
"symbol_native": "դր.",
|
||||
},
|
||||
Object {
|
||||
"code": "ars",
|
||||
"name": "Argentine Peso",
|
||||
"symbol": "AR$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "aud",
|
||||
"name": "Australian Dollar",
|
||||
"symbol": "AU$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "azn",
|
||||
"name": "Azerbaijani Manat",
|
||||
"symbol": "man.",
|
||||
"symbol_native": "ман.",
|
||||
},
|
||||
Object {
|
||||
"code": "bam",
|
||||
"name": "Bosnia-Herzegovina Convertible Mark",
|
||||
"symbol": "KM",
|
||||
"symbol_native": "KM",
|
||||
},
|
||||
Object {
|
||||
"code": "bdt",
|
||||
"name": "Bangladeshi Taka",
|
||||
"symbol": "Tk",
|
||||
"symbol_native": "৳",
|
||||
},
|
||||
Object {
|
||||
"code": "bgn",
|
||||
"name": "Bulgarian Lev",
|
||||
"symbol": "BGN",
|
||||
"symbol_native": "лв.",
|
||||
},
|
||||
Object {
|
||||
"code": "bhd",
|
||||
"name": "Bahraini Dinar",
|
||||
"symbol": "BD",
|
||||
"symbol_native": "د.ب.",
|
||||
},
|
||||
Object {
|
||||
"code": "bif",
|
||||
"name": "Burundian Franc",
|
||||
"symbol": "FBu",
|
||||
"symbol_native": "FBu",
|
||||
},
|
||||
Object {
|
||||
"code": "bnd",
|
||||
"name": "Brunei Dollar",
|
||||
"symbol": "BN$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "bob",
|
||||
"name": "Bolivian Boliviano",
|
||||
"symbol": "Bs",
|
||||
"symbol_native": "Bs",
|
||||
},
|
||||
Object {
|
||||
"code": "brl",
|
||||
"name": "Brazilian Real",
|
||||
"symbol": "R$",
|
||||
"symbol_native": "R$",
|
||||
},
|
||||
Object {
|
||||
"code": "bwp",
|
||||
"name": "Botswanan Pula",
|
||||
"symbol": "BWP",
|
||||
"symbol_native": "P",
|
||||
},
|
||||
Object {
|
||||
"code": "byn",
|
||||
"name": "Belarusian Ruble",
|
||||
"symbol": "Br",
|
||||
"symbol_native": "руб.",
|
||||
},
|
||||
Object {
|
||||
"code": "bzd",
|
||||
"name": "Belize Dollar",
|
||||
"symbol": "BZ$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "cad",
|
||||
"name": "Canadian Dollar",
|
||||
"symbol": "CA$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "cdf",
|
||||
"name": "Congolese Franc",
|
||||
"symbol": "CDF",
|
||||
"symbol_native": "FrCD",
|
||||
},
|
||||
],
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies GET /admin/currencies should retrieve the currencies 1`] = `
|
||||
Object {
|
||||
"count": 120,
|
||||
"currencies": Array [
|
||||
@@ -150,7 +280,7 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/currencies POST /admin/currencies/:code should update currency includes_tax 1`] = `
|
||||
exports[`[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies POST /admin/currencies/:code should update currency includes_tax 1`] = `
|
||||
Object {
|
||||
"currency": Object {
|
||||
"code": "aed",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
const path = require("path")
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const startServerWithEnvironment =
|
||||
require("../../../helpers/start-server-with-environment").default
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { useDb } = require("../../../helpers/use-db")
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
const { useDb, initDb } = require("../../../helpers/use-db")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
|
||||
const adminReqConfig = {
|
||||
headers: {
|
||||
@@ -16,12 +17,86 @@ describe("/admin/currencies", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("GET /admin/currencies", function () {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should retrieve the currencies", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/currencies?order=code`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.data).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/currencies/:code", function () {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should fail when attempting to update includes_tax", async () => {
|
||||
const api = useApi()
|
||||
|
||||
try {
|
||||
await api.post(
|
||||
`/admin/currencies/aed`,
|
||||
{
|
||||
includes_tax: true,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
} catch (error) {
|
||||
expect(error.response.data.message).toBe(
|
||||
"property includes_tax should not exist"
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
const [process, connection] = await startServerWithEnvironment({
|
||||
cwd,
|
||||
env: { MEDUSA_FF_TAX_INCLUSIVE_PRICING: true },
|
||||
verbose: false,
|
||||
})
|
||||
dbConnection = connection
|
||||
medusaProcess = process
|
||||
@@ -57,7 +132,7 @@ describe("/admin/currencies", () => {
|
||||
|
||||
expect(response.data).toMatchSnapshot()
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
describe("POST /admin/currencies/:code", function () {
|
||||
beforeEach(async () => {
|
||||
@@ -78,12 +153,12 @@ describe("/admin/currencies", () => {
|
||||
const response = await api.post(
|
||||
`/admin/currencies/aed`,
|
||||
{
|
||||
includes_tax: true
|
||||
includes_tax: true,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.data).toMatchSnapshot()
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/ta
|
||||
import { PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares, {
|
||||
transformBody,
|
||||
transformQuery,
|
||||
transformQuery
|
||||
} from "../../../middlewares"
|
||||
import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled"
|
||||
import { AdminGetCurrenciesParams } from "./list-currencies"
|
||||
@@ -14,7 +14,6 @@ export default (app) => {
|
||||
const route = Router()
|
||||
app.use(
|
||||
"/currencies",
|
||||
isFeatureFlagEnabled(TaxInclusivePricingFeatureFlag.key),
|
||||
route
|
||||
)
|
||||
|
||||
@@ -29,6 +28,7 @@ export default (app) => {
|
||||
route.post(
|
||||
"/:code",
|
||||
transformBody(AdminPostCurrenciesCurrencyReq),
|
||||
isFeatureFlagEnabled(TaxInclusivePricingFeatureFlag.key),
|
||||
middlewares.wrap(require("./update-currency").default)
|
||||
)
|
||||
|
||||
@@ -45,3 +45,4 @@ export type AdminCurrenciesRes = {
|
||||
|
||||
export * from "./list-currencies"
|
||||
export * from "./update-currency"
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { IsBoolean, IsOptional, IsString } from "class-validator"
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { Currency } from "../../../../models"
|
||||
import { CurrencyService } from "../../../../services"
|
||||
import { FindPaginationParams } from "../../../../types/common"
|
||||
import { ExtendedRequest } from "../../../../types/global"
|
||||
import { FindConfig, FindPaginationParams } from "../../../../types/common"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
|
||||
/**
|
||||
* @oas [get] /currencies
|
||||
@@ -66,8 +68,10 @@ export class AdminGetCurrenciesParams extends FindPaginationParams {
|
||||
@IsOptional()
|
||||
code?: string
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@FeatureFlagDecorators(TaxInclusivePricingFeatureFlag.key, [
|
||||
IsBoolean(),
|
||||
IsOptional(),
|
||||
])
|
||||
includes_tax?: boolean
|
||||
|
||||
@IsString()
|
||||
|
||||
Reference in New Issue
Block a user