UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

88 lines (73 loc) 2.57 kB
/** * Copyright Super iPaaS Integration LLC, an IBM Company 2024 */ import { BaseAsset } from '../../../model/assets-model.js'; import { getRefsFromPolicySeqAsset } from './policy-seq-kind-helper.js'; import { POLICY } from '../../../constants/app-constants.js'; describe('policy seq kind helper function test suite', () => { it('should return correct references for a fully populated PolicySeqAsset', () => { const mockAsset: BaseAsset = { spec: { transport: [{ $ref: 'transportRef1' }, { $ref: 'transportRef2' }], monitoring: [{ $ref: 'monitoringRef' }], 'req-processing': [{ $ref: 'reqProcessingRef' }], 'res-processing': [{ $ref: 'respProcessingRef' }], iam: [{ $ref: 'iamRef' }], 'error-handling': [{ $ref: 'errorProcessingRef' }], routing: [{ $ref: 'routingRef' }], }, } as unknown as BaseAsset; const result = getRefsFromPolicySeqAsset(mockAsset); expect(result).toEqual([ { kind: POLICY, ref: 'transportRef1', isNewlyAdded: true }, { kind: POLICY, ref: 'transportRef2' , isNewlyAdded: true}, { kind: POLICY, ref: 'monitoringRef' , isNewlyAdded: true }, { kind: POLICY, ref: 'reqProcessingRef' , isNewlyAdded: true }, { kind: POLICY, ref: 'respProcessingRef' , isNewlyAdded: true }, { kind: POLICY, ref: 'iamRef' , isNewlyAdded: true }, { kind: POLICY, ref: 'errorProcessingRef' , isNewlyAdded: true }, { kind: POLICY, ref: 'routingRef' , isNewlyAdded: true }, ]); }); it('should handle an asset with missing spec fields', () => { const mockAsset: BaseAsset = { spec: { transport: [{ $ref: 'transportRef' }], }, } as unknown as BaseAsset; const result = getRefsFromPolicySeqAsset(mockAsset); expect(result).toEqual([ { kind: POLICY, ref: 'transportRef' , isNewlyAdded: true}, ]); }); it('should handle an asset with empty spec fields', () => { const mockAsset: BaseAsset = { spec: { transport: [], monitoring: [], 'req-processing': [], 'res-processing': [], iam: [], 'error-handling': [], routing: [], }, } as unknown as BaseAsset; const result = getRefsFromPolicySeqAsset(mockAsset); expect(result).toEqual([]); }); it('should handle an asset with null spec fields', () => { const mockAsset: BaseAsset = { spec: { transport: null, monitoring: null, 'req-processing': null, 'res-processing': null, iam: null, 'error-handling': null, routing: null, }, } as unknown as BaseAsset; const result = getRefsFromPolicySeqAsset(mockAsset); expect(result).toEqual([]); }); });