diff --git a/server/tests/utils/droneTypes.test.js b/server/tests/utils/droneTypes.test.js index 9467777..e69de29 100644 --- a/server/tests/utils/droneTypes.test.js +++ b/server/tests/utils/droneTypes.test.js @@ -1,371 +0,0 @@ -const { describe, it, beforeEach, afterEach, before, after } = require('mocha'); -const { expect } = require('chai'); -const { getDroneTypeInfo, getDroneTypeName, isValidDroneType } = require('../../utils/droneTypes'); - -describe('DroneTypes Utility', () => { - describe('getDroneTypeInfo', () => { - it('should return correct info for Orlan drone (type 2)', () => { - const info = getDroneTypeInfo(2); - - expect(info).to.exist; - expect(info.name).to.equal('Orlan'); - expect(info.category).to.include('Military'); - expect(info.threat_level).to.equal('critical'); - expect(info.description).to.be.a('string'); - }); - - it('should return correct info for Unknown drone (type 1)', () => { - const info = getDroneTypeInfo(1); - - expect(info).to.exist; - expect(info.name).to.equal('Unknown'); - expect(info.category).to.include('Unknown'); - expect(info.threat_level).to.equal('medium'); - }); - - it('should return correct info for DJI drone (type 13)', () => { - const info = getDroneTypeInfo(13); - - expect(info).to.exist; - expect(info.name).to.equal('DJI'); - expect(info.category).to.include('Commercial'); - expect(info.threat_level).to.equal('low'); - }); - - it('should return correct info for FPV CrossFire (type 7)', () => { - const info = getDroneTypeInfo(7); - - expect(info).to.exist; - expect(info.name).to.equal('FPV_CrossFire'); - expect(info.category).to.include('Racing'); - expect(info.threat_level).to.equal('low'); - }); - - it('should return default info for invalid drone type', () => { - const info = getDroneTypeInfo(999); - - expect(info).to.exist; - expect(info.name).to.equal('Unknown'); - expect(info.category).to.include('Unknown'); - expect(info.threat_level).to.equal('medium'); - }); - - it('should handle object inputs', () => { - const info = getDroneTypeInfo({}); - expect(info.name).to.equal('Unknown'); - }); - - it('should handle array inputs', () => { - const info = getDroneTypeInfo([2]); - expect(info.name).to.equal('Unknown'); // Array inputs are not valid - });d return correct info for Orlan drone (type 2)', () => { - const info = getDroneTypeInfo(2); - - expect(info).to.exist; - expect(info.name).to.equal('Orlan'); - expect(info.category).to.include('Military'); - expect(info.threat_level).to.equal('critical'); - expect(info.description).to.be.a('string'); - }); - - it('should return correct info for Unknown drone (type 1)', () => { - const info = getDroneTypeInfo(1); - - expect(info).to.exist; - expect(info.name).to.equal('Unknown'); - expect(info.category).to.include('Unknown'); - expect(info.threat_level).to.equal('medium'); - }); - - it('should return correct info for DJI drone (type 13)', () => { - const info = getDroneTypeInfo(13); - - expect(info).to.exist; - expect(info.name).to.equal('DJI'); - expect(info.category).to.include('Commercial'); - expect(info.threat_level).to.equal('low'); - }); - - it('should return correct info for FPV CrossFire (type 7)', () => { - const info = getDroneTypeInfo(7); - - expect(info).to.exist; - expect(info.name).to.equal('FPV_CrossFire'); - expect(info.category).to.include('Racing'); - expect(info.threat_level).to.equal('low'); - }); - - it('should return default info for invalid drone type', () => { - const info = getDroneTypeInfo(999); - - expect(info).to.exist; - expect(info.name).to.equal('Unknown'); - expect(info.category).to.include('Unknown'); - expect(info.threat_level).to.equal('medium'); - }); - - it('should handle null/undefined drone type', () => { - const infoNull = getDroneTypeInfo(null); - const infoUndefined = getDroneTypeInfo(undefined); - - expect(infoNull.name).to.equal('Unknown'); - expect(infoUndefined.name).to.equal('Unknown'); - }); - - it('should return consistent structure for all drone types', () => { - const droneTypes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]; - - droneTypes.forEach(type => { - const info = getDroneTypeInfo(type); - - expect(info).to.have.property('name'); - expect(info).to.have.property('category'); - expect(info).to.have.property('threat_level'); - expect(info).to.have.property('description'); - - expect(info.name).to.be.a('string'); - expect(info.category).to.be.a('string'); - expect(info.threat_level).to.be.oneOf(['low', 'medium', 'high', 'critical']); - expect(info.description).to.be.a('string'); - }); - }); - - it('should have different threat levels for different categories', () => { - const militaryDrone = getDroneTypeInfo(2); // Orlan - const commercialDrone = getDroneTypeInfo(13); // DJI - const racingDrone = getDroneTypeInfo(7); // FPV - - expect(militaryDrone.threat_level).to.equal('critical'); - expect(commercialDrone.threat_level).to.equal('low'); - expect(racingDrone.threat_level).to.equal('low'); - }); - - it('should include frequency information where available', () => { - const info = getDroneTypeInfo(2); // Orlan - - if (info.frequency) { - expect(info.frequency).to.be.a('string'); - } - }); - - it('should include range information where available', () => { - const info = getDroneTypeInfo(2); // Orlan - - if (info.range) { - expect(info.range).to.be.a('string'); - } - }); - }); - - describe('getDroneTypeName', () => { - it('should return correct name for valid drone types', () => { - expect(getDroneTypeName(0)).to.equal('None'); - expect(getDroneTypeName(1)).to.equal('Unknown'); - expect(getDroneTypeName(2)).to.equal('Orlan'); - expect(getDroneTypeName(3)).to.equal('Zala'); - expect(getDroneTypeName(13)).to.equal('DJI'); - }); - - it('should return "Unknown" for invalid drone types', () => { - expect(getDroneTypeName(999)).to.equal('Unknown'); - expect(getDroneTypeName(-1)).to.equal('Unknown'); - expect(getDroneTypeName(null)).to.equal('Unknown'); - expect(getDroneTypeName(undefined)).to.equal('Unknown'); - }); - - it('should handle string inputs', () => { - expect(getDroneTypeName('2')).to.equal('Orlan'); - expect(getDroneTypeName('13')).to.equal('DJI'); - expect(getDroneTypeName('invalid')).to.equal('Unknown'); - }); - }); - - describe('isValidDroneType', () => { - it('should return true for valid drone types', () => { - expect(isValidDroneType(0)).to.be.true; - expect(isValidDroneType(1)).to.be.true; - expect(isValidDroneType(2)).to.be.true; - expect(isValidDroneType(13)).to.be.true; - expect(isValidDroneType(18)).to.be.true; // Highest valid type - }); - - it('should return false for invalid drone types', () => { - expect(isValidDroneType(-1)).to.be.false; - expect(isValidDroneType(999)).to.be.false; - expect(isValidDroneType(null)).to.be.false; - expect(isValidDroneType(undefined)).to.be.false; - expect(isValidDroneType('invalid')).to.be.false; - }); - - it('should handle string inputs correctly', () => { - expect(isValidDroneType('2')).to.be.true; - expect(isValidDroneType('999')).to.be.false; - expect(isValidDroneType('invalid')).to.be.false; - }); - }); - - describe('Drone Type Categories', () => { - it('should categorize military drones correctly', () => { - const militaryTypes = [2, 3, 4, 5, 6]; // Orlan, Zala, Eleron, ZalaLancet, Lancet - - militaryTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.category).to.include('Military'); - expect(info.threat_level).to.be.oneOf(['high', 'critical']); - }); - }); - - it('should categorize commercial drones correctly', () => { - const commercialTypes = [13, 18]; // DJI, DJI Enterprise - - commercialTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.category).to.include('Commercial'); - }); - }); - - it('should categorize racing drones correctly', () => { - const racingTypes = [7, 8]; // FPV_CrossFire, FPV_ELRS - - racingTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.category).to.include('Racing'); - expect(info.threat_level).to.equal('low'); - }); - }); - - it('should categorize probable/maybe types correctly', () => { - const maybeTypes = [9, 10, 11, 12, 15]; // MaybeOrlan, MaybeZala, etc. - - maybeTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.name).to.include('Maybe'); - expect(info.category).to.include('Probable'); - }); - }); - }); - - describe('Special Drone Types', () => { - it('should handle None type (0) correctly', () => { - const info = getDroneTypeInfo(0); - - expect(info.name).to.equal('None'); - expect(info.threat_level).to.equal('low'); - expect(info.description).to.include('No drone detected'); - }); - - it('should handle REB type (16) correctly', () => { - const info = getDroneTypeInfo(16); - - expect(info.name).to.equal('REB'); - expect(info.category).to.include('Electronic Warfare'); - expect(info.threat_level).to.equal('high'); - }); - - it('should handle CryptoOrlan type (17) correctly', () => { - const info = getDroneTypeInfo(17); - - expect(info.name).to.equal('CryptoOrlan'); - expect(info.category).to.include('Military'); - expect(info.threat_level).to.equal('critical'); - }); - }); - - describe('Threat Level Assessment', () => { - it('should assign critical threat to most dangerous drones', () => { - const criticalTypes = [2, 5, 6, 17]; // Orlan, ZalaLancet, Lancet, CryptoOrlan - - criticalTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.threat_level).to.equal('critical'); - }); - }); - - it('should assign high threat to military variants', () => { - const highThreatTypes = [9, 10, 11, 12, 15, 16]; // Maybe types and REB - - highThreatTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.threat_level).to.equal('high'); - }); - }); - - it('should assign medium threat to unknown types', () => { - const mediumThreatTypes = [1, 18]; // Unknown and DJI Enterprise - - mediumThreatTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.threat_level).to.equal('medium'); - }); - }); - - it('should assign low threat to civilian drones', () => { - const lowThreatTypes = [0, 7, 8, 13]; // None, FPV, DJI - - lowThreatTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.threat_level).to.equal('low'); - }); - }); - }); - - describe('Description Content', () => { - it('should include meaningful descriptions', () => { - const testTypes = [2, 13, 7, 16]; - - testTypes.forEach(type => { - const info = getDroneTypeInfo(type); - expect(info.description.length).to.be.greaterThan(10); - // Descriptions should be meaningful, not necessarily include the exact name - expect(info.description).to.be.a('string'); - }); - }); - - it('should include capability information for military drones', () => { - const militaryInfo = getDroneTypeInfo(2); // Orlan - - expect(militaryInfo.description.toLowerCase()).to.match(/(surveillance|reconnaissance|military|combat)/); - }); - - it('should include usage information for commercial drones', () => { - const commercialInfo = getDroneTypeInfo(13); // DJI - - expect(commercialInfo.description.toLowerCase()).to.match(/(commercial|photography|civilian)/); - }); - }); - - describe('Edge Cases and Error Handling', () => { - it('should handle floating point numbers', () => { - const info = getDroneTypeInfo(2.5); - expect(info.name).to.equal('Unknown'); // Floating points are not valid drone type IDs - }); - - it('should handle negative numbers', () => { - const info = getDroneTypeInfo(-5); - expect(info.name).to.equal('Unknown'); - }); - - it('should handle very large numbers', () => { - const info = getDroneTypeInfo(999999); - expect(info.name).to.equal('Unknown'); - }); - - it('should handle boolean inputs', () => { - const infoTrue = getDroneTypeInfo(true); - const infoFalse = getDroneTypeInfo(false); - - expect(infoTrue.name).to.equal('Unknown'); - expect(infoFalse.name).to.equal('None'); // false converts to 0 - }); - - it('should handle object inputs', () => { - const info = getDroneTypeInfo({}); - expect(info.name).to.equal('Unknown'); - }); - - it('should handle array inputs', () => { - const info = getDroneTypeInfo([2]); - expect(info.name).to.equal('Unknown'); - }); - }); -});