diff --git a/src/lib/util/feature-evaluator/client.ts b/src/lib/util/feature-evaluator/client.ts index a538786fc2..71210cd81d 100644 --- a/src/lib/util/feature-evaluator/client.ts +++ b/src/lib/util/feature-evaluator/client.ts @@ -84,9 +84,21 @@ export default class UnleashClient { const strategies = feature.strategies.map( (strategySelector): PlaygroundStrategySchema => { - const strategy = - this.getStrategy(strategySelector.name) ?? - this.getStrategy('unknown'); + const getStrategy = () => { + // the application hostname strategy relies on external + // variables to calculate its result. As such, we can't + // evaluate it in a way that makes sense. So we'll + // use the 'unknown' strategy instead. + if (strategySelector.name === 'applicationHostname') { + return this.getStrategy('unknown'); + } + return ( + this.getStrategy(strategySelector.name) ?? + this.getStrategy('unknown') + ); + }; + + const strategy = getStrategy(); const segments = strategySelector.segments diff --git a/src/lib/util/offline-unleash-client.test.ts b/src/lib/util/offline-unleash-client.test.ts index 1beca88188..0181d69378 100644 --- a/src/lib/util/offline-unleash-client.test.ts +++ b/src/lib/util/offline-unleash-client.test.ts @@ -278,6 +278,42 @@ describe('offline client', () => { ); }); + it(`returns '${playgroundStrategyEvaluation.unknownResult}' for the application hostname strategy`, async () => { + const name = 'toggle-name'; + const context = { appName: 'client-test' }; + + const client = await offlineUnleashClient({ + features: [ + { + strategies: [ + { + name: 'applicationHostname', + constraints: [], + }, + ], + stale: false, + enabled: true, + name, + type: 'experiment', + variants: [], + }, + ], + context, + logError: console.log, + }); + + const result = client.isEnabled(name, context); + + result.strategies.forEach((strategy) => + expect(strategy.result.enabled).toEqual( + playgroundStrategyEvaluation.unknownResult, + ), + ); + expect(result.result).toEqual( + playgroundStrategyEvaluation.unknownResult, + ); + }); + it('returns strategies in the order they are provided', async () => { const featureName = 'featureName'; const strategies = [