System unit tests.

This commit is contained in:
marley 2023-05-17 13:09:57 -07:00
parent edd9ef88a6
commit f0a79d4d7a
2 changed files with 331 additions and 166 deletions

View file

@ -1,134 +1,134 @@
interface journalEntry<eventType = string> {
timestamp: string,
event: eventType,
timestamp: string,
event: eventType,
}
export interface discoveryHonk extends journalEntry<'FSSDiscoveryScan'> {
Progress: number,
BodyCount: number,
NonBodyCount: number,
SystemName: string,
SystemAddress: number,
Progress: number,
BodyCount: number,
NonBodyCount: number,
SystemName: string,
SystemAddress: number,
}
export interface completedSystemFSSScan extends journalEntry<'FSSAllBodiesFound'> {
event: 'FSSAllBodiesFound',
SystemName: string,
SystemAddress: number,
Count: number,
event: 'FSSAllBodiesFound',
SystemName: string,
SystemAddress: number,
Count: number,
}
export interface dssIndicator extends journalEntry<'SAAScanComplete'> {
BodyName: string,
SystemAddress: number,
BodyID: number,
ProbesUsed: number,
EfficiencyTarget: number,
BodyName: string,
SystemAddress: number,
BodyID: number,
ProbesUsed: number,
EfficiencyTarget: number,
}
interface bodyParent {
[index: string]: number,
[index: string]: number,
}
interface bodyAtmosphere {
Name: string,
Percent: number,
Name: string,
Percent: number,
}
interface bodyMaterials {
Name: string,
Percent: number,
Name: string,
Percent: number,
}
interface bodyRings {
Name: string,
RingClass: string,
MassMT: number,
InnerRad: number,
OuterRad: number,
Name: string,
RingClass: string,
MassMT: number,
InnerRad: number,
OuterRad: number,
}
export interface starScan<scanType> extends journalEntry<'Scan'> {
ScanType: scanType,
BodyName: string,
BodyID: number,
Parents: bodyParent[],
StarSystem: string,
SystemAddress: number,
DistanceFromArrivalLS: number,
StarType: string,
Subclass: number,
StellarMass: number,
Radius: number,
AbsoluteMagnitude: number,
Age_MY: number,
SurfaceTemperature: number,
Luminosity: string,
SemiMajorAxis: number,
Eccentricity: number,
OrbitalInclination: number,
Periapsis: number,
OrbitalPeriod: number,
AscendingNode: number,
MeanAnomaly: number,
RotationPeriod: number,
AxialTilt: number,
WasDiscovered: boolean,
WasMapped: boolean,
ScanType: scanType,
BodyName: string,
BodyID: number,
Parents: bodyParent[],
StarSystem: string,
SystemAddress: number,
DistanceFromArrivalLS: number,
StarType: string,
Subclass: number,
StellarMass: number,
Radius: number,
AbsoluteMagnitude: number,
Age_MY: number,
SurfaceTemperature: number,
Luminosity: string,
SemiMajorAxis: number,
Eccentricity: number,
OrbitalInclination: number,
Periapsis: number,
OrbitalPeriod: number,
AscendingNode: number,
MeanAnomaly: number,
RotationPeriod: number,
AxialTilt: number,
WasDiscovered: boolean,
WasMapped: boolean,
}
export interface asteroidScan<scanType> extends journalEntry<'Scan'> {
ScanType: scanType,
BodyName: string,
BodyID: number,
Parents: bodyParent[],
StarSystem: string,
SystemAddress: number,
DistanceFromArrivalLS: number,
WasDiscovered: boolean,
WasMapped: boolean,
ScanType: scanType,
BodyName: string,
BodyID: number,
Parents: bodyParent[],
StarSystem: string,
SystemAddress: number,
DistanceFromArrivalLS: number,
WasDiscovered: boolean,
WasMapped: boolean,
}
export interface planetScan<scanType> extends journalEntry<'Scan'> {
ScanType: scanType,
BodyName: string,
BodyID: number,
Parents: bodyParent[],
StarSystem: string,
SystemAddress: number,
DistanceFromArrivalLS: number,
TidalLock: boolean,
TerraformState: string,
PlanetClass: string,
Atmosphere: string,
AtmosphereType: string,
AtmosphereComposition?: bodyAtmosphere[]
Volcanism: string,
MassEM: number,
Radius: number,
SurfaceGravity: number,
SurfaceTemperature: number,
SurfacePressure: number,
Landable: boolean,
Materials: bodyMaterials[],
Composition: {
Ice: number,
Rock: number,
Metal: number,
},
SemiMajorAxis: number,
Eccentricity: number,
OrbitalInclination: number,
Periapsis: number,
OrbitalPeriod: number,
AscendingNode: number,
MeanAnomaly: number,
RotationPeriod: number,
AxialTilt: number,
Rings?: bodyRings[],
ReserveLevel?: string,
WasDiscovered: boolean,
WasMapped: boolean,
ScanType: scanType,
BodyName: string,
BodyID: number,
Parents: bodyParent[],
StarSystem: string,
SystemAddress: number,
DistanceFromArrivalLS: number,
TidalLock: boolean,
TerraformState: string,
PlanetClass: string,
Atmosphere: string,
AtmosphereType: string,
AtmosphereComposition?: bodyAtmosphere[]
Volcanism: string,
MassEM: number,
Radius: number,
SurfaceGravity: number,
SurfaceTemperature: number,
SurfacePressure: number,
Landable: boolean,
Materials: bodyMaterials[],
Composition: {
Ice: number,
Rock: number,
Metal: number,
},
SemiMajorAxis: number,
Eccentricity: number,
OrbitalInclination: number,
Periapsis: number,
OrbitalPeriod: number,
AscendingNode: number,
MeanAnomaly: number,
RotationPeriod: number,
AxialTilt: number,
Rings?: bodyRings[],
ReserveLevel?: string,
WasDiscovered: boolean,
WasMapped: boolean,
}
export type autoScan = starScan<'AutoScan'> & asteroidScan<'AutoScan'> & planetScan<'AutoScan'>
@ -138,84 +138,84 @@ export type fssScan = detailedScan
export type dssScan = detailedScan
export interface startFsdJump extends journalEntry<'StartJump'> {
JumpType: 'Hyperspace',
StarSystem: string,
SystemAddress: number,
StarClass: string,
JumpType: 'Hyperspace',
StarSystem: string,
SystemAddress: number,
StarClass: string,
}
interface faction {
Name: string,
FactionState: string,
Government: string,
Influence: number,
Allegiance: string,
Happiness: string,
Happiness_Localized: string,
MyReputation: number,
RecoveringStates?: {State: string, Trend: number}[],
ActiveStates?: {State: string}[],
Name: string,
FactionState: string,
Government: string,
Influence: number,
Allegiance: string,
Happiness: string,
Happiness_Localised: string,
MyReputation: number,
RecoveringStates?: { State: string, Trend: number }[],
ActiveStates?: { State: string }[],
}
export interface completeFsdJump extends journalEntry<'FSDJump'> {
Taxi: boolean,
Multicrew: boolean,
StarSystem: string,
SystemAddress: number,
StarPos: [number, number, number],
SystemAllegiance: string,
SystemEconomy: string,
SystemEconomy_Localised: string,
SystemSecondEconomy: string,
SystemSecondEconomy_Localised: string,
SystemGovernment: string,
SystemGovernment_Localised: string,
SystemSecurity: string,
SystemSecurity_Localised: string,
Population: number,
Body: string,
BodyID: number,
BodyType: string,
JumpDist: number,
FuelUsed: number,
FuelLevel: number,
Factions?: faction[],
SystemFaction?: {Name: string},
Taxi: boolean,
Multicrew: boolean,
StarSystem: string,
SystemAddress: number,
StarPos: [number, number, number],
SystemAllegiance: string,
SystemEconomy: string,
SystemEconomy_Localised: string,
SystemSecondEconomy: string,
SystemSecondEconomy_Localised: string,
SystemGovernment: string,
SystemGovernment_Localised: string,
SystemSecurity: string,
SystemSecurity_Localised: string,
Population: number,
Body: string,
BodyID: number,
BodyType: string,
JumpDist: number,
FuelUsed: number,
FuelLevel: number,
Factions?: faction[],
SystemFaction?: { Name: string },
}
export interface location extends journalEntry<'Location'> {
Docked: boolean,
Taxi: boolean,
Multicrew: boolean,
StarSystem: string,
SystemAddress: number,
StarPos: [number, number, number],
SystemAllegiance: string,
SystemEconomy: string,
SystemEconomy_Localised: string,
SystemSecondEconomy: string,
SystemSecondEconomy_Localised: string,
SystemGovernment: string,
SystemGovernment_Localised: string,
SystemSecurity: string,
SystemSecurity_Localised: string,
Population: number,
Body: string,
BodyID: string,
BodyType: string,
Factions: faction[],
SystemFaction: {Name: string},
Docked: boolean,
Taxi: boolean,
Multicrew: boolean,
StarSystem: string,
SystemAddress: number,
StarPos: [number, number, number],
SystemAllegiance: string,
SystemEconomy: string,
SystemEconomy_Localised: string,
SystemSecondEconomy: string,
SystemSecondEconomy_Localised: string,
SystemGovernment: string,
SystemGovernment_Localised: string,
SystemSecurity: string,
SystemSecurity_Localised: string,
Population: number,
Body: string,
BodyID: number,
BodyType: string,
Factions: faction[],
SystemFaction: { Name: string },
}
export interface navRouteSystem {
StarSystem: string,
SystemAddress: number,
StarPos: [number, number, number],
StarClass: string,
StarSystem: string,
SystemAddress: number,
StarPos: [number, number, number],
StarClass: string,
}
export interface navRoute {
timestamp: string,
event: 'NavRoute',
Route: navRouteSystem[],
timestamp: string,
event: 'NavRoute',
Route: navRouteSystem[],
}

