UNPKG

@ozmap/ozn-sdk

Version:

OZN SDK is a powerful tool for developers to build their own applications on top of OZN using TMForum pattern.

132 lines (131 loc) 4.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const geographic_address_1 = require("./geographic-address"); const shared_1 = require("./shared"); describe('geographicAddressInputSchema', () => { const validInput = { name: 'Main Street', postcode: '12345', streetNr: '10b', lat: '40.7128', lng: '-74.0060', }; it('should validate correct input', () => { expect(() => geographic_address_1.geographicAddressInputSchema.parse(validInput)).not.toThrow(); }); for (const key in validInput) { it(`should throw an error if send only ${key}`, () => { // @ts-expect-error - we want to test invalid input const result = geographic_address_1.geographicAddressInputSchema.safeParse({ [key]: validInput[key] }); expect(result.success).toBe(false); }); } it('should reject invalid field types', () => { const invalidInput = { ...validInput, lat: 40.7128 }; // number instead of string const result = geographic_address_1.geographicAddressInputSchema.safeParse(invalidInput); expect(result.success).toBe(false); }); }); describe('geographicLocationSchema', () => { const validLocation = { name: 'Central Park', type: 'Point', geometry: [ { x: -73.968285, y: 40.785091, z: 10, }, ], }; it('should validate correct location', () => { expect(() => geographic_address_1.geographicLocationSchema.parse(validLocation)).not.toThrow(); }); it('should reject invalid geometry types', () => { const invalidLocation = { ...validLocation, geometry: { ...validLocation.geometry, x: 'invalid' }, }; const result = geographic_address_1.geographicLocationSchema.safeParse(invalidLocation); expect(result.success).toBe(false); }); }); describe('externalSystemsSchema', () => { const validExternalSystem = { externalId: 'EXT-123', externalSystem: 'CRM', }; it('should validate correct external system', () => { expect(() => shared_1.externalSystemsSchema.parse(validExternalSystem)).not.toThrow(); }); it('should reject missing externalSystem', () => { const invalidSystem = { externalId: 'EXT-123' }; const result = shared_1.externalSystemsSchema.safeParse(invalidSystem); expect(result.success).toBe(false); }); }); describe('geographicAddressOutputSchema', () => { const validOutput = { id: 'addr-123', city: 'New York', cnl: 'US', country: 'United States', locality: 'Manhattan', district: 'Midtown', name: 'Empire State Building', postcode: '10118', stateOrProvince: 'NY', streetName: '5th Avenue', streetNr: '350', streetType: 'Ave', streetTitle: 'Fifth Avenue', type: 'commercial', geographicLocation: { name: 'Empire State Location', type: 'Point', geometry: [ { x: -73.9857, y: 40.7484, z: null, }, ], }, externalSystems: [ { externalId: 'EXT-123', externalSystem: 'GIS', }, ], }; it('should validate complete output structure', () => { expect(() => geographic_address_1.geographicAddressOutputSchema.parse(validOutput)).not.toThrow(); }); it('should accept optional fields', () => { const withOptionalFields = { ...validOutput, geographicAddressComplement: 'Floor 86', geographicSubAddress: 'Observation Deck', }; expect(() => geographic_address_1.geographicAddressOutputSchema.parse(withOptionalFields)).not.toThrow(); }); it('should reject invalid externalSystems array', () => { const invalidOutput = { ...validOutput, externalSystems: [{ externalId: 'EXT-123' }], // missing externalSystem }; const result = geographic_address_1.geographicAddressOutputSchema.safeParse(invalidOutput); expect(result.success).toBe(false); }); it('should enforce number types for geometry coordinates', () => { const invalidOutput = { ...validOutput, geographicLocation: { ...validOutput.geographicLocation, geometry: { x: '-73.9857', y: 40.7484 }, // string instead of number }, }; const result = geographic_address_1.geographicAddressOutputSchema.safeParse(invalidOutput); expect(result.success).toBe(false); }); });