Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Dec 15, 2023
1 parent ca8857a commit b74737c
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/cli/lib/nav/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Future<DateTime?> beingNewRouteAndLog(
);
if (route == null) {
throw JobException(
'No route to $destinationSymbol!?',
'No route from $start to $destinationSymbol!?',
const Duration(minutes: 10),
);
}
Expand Down
108 changes: 105 additions & 3 deletions packages/cli/test/behavior/trader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class _MockShipNav extends Mock implements ShipNav {}

class _MockSystemsApi extends Mock implements SystemsApi {}

class _MockShipNavRoute extends Mock implements ShipNavRoute {}

void main() {
test('advanceTrader smoke test', () async {
registerFallbackValue(Duration.zero);
Expand Down Expand Up @@ -561,22 +563,55 @@ void main() {
when(() => shipCargo.capacity).thenReturn(10);
when(() => shipCargo.inventory).thenReturn([]);

final shipLocation = WaypointSymbol.fromString('S-A-W');
when(() => ship.symbol).thenReturn(shipSymbol.symbol);
when(() => ship.nav).thenReturn(shipNav);
when(() => shipNav.status).thenReturn(ShipNavStatus.DOCKED);
when(() => shipNav.waypointSymbol).thenReturn('S-A-W');
when(() => shipNav.systemSymbol).thenReturn('S-A');
when(() => shipNav.waypointSymbol).thenReturn(shipLocation.waypoint);
when(() => shipNav.systemSymbol).thenReturn(shipLocation.system);
when(() => ship.fuel).thenReturn(ShipFuel(capacity: 100, current: 100));
final shipEngine = _MockShipEngine();
when(() => shipEngine.speed).thenReturn(10);
when(() => ship.engine).thenReturn(shipEngine);
when(() => shipNav.flightMode).thenReturn(ShipNavFlightMode.CRUISE);

final start = WaypointSymbol.fromString('S-A-B');
final end = WaypointSymbol.fromString('S-A-C');
registerFallbackValue(start);

final startWaypoint = SystemWaypoint(
symbol: start.waypoint,
type: WaypointType.ASTEROID_FIELD,
x: 0,
y: 0,
);
final endWaypoint = SystemWaypoint(
symbol: end.waypoint,
type: WaypointType.ASTEROID_FIELD,
x: 0,
y: 0,
);
final shipLocationWaypoint = SystemWaypoint(
symbol: shipLocation.waypoint,
type: WaypointType.ASTEROID_FIELD,
x: 0,
y: 0,
);

when(() => caches.systems.waypoint(start)).thenReturn(startWaypoint);
when(() => caches.systems.waypoint(end)).thenReturn(endWaypoint);
when(() => caches.systems.waypoint(shipLocation))
.thenReturn(shipLocationWaypoint);

final routePlan = RoutePlan(
actions: [
RouteAction(
startSymbol: shipLocation,
endSymbol: start,
type: RouteActionType.navCruise,
seconds: 10,
fuelUsed: 10,
),
RouteAction(
startSymbol: start,
endSymbol: end,
Expand Down Expand Up @@ -617,8 +652,75 @@ void main() {
maxTotalOutlay: any(named: 'maxTotalOutlay'),
),
).thenReturn(costedDeal);
when(() => centralCommand.otherTraderSystems(shipSymbol)).thenReturn([]);
when(() => caches.marketPrices.prices).thenReturn([]);

final state = BehaviorState(shipSymbol, Behavior.trader);

when(
() => caches.routePlanner.planRoute(
start: shipLocation,
end: start,
fuelCapacity: any(named: 'fuelCapacity'),
shipSpeed: any(named: 'shipSpeed'),
),
).thenReturn(routePlan);

when(() => fleetApi.orbitShip(shipSymbol.symbol)).thenAnswer(
(_) async =>
OrbitShip200Response(data: OrbitShip200ResponseData(nav: shipNav)),
);
final now = DateTime(2021);
when(
() => fleetApi.navigateShip(
shipSymbol.symbol,
navigateShipRequest:
NavigateShipRequest(waypointSymbol: start.waypoint),
),
).thenAnswer(
(_) async => NavigateShip200Response(
data: NavigateShip200ResponseData(
fuel: ShipFuel(
capacity: 100,
current: 100,
consumed: ShipFuelConsumed(amount: 100, timestamp: now),
),
nav: shipNav,
),
),
);
final shipNavRoute = _MockShipNavRoute();
when(() => shipNav.route).thenReturn(shipNavRoute);
when(() => shipNavRoute.arrival).thenReturn(now);
when(() => shipNavRoute.departureTime).thenReturn(now);
when(() => shipNavRoute.departure).thenReturn(
ShipNavRouteWaypoint(
symbol: shipLocation.waypoint,
type: WaypointType.ASTEROID,
systemSymbol: shipLocation.system,
x: 0,
y: 0,
),
);
when(() => shipNavRoute.origin).thenReturn(
ShipNavRouteWaypoint(
symbol: shipLocation.waypoint,
type: WaypointType.ASTEROID,
systemSymbol: shipLocation.system,
x: 0,
y: 0,
),
);
when(() => shipNavRoute.destination).thenReturn(
ShipNavRouteWaypoint(
symbol: start.waypoint,
type: WaypointType.ASTEROID,
systemSymbol: start.system,
x: 0,
y: 0,
),
);

final logger = _MockLogger();
final waitUntil = await runWithLogger(
logger,
Expand All @@ -631,7 +733,7 @@ void main() {
ship,
),
);
expect(waitUntil, isNull);
expect(waitUntil, now);
});

test('handleUnwantedCargoIfNeeded smoke test', () async {
Expand Down
66 changes: 32 additions & 34 deletions packages/cli/test/market_scores_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,44 @@ void main() {
when(() => ship.nav).thenReturn(shipNav);
when(() => shipNav.systemSymbol).thenReturn(shipLocation.system);

final systemsCache = SystemsCache(
[
System(
symbol: shipLocation.system,
sectorSymbol: shipLocation.sector,
type: SystemType.BLUE_STAR,
final system = System(
symbol: shipLocation.system,
sectorSymbol: shipLocation.sector,
type: SystemType.BLUE_STAR,
x: 0,
y: 0,
waypoints: [
SystemWaypoint(
symbol: aSymbol.waypoint,
type: WaypointType.PLANET,
x: 0,
y: 0,
),
SystemWaypoint(
symbol: bSymbol.waypoint,
type: WaypointType.PLANET,
x: 0,
y: 0,
),
SystemWaypoint(
symbol: shipLocation.waypoint,
type: WaypointType.PLANET,
x: 0,
y: 0,
),
SystemWaypoint(
symbol: dSymbol.waypoint,
type: WaypointType.JUMP_GATE,
x: 0,
y: 0,
waypoints: [
SystemWaypoint(
symbol: aSymbol.waypoint,
type: WaypointType.PLANET,
x: 0,
y: 0,
),
SystemWaypoint(
symbol: bSymbol.waypoint,
type: WaypointType.PLANET,
x: 0,
y: 0,
),
SystemWaypoint(
symbol: shipLocation.waypoint,
type: WaypointType.PLANET,
x: 0,
y: 0,
),
SystemWaypoint(
symbol: dSymbol.waypoint,
type: WaypointType.JUMP_GATE,
x: 0,
y: 0,
),
],
),
],
fs: fs,
);

final systems = [system];
final systemsCache = SystemsCache(systems, fs: fs);
final systemConnectivity = _MockSystemConnectivity();
when(() => systemConnectivity.systemsReachableFrom(system.systemSymbol))
.thenReturn(systems.map((s) => s.systemSymbol));

CostedDeal? findNextDeal(Ship ship, WaypointSymbol startSymbol) {
return null;
Expand Down

0 comments on commit b74737c

Please sign in to comment.