diff --git a/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.test.ts b/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.test.ts index e6d23ad71..ee479df08 100644 --- a/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.test.ts +++ b/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.test.ts @@ -6,8 +6,11 @@ import { StepMappedRelationshipMetadata, StepRelationshipMetadata, } from '@jupiterone/integration-sdk-core'; -import { collectGraphObjectMetadataFromSteps } from './getSortedJupiterOneTypes'; import { randomUUID as uuid } from 'crypto'; +import { + alphabetizeMetadataProperties, + collectGraphObjectMetadataFromSteps, +} from './getSortedJupiterOneTypes'; function createIntegrationStep({ entities = [], @@ -214,3 +217,63 @@ describe('collectGraphObjectMetadataFromSteps', () => { }); }); }); + +describe('alphabetizeMetadataProperties', () => { + it('should correctly sort an array of StepRelationshipMetadata', () => { + const { relationships } = alphabetizeMetadataProperties( + collectGraphObjectMetadataFromSteps([ + createIntegrationStep({ + relationships: [ + { + _type: 'aws_account_has_service', + sourceType: 'aws_account', + _class: RelationshipClass.HAS, + targetType: 'aws_waf', + }, + ], + }), + createIntegrationStep({ + relationships: [ + { + _type: 'aws_account_owns_service', + sourceType: 'aws_account', + _class: RelationshipClass.OWNS, + targetType: 'aws_apigateway', + }, + ], + }), + createIntegrationStep({ + relationships: [ + { + _type: 'aws_account_has_service', + sourceType: 'aws_account', + _class: RelationshipClass.HAS, + targetType: 'aws_apigateway', + }, + ], + }), + ]), + ); + + expect(relationships).toEqual([ + { + _type: 'aws_account_has_service', + sourceType: 'aws_account', + _class: 'HAS', + targetType: 'aws_apigateway', + }, + { + _type: 'aws_account_owns_service', + sourceType: 'aws_account', + _class: 'OWNS', + targetType: 'aws_apigateway', + }, + { + _type: 'aws_account_has_service', + sourceType: 'aws_account', + _class: 'HAS', + targetType: 'aws_waf', + }, + ]); + }); +}); diff --git a/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.ts b/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.ts index 785f03fff..ca30ac562 100644 --- a/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.ts +++ b/packages/integration-sdk-cli/src/utils/getSortedJupiterOneTypes.ts @@ -1,14 +1,14 @@ -import { loadConfig } from '../config'; -import * as path from 'path'; -import { buildStepDependencyGraph } from '@jupiterone/integration-sdk-runtime'; import { IntegrationStepExecutionContext, Step, - StepGraphObjectMetadataProperties, StepEntityMetadata, - StepRelationshipMetadata, + StepGraphObjectMetadataProperties, StepMappedRelationshipMetadata, + StepRelationshipMetadata, } from '@jupiterone/integration-sdk-core'; +import { buildStepDependencyGraph } from '@jupiterone/integration-sdk-runtime'; +import * as path from 'path'; +import { loadConfig } from '../config'; export interface TypesCommandArgs { projectPath: string; @@ -60,12 +60,19 @@ function alphabetizeRelationshipMetadataPropertyByTypeCompareFn( a: StepRelationshipMetadata, b: StepRelationshipMetadata, ): number { - if (a._type > b._type) return 1; - if (a._type < b._type) return -1; + if (a.sourceType > b.sourceType) return 1; + if (a.sourceType < b.sourceType) return -1; + + if (a.targetType > b.targetType) return 1; + if (a.targetType < b.targetType) return -1; + + if (a._class > b._class) return 1; + if (a._class < b._class) return -1; + return 0; } -function alphabetizeMetadataProperties( +export function alphabetizeMetadataProperties( metadata: StepGraphObjectMetadataProperties, ): StepGraphObjectMetadataProperties { return {