@@ -108,6 +108,10 @@ afterAll(async () => {
108108 process . env = originalEnv ;
109109} ) ;
110110
111+ const allBenchmarkProviders = Object . values (
112+ BenchmarkProviders ,
113+ ) as BenchmarkProviders [ ] ;
114+
111115describe ( 'Benchmark wizard API' , ( ) => {
112116 const postWizard = async ( {
113117 provider,
@@ -127,61 +131,68 @@ describe('Benchmark wizard API', () => {
127131
128132 describe ( 'POST /v1/benchmarks/:provider/wizard' , ( ) => {
129133 beforeEach ( ( ) => {
134+ wizardServiceMock . resolveWizardNavigation . mockClear ( ) ;
130135 wizardServiceMock . resolveWizardNavigation . mockResolvedValue (
131136 mockWizardStep ,
132137 ) ;
133138 process . env . OPS_FINOPS_BENCHMARK_ENABLED = 'true' ;
134139 } ) ;
135140
136- it ( 'calls resolveWizardNavigation with AWS provider, body, and projectId and returns mocked step' , async ( ) => {
137- const { token, project } = await createAndInsertMocks ( ) ;
138- const body = { } ;
139-
140- const response = await postWizard ( {
141- provider : BenchmarkProviders . AWS ,
142- token,
143- body,
144- } ) ;
145-
146- expect ( response ?. statusCode ) . toBe ( StatusCodes . OK ) ;
147- expect ( response ?. json ( ) ) . toEqual ( mockWizardStep ) ;
148- expect ( wizardServiceMock . resolveWizardNavigation ) . toHaveBeenCalledTimes (
149- 1 ,
150- ) ;
151- expect ( wizardServiceMock . resolveWizardNavigation ) . toHaveBeenCalledWith (
152- BenchmarkProviders . AWS ,
153- {
154- currentStep : undefined ,
155- benchmarkConfiguration : undefined ,
156- } ,
157- project . id ,
158- ) ;
159- } ) ;
160-
161- it ( 'passes currentStep and benchmarkConfiguration to resolveWizardNavigation' , async ( ) => {
162- const { token, project } = await createAndInsertMocks ( ) ;
163- const body = {
164- currentStep : 'connection' ,
165- benchmarkConfiguration : { connection : [ 'conn-1' ] } ,
166- } ;
167-
168- const response = await postWizard ( {
169- provider : BenchmarkProviders . AWS ,
170- token,
171- body,
172- } ) ;
141+ it . each ( allBenchmarkProviders ) (
142+ 'calls resolveWizardNavigation with %s provider, body, and projectId and returns mocked step' ,
143+ async ( provider ) => {
144+ const { token, project } = await createAndInsertMocks ( ) ;
145+ const body = { } ;
146+
147+ const response = await postWizard ( {
148+ provider,
149+ token,
150+ body,
151+ } ) ;
152+
153+ expect ( response ?. statusCode ) . toBe ( StatusCodes . OK ) ;
154+ expect ( response ?. json ( ) ) . toEqual ( mockWizardStep ) ;
155+ expect ( wizardServiceMock . resolveWizardNavigation ) . toHaveBeenCalledTimes (
156+ 1 ,
157+ ) ;
158+ expect ( wizardServiceMock . resolveWizardNavigation ) . toHaveBeenCalledWith (
159+ provider ,
160+ {
161+ currentStep : undefined ,
162+ benchmarkConfiguration : undefined ,
163+ } ,
164+ project . id ,
165+ ) ;
166+ } ,
167+ ) ;
173168
174- expect ( response ?. statusCode ) . toBe ( StatusCodes . OK ) ;
175- expect ( response ?. json ( ) ) . toEqual ( mockWizardStep ) ;
176- expect ( wizardServiceMock . resolveWizardNavigation ) . toHaveBeenCalledWith (
177- BenchmarkProviders . AWS ,
178- {
169+ it . each ( allBenchmarkProviders ) (
170+ 'passes currentStep and benchmarkConfiguration to resolveWizardNavigation (%s)' ,
171+ async ( provider ) => {
172+ const { token , project } = await createAndInsertMocks ( ) ;
173+ const body = {
179174 currentStep : 'connection' ,
180175 benchmarkConfiguration : { connection : [ 'conn-1' ] } ,
181- } ,
182- project . id ,
183- ) ;
184- } ) ;
176+ } ;
177+
178+ const response = await postWizard ( {
179+ provider,
180+ token,
181+ body,
182+ } ) ;
183+
184+ expect ( response ?. statusCode ) . toBe ( StatusCodes . OK ) ;
185+ expect ( response ?. json ( ) ) . toEqual ( mockWizardStep ) ;
186+ expect ( wizardServiceMock . resolveWizardNavigation ) . toHaveBeenCalledWith (
187+ provider ,
188+ {
189+ currentStep : 'connection' ,
190+ benchmarkConfiguration : { connection : [ 'conn-1' ] } ,
191+ } ,
192+ project . id ,
193+ ) ;
194+ } ,
195+ ) ;
185196
186197 it ( 'returns 400 when provider is not in BenchmarkProviders enum' , async ( ) => {
187198 const { token } = await createAndInsertMocks ( ) ;
@@ -254,38 +265,49 @@ describe('Benchmark wizard API', () => {
254265} ) ;
255266
256267describe ( 'Create Benchmark API (POST /v1/benchmarks/:provider)' , ( ) => {
257- const validCreateBody = {
268+ const validAwsCreateBody = {
258269 benchmarkConfiguration : {
259270 connection : [ 'conn-1' ] ,
260271 workflows : [ 'AWS Benchmark - Unattached EBS' ] ,
261272 regions : [ 'us-east-1' ] ,
262273 } ,
263274 } ;
264275
265- const mockCreateResult = {
276+ const validAzureCreateBody = {
277+ benchmarkConfiguration : {
278+ connection : [ 'conn-1' ] ,
279+ workflows : [ 'Azure Benchmark - Unattached Managed Disks' ] ,
280+ regions : [ 'eastus' ] ,
281+ subscriptions : [ 'sub-a' , 'sub-b' ] ,
282+ } ,
283+ } ;
284+
285+ const mockCreateBenchmarkWorkflows = [
286+ {
287+ flowId : 'flow-1' ,
288+ displayName : 'Orchestrator' ,
289+ isOrchestrator : true ,
290+ isCleanup : false ,
291+ } ,
292+ {
293+ flowId : 'flow-2' ,
294+ displayName : 'Cleanup' ,
295+ isOrchestrator : false ,
296+ isCleanup : true ,
297+ } ,
298+ {
299+ flowId : 'flow-3' ,
300+ displayName : 'Sub' ,
301+ isOrchestrator : false ,
302+ isCleanup : false ,
303+ } ,
304+ ] ;
305+
306+ const mockAwsCreateResult = {
266307 benchmarkId : 'bench-1' ,
267308 folderId : 'folder-1' ,
268- provider : 'aws' ,
269- workflows : [
270- {
271- flowId : 'flow-1' ,
272- displayName : 'Orchestrator' ,
273- isOrchestrator : true ,
274- isCleanup : false ,
275- } ,
276- {
277- flowId : 'flow-2' ,
278- displayName : 'Cleanup' ,
279- isOrchestrator : false ,
280- isCleanup : true ,
281- } ,
282- {
283- flowId : 'flow-3' ,
284- displayName : 'Sub' ,
285- isOrchestrator : false ,
286- isCleanup : false ,
287- } ,
288- ] ,
309+ provider : BenchmarkProviders . AWS ,
310+ workflows : mockCreateBenchmarkWorkflows ,
289311 webhookPayload : {
290312 webhookBaseUrl : 'https://api.example.com' ,
291313 workflows : [ 'flow-3' ] ,
@@ -295,6 +317,37 @@ describe('Create Benchmark API (POST /v1/benchmarks/:provider)', () => {
295317 } ,
296318 } ;
297319
320+ const mockAzureCreateResult = {
321+ benchmarkId : 'bench-1' ,
322+ folderId : 'folder-1' ,
323+ provider : BenchmarkProviders . AZURE ,
324+ workflows : mockCreateBenchmarkWorkflows ,
325+ webhookPayload : {
326+ webhookBaseUrl : 'https://api.example.com' ,
327+ workflows : [ 'flow-3' ] ,
328+ cleanupWorkflows : [ 'flow-2' ] ,
329+ subscriptions : [ 'sub-a' , 'sub-b' ] ,
330+ regions : [ 'eastus' ] ,
331+ } ,
332+ } ;
333+
334+ const createBenchmarkSuccessCases : ReadonlyArray < {
335+ provider : BenchmarkProviders ;
336+ body : typeof validAwsCreateBody | typeof validAzureCreateBody ;
337+ mockResult : typeof mockAwsCreateResult | typeof mockAzureCreateResult ;
338+ } > = [
339+ {
340+ provider : BenchmarkProviders . AWS ,
341+ body : validAwsCreateBody ,
342+ mockResult : mockAwsCreateResult ,
343+ } ,
344+ {
345+ provider : BenchmarkProviders . AZURE ,
346+ body : validAzureCreateBody ,
347+ mockResult : mockAzureCreateResult ,
348+ } ,
349+ ] ;
350+
298351 const postCreate = async ( {
299352 provider,
300353 token,
@@ -308,41 +361,44 @@ describe('Create Benchmark API (POST /v1/benchmarks/:provider)', () => {
308361 method : 'POST' ,
309362 url : `/v1/benchmarks/${ provider } ` ,
310363 headers : token ? { authorization : `Bearer ${ token } ` } : undefined ,
311- body : body ?? validCreateBody ,
364+ body : body ?? validAwsCreateBody ,
312365 } ) ;
313366
314367 beforeEach ( ( ) => {
315368 createBenchmarkServiceMock . createBenchmark . mockReset ( ) ;
316369 process . env . OPS_FINOPS_BENCHMARK_ENABLED = 'true' ;
317370 } ) ;
318371
319- it ( 'returns 201 and BenchmarkCreationResult when body is valid' , async ( ) => {
320- createBenchmarkServiceMock . createBenchmark . mockResolvedValue (
321- mockCreateResult ,
322- ) ;
323- const { token, project } = await createAndInsertMocks ( ) ;
372+ it . each ( createBenchmarkSuccessCases ) (
373+ 'returns 201 and BenchmarkCreationResult when body is valid ($provider)' ,
374+ async ( { provider , body , mockResult } ) => {
375+ createBenchmarkServiceMock . createBenchmark . mockResolvedValue ( mockResult ) ;
376+ const { token, project } = await createAndInsertMocks ( ) ;
324377
325- const response = await postCreate ( {
326- provider : BenchmarkProviders . AWS ,
327- token,
328- body : validCreateBody ,
329- } ) ;
378+ const response = await postCreate ( {
379+ provider ,
380+ token,
381+ body ,
382+ } ) ;
330383
331- expect ( response ?. statusCode ) . toBe ( StatusCodes . CREATED ) ;
332- expect ( response ?. json ( ) ) . toEqual ( mockCreateResult ) ;
333- expect ( createBenchmarkServiceMock . createBenchmark ) . toHaveBeenCalledTimes ( 1 ) ;
334- expect ( createBenchmarkServiceMock . createBenchmark ) . toHaveBeenCalledWith ( {
335- provider : BenchmarkProviders . AWS ,
336- projectId : project . id ,
337- userId : expect . any ( String ) ,
338- benchmarkConfiguration : validCreateBody . benchmarkConfiguration ,
339- } ) ;
340- } ) ;
384+ expect ( response ?. statusCode ) . toBe ( StatusCodes . CREATED ) ;
385+ expect ( response ?. json ( ) ) . toEqual ( mockResult ) ;
386+ expect ( createBenchmarkServiceMock . createBenchmark ) . toHaveBeenCalledTimes (
387+ 1 ,
388+ ) ;
389+ expect ( createBenchmarkServiceMock . createBenchmark ) . toHaveBeenCalledWith ( {
390+ provider,
391+ projectId : project . id ,
392+ userId : expect . any ( String ) ,
393+ benchmarkConfiguration : body . benchmarkConfiguration ,
394+ } ) ;
395+ } ,
396+ ) ;
341397
342398 it ( 'returns 401 when not authenticated' , async ( ) => {
343399 const response = await postCreate ( {
344400 provider : BenchmarkProviders . AWS ,
345- body : validCreateBody ,
401+ body : validAwsCreateBody ,
346402 } ) ;
347403
348404 expect ( response ?. statusCode ) . toBe ( StatusCodes . UNAUTHORIZED ) ;
@@ -356,7 +412,7 @@ describe('Create Benchmark API (POST /v1/benchmarks/:provider)', () => {
356412 const response = await postCreate ( {
357413 provider : BenchmarkProviders . AWS ,
358414 token,
359- body : validCreateBody ,
415+ body : validAwsCreateBody ,
360416 } ) ;
361417
362418 expect ( response ?. statusCode ) . toBe ( StatusCodes . PAYMENT_REQUIRED ) ;
@@ -371,7 +427,7 @@ describe('Create Benchmark API (POST /v1/benchmarks/:provider)', () => {
371427 const response = await postCreate ( {
372428 provider : 'invalidprovider' ,
373429 token,
374- body : validCreateBody ,
430+ body : validAwsCreateBody ,
375431 } ) ;
376432
377433 expect ( response ?. statusCode ) . toBe ( StatusCodes . BAD_REQUEST ) ;
@@ -546,20 +602,23 @@ describe('List benchmarks API', () => {
546602 } ) ;
547603 } ) ;
548604
549- it ( 'passes provider filter to listBenchmarks' , async ( ) => {
550- const { token, project } = await createAndInsertMocks ( ) ;
551-
552- const response = await getBenchmarkList ( {
553- token,
554- provider : BenchmarkProviders . AWS ,
555- } ) ;
556-
557- expect ( response ?. statusCode ) . toBe ( StatusCodes . OK ) ;
558- expect ( benchmarkStatusServiceMock . listBenchmarks ) . toHaveBeenCalledWith ( {
559- projectId : project . id ,
560- provider : BenchmarkProviders . AWS ,
561- } ) ;
562- } ) ;
605+ it . each ( allBenchmarkProviders ) (
606+ 'passes provider filter to listBenchmarks (%s)' ,
607+ async ( provider ) => {
608+ const { token, project } = await createAndInsertMocks ( ) ;
609+
610+ const response = await getBenchmarkList ( {
611+ token,
612+ provider,
613+ } ) ;
614+
615+ expect ( response ?. statusCode ) . toBe ( StatusCodes . OK ) ;
616+ expect ( benchmarkStatusServiceMock . listBenchmarks ) . toHaveBeenCalledWith ( {
617+ projectId : project . id ,
618+ provider,
619+ } ) ;
620+ } ,
621+ ) ;
563622
564623 it ( 'returns 400 when provider is not a valid BenchmarkProviders value' , async ( ) => {
565624 const { token } = await createAndInsertMocks ( ) ;
0 commit comments