System unit tests.
This commit is contained in:
parent
edd9ef88a6
commit
f0a79d4d7a
2 changed files with 331 additions and 166 deletions
330
src/@types/journalLines.d.ts
vendored
330
src/@types/journalLines.d.ts
vendored
|
@ -1,134 +1,134 @@
|
||||||
interface journalEntry<eventType = string> {
|
interface journalEntry<eventType = string> {
|
||||||
timestamp: string,
|
timestamp: string,
|
||||||
event: eventType,
|
event: eventType,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface discoveryHonk extends journalEntry<'FSSDiscoveryScan'> {
|
export interface discoveryHonk extends journalEntry<'FSSDiscoveryScan'> {
|
||||||
Progress: number,
|
Progress: number,
|
||||||
BodyCount: number,
|
BodyCount: number,
|
||||||
NonBodyCount: number,
|
NonBodyCount: number,
|
||||||
SystemName: string,
|
SystemName: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface completedSystemFSSScan extends journalEntry<'FSSAllBodiesFound'> {
|
export interface completedSystemFSSScan extends journalEntry<'FSSAllBodiesFound'> {
|
||||||
event: 'FSSAllBodiesFound',
|
event: 'FSSAllBodiesFound',
|
||||||
SystemName: string,
|
SystemName: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
Count: number,
|
Count: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface dssIndicator extends journalEntry<'SAAScanComplete'> {
|
export interface dssIndicator extends journalEntry<'SAAScanComplete'> {
|
||||||
BodyName: string,
|
BodyName: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
BodyID: number,
|
BodyID: number,
|
||||||
ProbesUsed: number,
|
ProbesUsed: number,
|
||||||
EfficiencyTarget: number,
|
EfficiencyTarget: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface bodyParent {
|
interface bodyParent {
|
||||||
[index: string]: number,
|
[index: string]: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface bodyAtmosphere {
|
interface bodyAtmosphere {
|
||||||
Name: string,
|
Name: string,
|
||||||
Percent: number,
|
Percent: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface bodyMaterials {
|
interface bodyMaterials {
|
||||||
Name: string,
|
Name: string,
|
||||||
Percent: number,
|
Percent: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface bodyRings {
|
interface bodyRings {
|
||||||
Name: string,
|
Name: string,
|
||||||
RingClass: string,
|
RingClass: string,
|
||||||
MassMT: number,
|
MassMT: number,
|
||||||
InnerRad: number,
|
InnerRad: number,
|
||||||
OuterRad: number,
|
OuterRad: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface starScan<scanType> extends journalEntry<'Scan'> {
|
export interface starScan<scanType> extends journalEntry<'Scan'> {
|
||||||
ScanType: scanType,
|
ScanType: scanType,
|
||||||
BodyName: string,
|
BodyName: string,
|
||||||
BodyID: number,
|
BodyID: number,
|
||||||
Parents: bodyParent[],
|
Parents: bodyParent[],
|
||||||
StarSystem: string,
|
StarSystem: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
DistanceFromArrivalLS: number,
|
DistanceFromArrivalLS: number,
|
||||||
StarType: string,
|
StarType: string,
|
||||||
Subclass: number,
|
Subclass: number,
|
||||||
StellarMass: number,
|
StellarMass: number,
|
||||||
Radius: number,
|
Radius: number,
|
||||||
AbsoluteMagnitude: number,
|
AbsoluteMagnitude: number,
|
||||||
Age_MY: number,
|
Age_MY: number,
|
||||||
SurfaceTemperature: number,
|
SurfaceTemperature: number,
|
||||||
Luminosity: string,
|
Luminosity: string,
|
||||||
SemiMajorAxis: number,
|
SemiMajorAxis: number,
|
||||||
Eccentricity: number,
|
Eccentricity: number,
|
||||||
OrbitalInclination: number,
|
OrbitalInclination: number,
|
||||||
Periapsis: number,
|
Periapsis: number,
|
||||||
OrbitalPeriod: number,
|
OrbitalPeriod: number,
|
||||||
AscendingNode: number,
|
AscendingNode: number,
|
||||||
MeanAnomaly: number,
|
MeanAnomaly: number,
|
||||||
RotationPeriod: number,
|
RotationPeriod: number,
|
||||||
AxialTilt: number,
|
AxialTilt: number,
|
||||||
WasDiscovered: boolean,
|
WasDiscovered: boolean,
|
||||||
WasMapped: boolean,
|
WasMapped: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface asteroidScan<scanType> extends journalEntry<'Scan'> {
|
export interface asteroidScan<scanType> extends journalEntry<'Scan'> {
|
||||||
ScanType: scanType,
|
ScanType: scanType,
|
||||||
BodyName: string,
|
BodyName: string,
|
||||||
BodyID: number,
|
BodyID: number,
|
||||||
Parents: bodyParent[],
|
Parents: bodyParent[],
|
||||||
StarSystem: string,
|
StarSystem: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
DistanceFromArrivalLS: number,
|
DistanceFromArrivalLS: number,
|
||||||
WasDiscovered: boolean,
|
WasDiscovered: boolean,
|
||||||
WasMapped: boolean,
|
WasMapped: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface planetScan<scanType> extends journalEntry<'Scan'> {
|
export interface planetScan<scanType> extends journalEntry<'Scan'> {
|
||||||
ScanType: scanType,
|
ScanType: scanType,
|
||||||
BodyName: string,
|
BodyName: string,
|
||||||
BodyID: number,
|
BodyID: number,
|
||||||
Parents: bodyParent[],
|
Parents: bodyParent[],
|
||||||
StarSystem: string,
|
StarSystem: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
DistanceFromArrivalLS: number,
|
DistanceFromArrivalLS: number,
|
||||||
TidalLock: boolean,
|
TidalLock: boolean,
|
||||||
TerraformState: string,
|
TerraformState: string,
|
||||||
PlanetClass: string,
|
PlanetClass: string,
|
||||||
Atmosphere: string,
|
Atmosphere: string,
|
||||||
AtmosphereType: string,
|
AtmosphereType: string,
|
||||||
AtmosphereComposition?: bodyAtmosphere[]
|
AtmosphereComposition?: bodyAtmosphere[]
|
||||||
Volcanism: string,
|
Volcanism: string,
|
||||||
MassEM: number,
|
MassEM: number,
|
||||||
Radius: number,
|
Radius: number,
|
||||||
SurfaceGravity: number,
|
SurfaceGravity: number,
|
||||||
SurfaceTemperature: number,
|
SurfaceTemperature: number,
|
||||||
SurfacePressure: number,
|
SurfacePressure: number,
|
||||||
Landable: boolean,
|
Landable: boolean,
|
||||||
Materials: bodyMaterials[],
|
Materials: bodyMaterials[],
|
||||||
Composition: {
|
Composition: {
|
||||||
Ice: number,
|
Ice: number,
|
||||||
Rock: number,
|
Rock: number,
|
||||||
Metal: number,
|
Metal: number,
|
||||||
},
|
},
|
||||||
SemiMajorAxis: number,
|
SemiMajorAxis: number,
|
||||||
Eccentricity: number,
|
Eccentricity: number,
|
||||||
OrbitalInclination: number,
|
OrbitalInclination: number,
|
||||||
Periapsis: number,
|
Periapsis: number,
|
||||||
OrbitalPeriod: number,
|
OrbitalPeriod: number,
|
||||||
AscendingNode: number,
|
AscendingNode: number,
|
||||||
MeanAnomaly: number,
|
MeanAnomaly: number,
|
||||||
RotationPeriod: number,
|
RotationPeriod: number,
|
||||||
AxialTilt: number,
|
AxialTilt: number,
|
||||||
Rings?: bodyRings[],
|
Rings?: bodyRings[],
|
||||||
ReserveLevel?: string,
|
ReserveLevel?: string,
|
||||||
WasDiscovered: boolean,
|
WasDiscovered: boolean,
|
||||||
WasMapped: boolean,
|
WasMapped: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type autoScan = starScan<'AutoScan'> & asteroidScan<'AutoScan'> & planetScan<'AutoScan'>
|
export type autoScan = starScan<'AutoScan'> & asteroidScan<'AutoScan'> & planetScan<'AutoScan'>
|
||||||
|
@ -138,84 +138,84 @@ export type fssScan = detailedScan
|
||||||
export type dssScan = detailedScan
|
export type dssScan = detailedScan
|
||||||
|
|
||||||
export interface startFsdJump extends journalEntry<'StartJump'> {
|
export interface startFsdJump extends journalEntry<'StartJump'> {
|
||||||
JumpType: 'Hyperspace',
|
JumpType: 'Hyperspace',
|
||||||
StarSystem: string,
|
StarSystem: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
StarClass: string,
|
StarClass: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface faction {
|
interface faction {
|
||||||
Name: string,
|
Name: string,
|
||||||
FactionState: string,
|
FactionState: string,
|
||||||
Government: string,
|
Government: string,
|
||||||
Influence: number,
|
Influence: number,
|
||||||
Allegiance: string,
|
Allegiance: string,
|
||||||
Happiness: string,
|
Happiness: string,
|
||||||
Happiness_Localized: string,
|
Happiness_Localised: string,
|
||||||
MyReputation: number,
|
MyReputation: number,
|
||||||
RecoveringStates?: {State: string, Trend: number}[],
|
RecoveringStates?: { State: string, Trend: number }[],
|
||||||
ActiveStates?: {State: string}[],
|
ActiveStates?: { State: string }[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface completeFsdJump extends journalEntry<'FSDJump'> {
|
export interface completeFsdJump extends journalEntry<'FSDJump'> {
|
||||||
Taxi: boolean,
|
Taxi: boolean,
|
||||||
Multicrew: boolean,
|
Multicrew: boolean,
|
||||||
StarSystem: string,
|
StarSystem: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
StarPos: [number, number, number],
|
StarPos: [number, number, number],
|
||||||
SystemAllegiance: string,
|
SystemAllegiance: string,
|
||||||
SystemEconomy: string,
|
SystemEconomy: string,
|
||||||
SystemEconomy_Localised: string,
|
SystemEconomy_Localised: string,
|
||||||
SystemSecondEconomy: string,
|
SystemSecondEconomy: string,
|
||||||
SystemSecondEconomy_Localised: string,
|
SystemSecondEconomy_Localised: string,
|
||||||
SystemGovernment: string,
|
SystemGovernment: string,
|
||||||
SystemGovernment_Localised: string,
|
SystemGovernment_Localised: string,
|
||||||
SystemSecurity: string,
|
SystemSecurity: string,
|
||||||
SystemSecurity_Localised: string,
|
SystemSecurity_Localised: string,
|
||||||
Population: number,
|
Population: number,
|
||||||
Body: string,
|
Body: string,
|
||||||
BodyID: number,
|
BodyID: number,
|
||||||
BodyType: string,
|
BodyType: string,
|
||||||
JumpDist: number,
|
JumpDist: number,
|
||||||
FuelUsed: number,
|
FuelUsed: number,
|
||||||
FuelLevel: number,
|
FuelLevel: number,
|
||||||
Factions?: faction[],
|
Factions?: faction[],
|
||||||
SystemFaction?: {Name: string},
|
SystemFaction?: { Name: string },
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface location extends journalEntry<'Location'> {
|
export interface location extends journalEntry<'Location'> {
|
||||||
Docked: boolean,
|
Docked: boolean,
|
||||||
Taxi: boolean,
|
Taxi: boolean,
|
||||||
Multicrew: boolean,
|
Multicrew: boolean,
|
||||||
StarSystem: string,
|
StarSystem: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
StarPos: [number, number, number],
|
StarPos: [number, number, number],
|
||||||
SystemAllegiance: string,
|
SystemAllegiance: string,
|
||||||
SystemEconomy: string,
|
SystemEconomy: string,
|
||||||
SystemEconomy_Localised: string,
|
SystemEconomy_Localised: string,
|
||||||
SystemSecondEconomy: string,
|
SystemSecondEconomy: string,
|
||||||
SystemSecondEconomy_Localised: string,
|
SystemSecondEconomy_Localised: string,
|
||||||
SystemGovernment: string,
|
SystemGovernment: string,
|
||||||
SystemGovernment_Localised: string,
|
SystemGovernment_Localised: string,
|
||||||
SystemSecurity: string,
|
SystemSecurity: string,
|
||||||
SystemSecurity_Localised: string,
|
SystemSecurity_Localised: string,
|
||||||
Population: number,
|
Population: number,
|
||||||
Body: string,
|
Body: string,
|
||||||
BodyID: string,
|
BodyID: number,
|
||||||
BodyType: string,
|
BodyType: string,
|
||||||
Factions: faction[],
|
Factions: faction[],
|
||||||
SystemFaction: {Name: string},
|
SystemFaction: { Name: string },
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface navRouteSystem {
|
export interface navRouteSystem {
|
||||||
StarSystem: string,
|
StarSystem: string,
|
||||||
SystemAddress: number,
|
SystemAddress: number,
|
||||||
StarPos: [number, number, number],
|
StarPos: [number, number, number],
|
||||||
StarClass: string,
|
StarClass: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface navRoute {
|
export interface navRoute {
|
||||||
timestamp: string,
|
timestamp: string,
|
||||||
event: 'NavRoute',
|
event: 'NavRoute',
|
||||||
Route: navRouteSystem[],
|
Route: navRouteSystem[],
|
||||||
}
|
}
|
165
test/System.test.ts
Normal file
165
test/System.test.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue