|
| 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 | +import { describe, it, expect } from 'vitest'; |
| 17 | +import { validate } from '.'; |
| 18 | +import testData from '../../tests/test_data'; |
| 19 | +import { NO_JSON_PROVIDED, INVALID_DATAFILE } from 'error_message'; |
| 20 | + |
| 21 | +describe('validate', () => { |
| 22 | + it('should throw an error if the object is not valid', () => { |
| 23 | + expect(() => validate({})).toThrow(); |
| 24 | + |
| 25 | + try { |
| 26 | + validate({}); |
| 27 | + } catch (err) { |
| 28 | + expect(err.baseMessage).toBe(INVALID_DATAFILE); |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + it('should throw an error if no json object is passed in', () => { |
| 33 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 34 | + // @ts-ignore |
| 35 | + expect(() => validate()).toThrow(); |
| 36 | + |
| 37 | + try { |
| 38 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 39 | + // @ts-ignore |
| 40 | + validate(); |
| 41 | + } catch (err) { |
| 42 | + expect(err.baseMessage).toBe(NO_JSON_PROVIDED); |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + it('should validate specified Optimizely datafile', () => { |
| 47 | + expect(validate(testData.getTestProjectConfig())).toBe(true); |
| 48 | + }); |
| 49 | +}); |
0 commit comments