diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-17 15:16:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-17 15:16:21 +0300 |
commit | 5d92a0af93588db9c6bef9ab5d81b73daebc782a (patch) | |
tree | c77e1c9c1a80e91de5d3e04c48d5082a971920be /spec/frontend/security_configuration | |
parent | 4a52a162d1b5c7dfe7b0ef90f42fd39e4bb2a863 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/security_configuration')
-rw-r--r-- | spec/frontend/security_configuration/utils_spec.js | 199 |
1 files changed, 109 insertions, 90 deletions
diff --git a/spec/frontend/security_configuration/utils_spec.js b/spec/frontend/security_configuration/utils_spec.js index eaed4532baa..241e69204d2 100644 --- a/spec/frontend/security_configuration/utils_spec.js +++ b/spec/frontend/security_configuration/utils_spec.js @@ -1,101 +1,120 @@ -import { augmentFeatures } from '~/security_configuration/utils'; - -const mockSecurityFeatures = [ - { - name: 'SAST', - type: 'SAST', - }, -]; - -const mockComplianceFeatures = [ - { - name: 'LICENSE_COMPLIANCE', - type: 'LICENSE_COMPLIANCE', - }, -]; - -const mockFeaturesWithSecondary = [ - { - name: 'DAST', - type: 'DAST', - secondary: { - type: 'DAST PROFILES', - name: 'DAST PROFILES', +import { augmentFeatures, translateScannerNames } from '~/security_configuration/utils'; +import { SCANNER_NAMES_MAP } from '~/security_configuration/components/constants'; + +describe('augmentFeatures', () => { + const mockSecurityFeatures = [ + { + name: 'SAST', + type: 'SAST', }, - }, -]; - -const mockInvalidCustomFeature = [ - { - foo: 'bar', - }, -]; - -const mockValidCustomFeature = [ - { - name: 'SAST', - type: 'SAST', - customField: 'customvalue', - }, -]; - -const mockValidCustomFeatureSnakeCase = [ - { - name: 'SAST', - type: 'SAST', - custom_field: 'customvalue', - }, -]; - -const expectedOutputDefault = { - augmentedSecurityFeatures: mockSecurityFeatures, - augmentedComplianceFeatures: mockComplianceFeatures, -}; - -const expectedOutputSecondary = { - augmentedSecurityFeatures: mockSecurityFeatures, - augmentedComplianceFeatures: mockFeaturesWithSecondary, -}; - -const expectedOutputCustomFeature = { - augmentedSecurityFeatures: mockValidCustomFeature, - augmentedComplianceFeatures: mockComplianceFeatures, -}; - -describe('returns an object with augmentedSecurityFeatures and augmentedComplianceFeatures when', () => { - it('given an empty array', () => { - expect(augmentFeatures(mockSecurityFeatures, mockComplianceFeatures, [])).toEqual( - expectedOutputDefault, - ); + ]; + + const mockComplianceFeatures = [ + { + name: 'LICENSE_COMPLIANCE', + type: 'LICENSE_COMPLIANCE', + }, + ]; + + const mockFeaturesWithSecondary = [ + { + name: 'DAST', + type: 'DAST', + secondary: { + type: 'DAST PROFILES', + name: 'DAST PROFILES', + }, + }, + ]; + + const mockInvalidCustomFeature = [ + { + foo: 'bar', + }, + ]; + + const mockValidCustomFeature = [ + { + name: 'SAST', + type: 'SAST', + customField: 'customvalue', + }, + ]; + + const mockValidCustomFeatureSnakeCase = [ + { + name: 'SAST', + type: 'SAST', + custom_field: 'customvalue', + }, + ]; + + const expectedOutputDefault = { + augmentedSecurityFeatures: mockSecurityFeatures, + augmentedComplianceFeatures: mockComplianceFeatures, + }; + + const expectedOutputSecondary = { + augmentedSecurityFeatures: mockSecurityFeatures, + augmentedComplianceFeatures: mockFeaturesWithSecondary, + }; + + const expectedOutputCustomFeature = { + augmentedSecurityFeatures: mockValidCustomFeature, + augmentedComplianceFeatures: mockComplianceFeatures, + }; + + describe('returns an object with augmentedSecurityFeatures and augmentedComplianceFeatures when', () => { + it('given an empty array', () => { + expect(augmentFeatures(mockSecurityFeatures, mockComplianceFeatures, [])).toEqual( + expectedOutputDefault, + ); + }); + + it('given an invalid populated array', () => { + expect( + augmentFeatures(mockSecurityFeatures, mockComplianceFeatures, mockInvalidCustomFeature), + ).toEqual(expectedOutputDefault); + }); + + it('features have secondary key', () => { + expect(augmentFeatures(mockSecurityFeatures, mockFeaturesWithSecondary, [])).toEqual( + expectedOutputSecondary, + ); + }); + + it('given a valid populated array', () => { + expect( + augmentFeatures(mockSecurityFeatures, mockComplianceFeatures, mockValidCustomFeature), + ).toEqual(expectedOutputCustomFeature); + }); }); - it('given an invalid populated array', () => { - expect( - augmentFeatures(mockSecurityFeatures, mockComplianceFeatures, mockInvalidCustomFeature), - ).toEqual(expectedOutputDefault); + describe('returns an object with camelcased keys', () => { + it('given a customfeature in snakecase', () => { + expect( + augmentFeatures( + mockSecurityFeatures, + mockComplianceFeatures, + mockValidCustomFeatureSnakeCase, + ), + ).toEqual(expectedOutputCustomFeature); + }); }); +}); - it('features have secondary key', () => { - expect(augmentFeatures(mockSecurityFeatures, mockFeaturesWithSecondary, [])).toEqual( - expectedOutputSecondary, - ); +describe('translateScannerNames', () => { + it.each(['', undefined, null, 1, 'UNKNOWN_SCANNER_KEY'])('returns %p as is', (key) => { + expect(translateScannerNames([key])).toEqual([key]); }); - it('given a valid populated array', () => { - expect( - augmentFeatures(mockSecurityFeatures, mockComplianceFeatures, mockValidCustomFeature), - ).toEqual(expectedOutputCustomFeature); + it('returns an empty array if no input is provided', () => { + expect(translateScannerNames([])).toEqual([]); }); -}); -describe('returns an object with camelcased keys', () => { - it('given a customfeature in snakecase', () => { - expect( - augmentFeatures( - mockSecurityFeatures, - mockComplianceFeatures, - mockValidCustomFeatureSnakeCase, - ), - ).toEqual(expectedOutputCustomFeature); + it('returns translated scanner names', () => { + expect(translateScannerNames(Object.keys(SCANNER_NAMES_MAP))).toEqual( + Object.values(SCANNER_NAMES_MAP), + ); }); }); |