feat(workflows,medusa,utils): add medusa v2 feature flag (#5603)

* chore: add medusa v2 feature flag

* chore: cleanup more FF

* chore: cleanup workflows FF

* chore: add comments on broken specs

* chore: added check for package registration

* chore: reenable workflows FF for create order workflow

* chore: disable FF on test cli db

* chore: hide loader validation behind FF

* chore: use medusa v2 enabled

* chore: register feature flag router in use-db

* chore: change to minro
This commit is contained in:
Riqwan Thamir
2023-11-13 16:18:05 +01:00
committed by GitHub
parent c7b8d060d7
commit cedab58339
45 changed files with 291 additions and 463 deletions
+2 -1
View File
@@ -1,4 +1,6 @@
export * from "./analytics"
export * from "./many-to-many-inventory"
export * from "./medusa-v2"
export * from "./order-editing"
export * from "./product-categories"
export * from "./publishable-api-keys"
@@ -6,4 +8,3 @@ export * from "./sales-channels"
export * from "./tax-inclusive-pricing"
export * from "./utils"
export * from "./workflows"
export * from "./many-to-many-inventory"
@@ -0,0 +1,8 @@
import { FeatureFlagTypes } from "@medusajs/types"
export const MedusaV2Flag: FeatureFlagTypes.FlagSettings = {
key: "medusa_v2",
default_val: false,
env_key: "MEDUSA_FF_MEDUSA_V2",
description: "[WIP] Enable Medusa V2",
}
@@ -1,154 +0,0 @@
import { FlagRouter } from "../flag-router"
const someFlag = {
key: "some_flag",
default_val: false,
env_key: "MEDUSA_FF_SOME_FLAG",
description: "[WIP] Enable some flag",
}
const workflows = {
key: "workflows",
default_val: {},
env_key: "MEDUSA_FF_WORKFLOWS",
description: "[WIP] Enable workflows",
}
describe("FlagRouter", function () {
it("should set a top-level flag", async function () {
const flagRouter = new FlagRouter({})
flagRouter.setFlag(someFlag.key, true)
expect(flagRouter.listFlags()).toEqual([
{
key: someFlag.key,
value: true,
},
])
})
it("should set a nested flag", async function () {
const flagRouter = new FlagRouter({})
flagRouter.setFlag(workflows.key, { createCart: true })
expect(flagRouter.listFlags()).toEqual([
{
key: workflows.key,
value: {
createCart: true,
},
},
])
})
it("should append to a nested flag", async function () {
const flagRouter = new FlagRouter({})
flagRouter.setFlag(workflows.key, { createCart: true })
flagRouter.setFlag(workflows.key, { addShippingMethod: true })
expect(flagRouter.listFlags()).toEqual([
{
key: workflows.key,
value: {
createCart: true,
addShippingMethod: true,
},
},
])
})
it("should check if top-level flag is enabled", async function () {
const flagRouter = new FlagRouter({
[someFlag.key]: true,
})
const isEnabled = flagRouter.isFeatureEnabled(someFlag.key)
expect(isEnabled).toEqual(true)
})
it("should check if nested flag is enabled", async function () {
const flagRouter = new FlagRouter({
[workflows.key]: {
createCart: true,
},
})
const isEnabled = flagRouter.isFeatureEnabled({ workflows: "createCart" })
expect(isEnabled).toEqual(true)
})
it("should check if nested flag is enabled using top-level access", async function () {
const flagRouter = new FlagRouter({
[workflows.key]: {
createCart: true,
},
})
const isEnabled = flagRouter.isFeatureEnabled(workflows.key)
expect(isEnabled).toEqual(true)
})
it("should return true if top-level is enabled using nested-level access", async function () {
const flagRouter = new FlagRouter({
[workflows.key]: true,
})
const isEnabled = flagRouter.isFeatureEnabled({
[workflows.key]: "createCart",
})
expect(isEnabled).toEqual(true)
})
it("should return false if flag is disabled using top-level access", async function () {
const flagRouter = new FlagRouter({
[workflows.key]: false,
})
const isEnabled = flagRouter.isFeatureEnabled(workflows.key)
expect(isEnabled).toEqual(false)
})
it("should return false if nested flag is disabled", async function () {
const flagRouter = new FlagRouter({
[workflows.key]: {
createCart: false,
},
})
const isEnabled = flagRouter.isFeatureEnabled({ workflows: "createCart" })
expect(isEnabled).toEqual(false)
})
it("should initialize with both types of flags", async function () {
const flagRouter = new FlagRouter({
[workflows.key]: {
createCart: true,
},
[someFlag.key]: true,
})
const flags = flagRouter.listFlags()
expect(flags).toEqual([
{
key: workflows.key,
value: {
createCart: true,
},
},
{
key: someFlag.key,
value: true,
},
])
})
})