fix(medusa): Expose list-currencies endpoint by removing feature flag guard (#2216)

This commit is contained in:
Oliver Windall Juhl authored and GitHub committed 2022-09-15 16:29:14 +02:00
1 parent f863d28b9a
commit 5d75e16b1f
4 files changed
+222 -12

No files matched your search

@@ -1,6 +1,136 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/admin/currencies GET /admin/currencies should retrieve the currencies 1`] = ` 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 { Object {
"count": 120, "count": 120,
"currencies": Array [ "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 { Object {
"currency": Object { "currency": Object {
"code": "aed", "code": "aed",
@@ -1,9 +1,10 @@
const path = require("path") const path = require("path")
const setupServer = require("../../../helpers/setup-server")
const startServerWithEnvironment = const startServerWithEnvironment =
require("../../../helpers/start-server-with-environment").default require("../../../helpers/start-server-with-environment").default
const { useApi } = require("../../../helpers/use-api") const { useApi } = require("../../../helpers/use-api")
const { useDb } = require("../../../helpers/use-db") const { useDb, initDb } = require("../../../helpers/use-db")
const adminSeeder = require("../../helpers/admin-seeder"); const adminSeeder = require("../../helpers/admin-seeder")
const adminReqConfig = { const adminReqConfig = {
headers: { headers: {
@@ -16,12 +17,86 @@ describe("/admin/currencies", () => {
let medusaProcess let medusaProcess
let dbConnection 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 () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..")) const cwd = path.resolve(path.join(__dirname, "..", ".."))
const [process, connection] = await startServerWithEnvironment({ const [process, connection] = await startServerWithEnvironment({
cwd, cwd,
env: { MEDUSA_FF_TAX_INCLUSIVE_PRICING: true }, env: { MEDUSA_FF_TAX_INCLUSIVE_PRICING: true },
verbose: false,
}) })
dbConnection = connection dbConnection = connection
medusaProcess = process medusaProcess = process
@@ -57,7 +132,7 @@ describe("/admin/currencies", () => {
expect(response.data).toMatchSnapshot() expect(response.data).toMatchSnapshot()
}) })
}); })
describe("POST /admin/currencies/:code", function () { describe("POST /admin/currencies/:code", function () {
beforeEach(async () => { beforeEach(async () => {
@@ -78,12 +153,12 @@ describe("/admin/currencies", () => {
const response = await api.post( const response = await api.post(
`/admin/currencies/aed`, `/admin/currencies/aed`,
{ {
includes_tax: true includes_tax: true,
}, },
adminReqConfig adminReqConfig
) )
expect(response.data).toMatchSnapshot() expect(response.data).toMatchSnapshot()
}) })
}); })
}) })
@@ -4,7 +4,7 @@ import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/ta
import { PaginatedResponse } from "../../../../types/common" import { PaginatedResponse } from "../../../../types/common"
import middlewares, { import middlewares, {
transformBody, transformBody,
transformQuery, transformQuery
} from "../../../middlewares" } from "../../../middlewares"
import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled" import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled"
import { AdminGetCurrenciesParams } from "./list-currencies" import { AdminGetCurrenciesParams } from "./list-currencies"
@@ -14,7 +14,6 @@ export default (app) => {
const route = Router() const route = Router()
app.use( app.use(
"/currencies", "/currencies",
isFeatureFlagEnabled(TaxInclusivePricingFeatureFlag.key),
route route
) )
@@ -29,6 +28,7 @@ export default (app) => {
route.post( route.post(
"/:code", "/:code",
transformBody(AdminPostCurrenciesCurrencyReq), transformBody(AdminPostCurrenciesCurrencyReq),
isFeatureFlagEnabled(TaxInclusivePricingFeatureFlag.key),
middlewares.wrap(require("./update-currency").default) middlewares.wrap(require("./update-currency").default)
) )
@@ -45,3 +45,4 @@ export type AdminCurrenciesRes = {
export * from "./list-currencies" export * from "./list-currencies"
export * from "./update-currency" export * from "./update-currency"
@@ -1,8 +1,10 @@
import { IsBoolean, IsOptional, IsString } from "class-validator" import { IsBoolean, IsOptional, IsString } from "class-validator"
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
import { Currency } from "../../../../models" import { Currency } from "../../../../models"
import { CurrencyService } from "../../../../services" import { CurrencyService } from "../../../../services"
import { FindPaginationParams } from "../../../../types/common"
import { ExtendedRequest } from "../../../../types/global" import { ExtendedRequest } from "../../../../types/global"
import { FindConfig, FindPaginationParams } from "../../../../types/common" import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
/** /**
* @oas [get] /currencies * @oas [get] /currencies
@@ -66,8 +68,10 @@ export class AdminGetCurrenciesParams extends FindPaginationParams {
@IsOptional() @IsOptional()
code?: string code?: string
@IsBoolean() @FeatureFlagDecorators(TaxInclusivePricingFeatureFlag.key, [
@IsOptional() IsBoolean(),
IsOptional(),
])
includes_tax?: boolean includes_tax?: boolean
@IsString() @IsString()