Skip to content

Commit 5e039c0

Browse files
committed
feat: reformatted-tests-handling-new-structure
1 parent cdbb62c commit 5e039c0

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

sdk/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { buildEnvironmentModel } from '../flagsmith-engine/environments/util.js'
44

55
import { ANALYTICS_ENDPOINT, AnalyticsProcessor } from './analytics.js';
66
import { BaseOfflineHandler } from './offline_handlers.js';
7-
import { FlagsmithAPIError } from './errors.js';
7+
import { FlagsmithAPIError, FlagsmithClientError } from './errors.js';
88

99
import { DefaultFlag, Flags } from './models.js';
1010
import { EnvironmentDataPollingManager } from './polling_manager.js';
@@ -279,6 +279,9 @@ export class Flagsmith {
279279
);
280280

281281
const context = getEvaluationContext(environment, identityModel);
282+
if (!context) {
283+
throw new FlagsmithClientError('Local evaluation required to obtain identity segments');
284+
}
282285
const evaluationResult = getEvaluationResult(context);
283286

284287
return SegmentModel.fromSegmentResult(evaluationResult.segments, context);
@@ -401,6 +404,9 @@ export class Flagsmith {
401404
private async getEnvironmentFlagsFromDocument(): Promise<Flags> {
402405
const environment = await this.getEnvironment();
403406
const context = getEvaluationContext(environment);
407+
if (!context) {
408+
throw new FlagsmithClientError('Unable to get flags. No environment present.');
409+
}
404410
const evaluationResult = getEvaluationResult(context);
405411
const flags = Flags.fromEvaluationResult(evaluationResult);
406412

@@ -426,6 +432,9 @@ export class Flagsmith {
426432
);
427433

428434
const context = getEvaluationContext(environment, identityModel);
435+
if (!context) {
436+
throw new FlagsmithClientError('Unable to get flags. No environment present.');
437+
}
429438
const evaluationResult = getEvaluationResult(context);
430439

431440
const flags = Flags.fromEvaluationResult(

tests/engine/e2e/engine.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ test('Test Engine', () => {
2424
const sortedEngineFlags = flags
2525
.allFlags()
2626
.sort((a, b) => (a.featureName > b.featureName ? 1 : -1));
27-
const sortedAPIFlags = testCase.response['flags'].sort((a: any, b: any) =>
27+
28+
const expectedFlags = testCase.response['flags'] || {};
29+
const sortedAPIFlags = Object.values(expectedFlags).sort((a: any, b: any) =>
2830
a.name > b.name ? 1 : -1
29-
);
31+
) as Flags[];
3032

3133
expect(sortedEngineFlags.length).toBe(sortedAPIFlags.length);
3234

tests/engine/unit/segments/segment_evaluators.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {
1818
EvaluationContext,
1919
InSegmentCondition,
2020
SegmentCondition,
21-
SegmentCondition1,
22-
SegmentContext
21+
SegmentCondition1
2322
} from '../../../../flagsmith-engine/evaluation/models.js';
2423

2524
// todo: work out how to implement this in a test function or before hook

0 commit comments

Comments
 (0)