165
test/System.test.ts Normal file
View file

@ -0,0 +1,165 @@
// noinspection DuplicatedCode
import {expect, jest, it, beforeEach} from '@jest/globals';
import {completeFsdJump, location, navRouteSystem} from '../src/@types/journalLines';
import {Body} from '../src/models/Body';
import {EDSM} from '../src/models/EDSM';
import {Journal} from '../src/models/Journal';
import {System} from '../src/models/System';
const appRoot = require('app-root-path');
describe('EDSM', () => {
beforeEach(() => {
const getSystemValueMock =
jest.spyOn(EDSM, 'getSystemValue')
.mockResolvedValue(undefined);
});
describe('constructor()', () => {
it('should create new system from NavRoute', () => {
const data: navRouteSystem = {
'StarSystem': 'LHS 3447',
'SystemAddress': 5306465653474,
'StarPos': [-43.18750, -5.28125, 56.15625],
'StarClass': 'M',
};
const system = new System(data);
expect(system.name).toBe(data.StarSystem);
expect(system.SystemAddress).toBe(data.SystemAddress);
expect(system.StarClass).toBe(data.StarClass);
expect(Array.isArray(system.bodies)).toBe(true);
});
it('should create new system from completeFsdJump', () => {
const data: completeFsdJump = {
'timestamp': '2023-05-08T19:13:52Z',
'event': 'FSDJump',
'Taxi': false,
'Multicrew': false,
'StarSystem': 'LHS 119',
'SystemAddress': 18262603605409,
'StarPos': [-30.15625, -21.87500, -17.25000],
'SystemAllegiance': '',
'SystemEconomy': '$economy_None;',
'SystemEconomy_Localised': 'None',
'SystemSecondEconomy': '$economy_None;',
'SystemSecondEconomy_Localised': 'None',
'SystemGovernment': '$government_None;',
'SystemGovernment_Localised': 'None',
'SystemSecurity': '$GAlAXY_MAP_INFO_state_anarchy;',
'SystemSecurity_Localised': 'Anarchy',
'Population': 0,
'Body': 'LHS 119 A',
'BodyID': 1,
'BodyType': 'Star',
'JumpDist': 8.575,
'FuelUsed': 0.982384,
'FuelLevel': 127.017616,
};
const system = new System(data);
expect(system.name).toBe(data.StarSystem);
expect(system.SystemAddress).toBe(data.SystemAddress);
expect(system.StarClass).toBeUndefined();
expect(Array.isArray(system.bodies)).toBe(true);
});
it('should create new system from location', () => {
const data: location = {
'timestamp': '2023-05-09T20:30:31Z',
'event': 'Location',
'Docked': false,
'Taxi': false,
'Multicrew': false,
'StarSystem': 'LP 292-66',
'SystemAddress': 2869172315553,
'StarPos': [-47.15625, -35.53125, -21.18750],
'SystemAllegiance': 'Federation',
'SystemEconomy': '$economy_Refinery;',
'SystemEconomy_Localised': 'Refinery',
'SystemSecondEconomy': '$economy_HighTech;',
'SystemSecondEconomy_Localised': 'High Tech',
'SystemGovernment': '$government_Corporate;',
'SystemGovernment_Localised': 'Corporate',
'SystemSecurity': '$SYSTEM_SECURITY_medium;',
'SystemSecurity_Localised': 'Medium Security',
'Population': 320135,
'Body': 'LP 292-66 A',
'BodyID': 4,
'BodyType': 'Star',
'Factions': [
{
'Name': 'Workers of LP 292-66 for Equality',
'FactionState': 'None',
'Government': 'Democracy',
'Influence': 0.056943,
'Allegiance': 'Federation',
'Happiness': '$Faction_HappinessBand2;',
'Happiness_Localised': 'Happy',
'MyReputation': 0.000000,
},
],
'SystemFaction': {'Name': 'LFT 42 Silver Energy Co'},
};
const system = new System(data);
expect(system.name).toBe(data.StarSystem);
expect(system.SystemAddress).toBe(data.SystemAddress);
expect(system.StarClass).toBeUndefined();
expect(Array.isArray(system.bodies)).toBe(true);
});
});
describe('System Appraisal', () => {
it('should get system value', (done) => {
const edsmData = {
'id': 13153,
'id64': 5306465653474,
'name': 'LHS 3447',
'url': 'https:\/\/www.edsm.net\/en\/system\/bodies\/id\/13153\/name\/LHS+3447',
'estimatedValue': 353968,
'estimatedValueMapped': 1164029,
'valuableBodies': [
{
'bodyId': 3195879,
'bodyName': 'LHS 3447 A 5',
'distance': 92282,
'valueMax': 879114,
},
],
};
const getSystemValueMock =
jest.spyOn(EDSM, 'getSystemValue')
.mockResolvedValue(edsmData);
const data: navRouteSystem = {
'StarSystem': 'LHS 3447',
'SystemAddress': 5306465653474,
'StarPos': [-43.18750, -5.28125, 56.15625],
'StarClass': 'M',
};
const system = new System(data);
EDSM.connect().on('SYSTEM_APPRAISED', () => {
expect(system.estimatedValue).toBe(edsmData.estimatedValue);
done();
});
});
});
describe('sortBodies()', () => {
it('should set bodies to Body[] with the same amount of elements', (done) => {
const journal = new Journal(`${appRoot}/test_journals/hasScannedBodies.log`);
journal.on('BUILD_BODY_LIST', () => {
const before = journal.location.bodies;
journal.location.sortBodies();
expect(journal.location.bodies.length).toBe(before.length);
expect(Array.isArray(journal.location.bodies)).toBe(true);
expect(journal.location.bodies[0]).toBeInstanceOf(Body);
done();
});
});
});
});