|
| 1 | +/*! |
| 2 | +This file is part of CycloneDX JavaScript Library. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +
|
| 16 | +SPDX-License-Identifier: Apache-2.0 |
| 17 | +Copyright (c) OWASP Foundation. All Rights Reserved. |
| 18 | +*/ |
| 19 | + |
| 20 | +const assert = require('assert') |
| 21 | +const { suite, test } = require('mocha') |
| 22 | + |
| 23 | +const { loadSpec, getSpecElement, getSpecEnum } = require('./specLoader') |
| 24 | + |
| 25 | +suite('test helpers: specLoader', () => { |
| 26 | + /* eslint-disable-next-line camelcase -- for better readability, JSON-path replaced `.` with `_` */ |
| 27 | + const expected_definitions_affectedStatus_enum = [ |
| 28 | + 'affected', |
| 29 | + 'unaffected', |
| 30 | + 'unknown' |
| 31 | + ] |
| 32 | + |
| 33 | + suite('loadSpec()', () => { |
| 34 | + test('unknown file', () => { |
| 35 | + assert.throws( |
| 36 | + () => { |
| 37 | + loadSpec('DOES-NOT-EXIST.schema.json') |
| 38 | + }, |
| 39 | + Error, |
| 40 | + 'missing expected error' |
| 41 | + ) |
| 42 | + }) |
| 43 | + test('happy path', () => { |
| 44 | + const loaded = loadSpec('bom-1.4.SNAPSHOT.schema.json') |
| 45 | + // dummy test to see if loading worked somehow ... |
| 46 | + assert.deepEqual(loaded.definitions.affectedStatus.enum, expected_definitions_affectedStatus_enum) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + suite('getSpecElement()', () => { |
| 51 | + test('unknown path', () => { |
| 52 | + assert.throws( |
| 53 | + () => { |
| 54 | + getSpecElement( |
| 55 | + 'bom-1.4.SNAPSHOT.schema.json', |
| 56 | + 'properties', 'UNKNOWN_PROP') |
| 57 | + }, |
| 58 | + TypeError('undefined element: bom-1.4.SNAPSHOT.schema.json#properties.UNKNOWN_PROP'), |
| 59 | + 'missing expected error' |
| 60 | + ) |
| 61 | + }) |
| 62 | + test('happy path', () => { |
| 63 | + const loaded = getSpecElement( |
| 64 | + 'bom-1.4.SNAPSHOT.schema.json', |
| 65 | + 'definitions', 'affectedStatus', 'enum') |
| 66 | + // dummy test to see if loading worked somehow ... |
| 67 | + assert.deepEqual(loaded, expected_definitions_affectedStatus_enum) |
| 68 | + }) |
| 69 | + }) |
| 70 | + |
| 71 | + suite('getSpecEnum()', () => { |
| 72 | + test('happy path', () => { |
| 73 | + const loaded = getSpecEnum( |
| 74 | + 'bom-1.4.SNAPSHOT.schema.json', |
| 75 | + 'affectedStatus') |
| 76 | + // dummy test to see if loading worked somehow ... |
| 77 | + assert.deepEqual(loaded, expected_definitions_affectedStatus_enum) |
| 78 | + }) |
| 79 | + }) |
| 80 | +}) |
0 commit comments