File tree Expand file tree Collapse file tree
packages/server/api/test/unit/benchmark Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ jest . mock ( '@openops/server-shared' , ( ) => ( {
2+ system : {
3+ getBoolean : jest . fn ( ) ,
4+ } ,
5+ AppSystemProp : {
6+ FINOPS_BENCHMARK_ENABLED : 'FINOPS_BENCHMARK_ENABLED' ,
7+ } ,
8+ logger : {
9+ info : jest . fn ( ) ,
10+ } ,
11+ } ) ) ;
12+
13+ import { logger , system } from '@openops/server-shared' ;
14+
15+ const mockSystem = system as jest . Mocked < typeof system > ;
16+
17+ import { benchmarkFeatureGuard } from '../../../src/app/benchmark/benchmark-feature-guard' ;
18+
19+ describe ( 'benchmarkFeatureGuard' , ( ) => {
20+ const projectId = 'project-id' ;
21+ const organizationId = 'org-id' ;
22+
23+ beforeEach ( ( ) => {
24+ jest . clearAllMocks ( ) ;
25+ } ) ;
26+
27+ it ( 'should throw error if FINOPS_BENCHMARK_ENABLED is not enabled' , async ( ) => {
28+ mockSystem . getBoolean . mockReturnValue ( false ) ;
29+
30+ await expect (
31+ benchmarkFeatureGuard . assertBenchmarkFeatureEnabled (
32+ projectId ,
33+ organizationId ,
34+ ) ,
35+ ) . rejects . toThrow (
36+ expect . objectContaining ( {
37+ message : 'FEATURE_DISABLED: Benchmark feature is not enabled' ,
38+ } ) ,
39+ ) ;
40+
41+ expect ( logger . info ) . toHaveBeenCalledWith (
42+ 'Benchmark access denied: FINOPS_BENCHMARK_ENABLED flag is not enabled' ,
43+ { provider : undefined , projectId } ,
44+ ) ;
45+ } ) ;
46+
47+ it ( 'should pass when FINOPS_BENCHMARK_ENABLED is true' , async ( ) => {
48+ mockSystem . getBoolean . mockReturnValue ( true ) ;
49+
50+ await expect (
51+ benchmarkFeatureGuard . assertBenchmarkFeatureEnabled (
52+ projectId ,
53+ organizationId ,
54+ ) ,
55+ ) . resolves . toBeUndefined ( ) ;
56+ } ) ;
57+ } ) ;
You can’t perform that action at this time.
0 commit comments