@@ -115,6 +115,13 @@ const defaultBenchmarkConfiguration = {
115115 regions : [ 'us-east-1' ] as string [ ] ,
116116} ;
117117
118+ const azureBenchmarkConfiguration = {
119+ connection : [ 'conn-1' ] ,
120+ workflows : [ 'Azure Benchmark - Unattached Managed Disks' ] ,
121+ subscriptions : [ 'sub-a' , 'sub-b' ] ,
122+ regions : [ 'eastus' ] as string [ ] ,
123+ } ;
124+
118125const createBenchmarkMockConnections = [
119126 {
120127 id : 'conn-1' ,
@@ -235,84 +242,117 @@ describe('create-benchmark.service', () => {
235242 expect ( flowFolderServiceMock . getOrCreate ) . not . toHaveBeenCalled ( ) ;
236243 } ) ;
237244
238- it ( 'createBenchmark returns BenchmarkCreationResult with workflows from seed' , async ( ) => {
239- const projectId = 'project-1' ;
240- const folder : Folder = {
241- id : 'folder-2' ,
242- projectId,
243- displayName : 'AWS Benchmark' ,
244- created : '' ,
245- updated : '' ,
246- contentType : ContentType . WORKFLOW ,
247- } ;
248- setupCreateBenchmarkMocks ( folder ) ;
245+ const workflowsFromSeedExpectation = [
246+ {
247+ flowId : 'flow-1' ,
248+ displayName : 'Orchestrator' ,
249+ isOrchestrator : true ,
250+ isCleanup : false ,
251+ } ,
252+ {
253+ flowId : 'flow-2' ,
254+ displayName : 'Cleanup' ,
255+ isOrchestrator : false ,
256+ isCleanup : true ,
257+ } ,
258+ {
259+ flowId : 'flow-3' ,
260+ displayName : 'Sub' ,
261+ isOrchestrator : false ,
262+ isCleanup : false ,
263+ } ,
264+ ] ;
249265
250- const result = await createBenchmark ( {
266+ it . each ( [
267+ {
268+ name : 'AWS' ,
251269 provider : BenchmarkProviders . AWS ,
252- projectId,
253- userId : 'user-1' ,
270+ folderDisplayName : 'AWS Benchmark' ,
254271 benchmarkConfiguration : defaultBenchmarkConfiguration ,
255- } ) ;
256-
257- expect ( flowFolderServiceMock . getOrCreate ) . toHaveBeenCalledWith ( {
258- projectId,
259- request : {
260- displayName : 'AWS Benchmark' ,
261- contentType : ContentType . WORKFLOW ,
262- } ,
263- } ) ;
264- expect ( result . folderId ) . toBe ( folder . id ) ;
265- expect ( result . workflows ) . toEqual ( [
266- {
267- flowId : 'flow-1' ,
268- displayName : 'Orchestrator' ,
269- isOrchestrator : true ,
270- isCleanup : false ,
271- } ,
272- {
273- flowId : 'flow-2' ,
274- displayName : 'Cleanup' ,
275- isOrchestrator : false ,
276- isCleanup : true ,
272+ expectedWebhookPayload : {
273+ webhookBaseUrl : defaultWebhookBaseUrl ,
274+ workflows : [ 'flow-3' ] ,
275+ cleanupWorkflows : [ 'flow-2' ] ,
276+ accounts : [ ] ,
277+ regions : [ 'us-east-1' ] ,
277278 } ,
278- {
279- flowId : 'flow-3' ,
280- displayName : 'Sub' ,
281- isOrchestrator : false ,
282- isCleanup : false ,
279+ } ,
280+ {
281+ name : 'Azure' ,
282+ provider : BenchmarkProviders . AZURE ,
283+ folderDisplayName : 'Azure Benchmark' ,
284+ benchmarkConfiguration : azureBenchmarkConfiguration ,
285+ expectedWebhookPayload : {
286+ webhookBaseUrl : defaultWebhookBaseUrl ,
287+ workflows : [ 'flow-3' ] ,
288+ cleanupWorkflows : [ 'flow-2' ] ,
289+ subscriptions : [ 'sub-a' , 'sub-b' ] ,
290+ regions : [ 'eastus' ] ,
283291 } ,
284- ] ) ;
285- expect ( result . benchmarkId ) . toBeDefined ( ) ;
286- expect ( result . benchmarkId ) . toHaveLength ( 21 ) ;
287- expect ( result . provider ) . toBe ( BenchmarkProviders . AWS ) ;
288- expect ( result . webhookPayload ) . toEqual ( {
289- webhookBaseUrl : defaultWebhookBaseUrl ,
290- workflows : [ 'flow-3' ] ,
291- cleanupWorkflows : [ 'flow-2' ] ,
292- accounts : [ ] ,
293- regions : [ 'us-east-1' ] ,
294- } ) ;
295- expect ( mockGetWebhookPrefix ) . toHaveBeenCalled ( ) ;
296- expect ( mockBenchmarkRepoSave ) . toHaveBeenCalledTimes ( 1 ) ;
297- expect ( mockBenchmarkFlowRepoSave ) . toHaveBeenCalledTimes ( 1 ) ;
298- expect ( mockBenchmarkFlowRepo . createQueryBuilder ) . toHaveBeenCalledWith ( 'bf' ) ;
299- expect ( mockResolveWorkflowPathsForSeed ) . toHaveBeenCalledWith (
300- 'aws' ,
301- defaultBenchmarkConfiguration . workflows ,
302- ) ;
303- expect ( mockBulkCreateAndPublishFlows ) . toHaveBeenCalledWith (
304- expect . any ( Array ) ,
305- createBenchmarkMockConnections ,
306- projectId ,
307- folder . id ,
308- ) ;
309- expect (
310- benchmarkDashboardService . createBenchmarkDashboard ,
311- ) . toHaveBeenCalledTimes ( 1 ) ;
312- expect (
313- benchmarkDashboardService . createBenchmarkDashboard ,
314- ) . toHaveBeenCalledWith ( 'aws' ) ;
315- } ) ;
292+ } ,
293+ ] ) (
294+ 'createBenchmark returns BenchmarkCreationResult with workflows from seed ($name)' ,
295+ async ( {
296+ provider,
297+ folderDisplayName,
298+ benchmarkConfiguration,
299+ expectedWebhookPayload,
300+ } ) => {
301+ const projectId = 'project-1' ;
302+ const folder : Folder = {
303+ id : 'folder-2' ,
304+ projectId,
305+ displayName : folderDisplayName ,
306+ created : '' ,
307+ updated : '' ,
308+ contentType : ContentType . WORKFLOW ,
309+ } ;
310+ setupCreateBenchmarkMocks ( folder ) ;
311+
312+ const result = await createBenchmark ( {
313+ provider,
314+ projectId,
315+ userId : 'user-1' ,
316+ benchmarkConfiguration,
317+ } ) ;
318+
319+ expect ( flowFolderServiceMock . getOrCreate ) . toHaveBeenCalledWith ( {
320+ projectId,
321+ request : {
322+ displayName : folderDisplayName ,
323+ contentType : ContentType . WORKFLOW ,
324+ } ,
325+ } ) ;
326+ expect ( result . folderId ) . toBe ( folder . id ) ;
327+ expect ( result . workflows ) . toEqual ( workflowsFromSeedExpectation ) ;
328+ expect ( result . benchmarkId ) . toBeDefined ( ) ;
329+ expect ( result . benchmarkId ) . toHaveLength ( 21 ) ;
330+ expect ( result . provider ) . toBe ( provider ) ;
331+ expect ( result . webhookPayload ) . toEqual ( expectedWebhookPayload ) ;
332+ expect ( mockGetWebhookPrefix ) . toHaveBeenCalled ( ) ;
333+ expect ( mockBenchmarkRepoSave ) . toHaveBeenCalledTimes ( 1 ) ;
334+ expect ( mockBenchmarkFlowRepoSave ) . toHaveBeenCalledTimes ( 1 ) ;
335+ expect ( mockBenchmarkFlowRepo . createQueryBuilder ) . toHaveBeenCalledWith (
336+ 'bf' ,
337+ ) ;
338+ expect ( mockResolveWorkflowPathsForSeed ) . toHaveBeenCalledWith (
339+ provider ,
340+ benchmarkConfiguration . workflows ,
341+ ) ;
342+ expect ( mockBulkCreateAndPublishFlows ) . toHaveBeenCalledWith (
343+ expect . any ( Array ) ,
344+ createBenchmarkMockConnections ,
345+ projectId ,
346+ folder . id ,
347+ ) ;
348+ expect (
349+ benchmarkDashboardService . createBenchmarkDashboard ,
350+ ) . toHaveBeenCalledTimes ( 1 ) ;
351+ expect (
352+ benchmarkDashboardService . createBenchmarkDashboard ,
353+ ) . toHaveBeenCalledWith ( provider ) ;
354+ } ,
355+ ) ;
316356
317357 it ( 'createBenchmark deletes newly created flows and rethrows when attachFlowsToBenchmark fails' , async ( ) => {
318358 const projectId = 'project-1' ;
0 commit comments