|
| 1 | +/** |
| 2 | + * Copyright 2025, Optimizely |
| 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 | + |
| 17 | +import { describe, it, expect } from 'vitest'; |
| 18 | +import configValidator from './'; |
| 19 | +import testData from '../../tests/test_data'; |
| 20 | +import { INVALID_DATAFILE_MALFORMED, INVALID_DATAFILE_VERSION, NO_DATAFILE_SPECIFIED } from 'error_message'; |
| 21 | +import { OptimizelyError } from '../../error/optimizly_error'; |
| 22 | + |
| 23 | +describe('validate', () => { |
| 24 | + it('should complain if datafile is not provided', () => { |
| 25 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 26 | + // @ts-ignore |
| 27 | + expect(() => configValidator.validateDatafile()).toThrowError(new OptimizelyError(NO_DATAFILE_SPECIFIED)); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should complain if datafile is malformed', () => { |
| 31 | + expect(() => configValidator.validateDatafile('abc')).toThrowError(new OptimizelyError(INVALID_DATAFILE_MALFORMED)); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should complain if datafile version is not supported', () => { |
| 35 | + expect(() => |
| 36 | + configValidator |
| 37 | + .validateDatafile(JSON.stringify(testData.getUnsupportedVersionConfig())) |
| 38 | + .toThrowError(new OptimizelyError(INVALID_DATAFILE_VERSION)) |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should not complain if datafile is valid', function() { |
| 43 | + expect(() => configValidator.validateDatafile(JSON.stringify(testData.getTestProjectConfig())).not.toThrowError()); |
| 44 | + }); |
| 45 | +}); |
0 commit comments