@telstra/iot-connectivity-manager
Version:
Telstra IoT Connectivity Manager
34 lines (31 loc) • 986 B
text/typescript
import { describe, it, expect } from 'vitest';
import { Validator } from '../../../src/classes/Validator.js';
import { AssertionError } from '@telstra/core';
describe('Validator', () => {
it('should pass validation for valid data', () => {
const schema = {
type: 'object',
properties: {
foo: { type: 'string' },
},
required: ['foo'],
additionalProperties: false,
};
const data = { foo: 'bar' };
const validator = new Validator(data);
expect(() => validator.schemaInline(schema)).not.toThrow();
});
it('should throw AssertionError for invalid data', () => {
const schema = {
type: 'object',
properties: {
foo: { type: 'string' },
},
required: ['foo'],
additionalProperties: false,
};
const data = { foo: 123 }; // invalid: foo should be string
const validator = new Validator(data);
expect(() => validator.schemaInline(schema)).toThrow(AssertionError);
});
});