-
-
Save Kalimaha/abe614a2f7bcf9a85ecc6ec7c24fd8f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as optimizelySDK from "@optimizely/js-web-sdk"; | |
| import OptimizelySingleton from "./index"; | |
| describe("OptimizelySingleton", () => { | |
| const localIsFeatureEnabled = jest.fn(); | |
| beforeEach(() => { | |
| optimizelySDK.createInstance = jest.fn(() => ({ | |
| isFeatureEnabled: (featureName, userId) => localIsFeatureEnabled(featureName, userId), | |
| })); | |
| }); | |
| describe("when the member's ID is provided", () => { | |
| it("invokes Optimizely with the member's ID", () => { | |
| OptimizelySingleton.isFeatureEnabled("FEATURE_SPAM", 42); | |
| expect(localIsFeatureEnabled).toHaveBeenCalledWith("FEATURE_SPAM", "MEMBER:42"); | |
| }); | |
| }); | |
| describe("when the member's ID is NOT provided", () => { | |
| it("invokes Optimizely with the member's ID", () => { | |
| OptimizelySingleton.isFeatureEnabled("FEATURE_EGGS", undefined); | |
| expect(localIsFeatureEnabled).toHaveBeenCalledWith("FEATURE_EGGS", "MEMBER:ANONYMOUS"); | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import OptimizelySingleton from "./optimizely/index"; | |
| export function loginToTheFrontEnabled() { | |
| return typeof FEATURE_LOGIN_TO_THE_FRONT !== "undefined" && FEATURE_LOGIN_TO_THE_FRONT === "ON"; | |
| } | |
| export function standAloneLoginEnabled() { | |
| return typeof FEATURE_STAND_ALONE_LOGIN !== "undefined" && FEATURE_STAND_ALONE_LOGIN === "ON"; | |
| } | |
| export function v2SaveAndCloseProperty() { | |
| return ( | |
| typeof FEATURE_V2_SAVE_AND_CLOSE_PROPERTY !== "undefined" && | |
| FEATURE_V2_SAVE_AND_CLOSE_PROPERTY === "ON" | |
| ); | |
| } | |
| export function v2SaveAndClosePerson() { | |
| return ( | |
| typeof FEATURE_V2_SAVE_AND_CLOSE_PERSON !== "undefined" && | |
| FEATURE_V2_SAVE_AND_CLOSE_PERSON === "ON" | |
| ); | |
| } | |
| export function inspectionsEnabled() { | |
| return typeof FEATURE_INSPECTIONS !== "undefined" && FEATURE_INSPECTIONS === "ON"; | |
| } | |
| export function freeAreaBannerEnabled() { | |
| return typeof FEATURE_INSPECTIONS !== "undefined" && FEATURE_TOWNSVILLE_FLOODS_BANNER === "ON"; | |
| } | |
| export function breadcrumbsEnabled() { | |
| return typeof FEATURE_BREADCRUMBS !== "undefined" && FEATURE_BREADCRUMBS === "ON"; | |
| } | |
| export function paginationEnabled() { | |
| return typeof FEATURE_PAGINATION !== "undefined" && FEATURE_PAGINATION === "ON"; | |
| } | |
| export function propertyBoostEnabled() { | |
| return typeof FEATURE_PROPERTY_BOOST !== "undefined" && FEATURE_PROPERTY_BOOST === "ON"; | |
| } | |
| export function roomFeaturesEnabled() { | |
| return typeof FEATURE_ROOM_FEATURES !== "undefined" && FEATURE_ROOM_FEATURES === "ON"; | |
| } | |
| export const enquireByRoomEnabled = memberId => | |
| OptimizelySingleton.isFeatureEnabled("FEATURE_ENQUIRE_BY_ROOM", memberId); | |
| export function focusInspectionsEnabled() { | |
| return typeof FEATURE_FOCUS_INSPECTIONS !== "undefined" && FEATURE_FOCUS_INSPECTIONS === "ON"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as optimizelySDK from "@optimizely/js-web-sdk"; | |
| const OptimizelySingleton = (function() { | |
| let instance; | |
| let featuresCache = {}; | |
| const createInstance = () => { | |
| const optimizelyClient = optimizelySDK.createInstance({ | |
| sdkKey: process.env.OPTIMIZELY_KEY, | |
| logLevel: 4, | |
| }); | |
| return optimizelyClient; | |
| }; | |
| return { | |
| getInstance: () => { | |
| if (!instance) { | |
| instance = createInstance(); | |
| } | |
| return instance; | |
| }, | |
| isFeatureEnabled: (featureName, userId) => { | |
| const memberId = userId ? `MEMBER:${userId}` : "MEMBER:ANONYMOUS"; | |
| if (!featuresCache[featureName]) { | |
| featuresCache[featureName] = OptimizelySingleton.getInstance().isFeatureEnabled( | |
| featureName, | |
| memberId | |
| ); | |
| } | |
| return featuresCache[featureName]; | |
| }, | |
| }; | |
| })(); | |
| export default OptimizelySingleton; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment