Skip to content

Commit

Permalink
Fix buyShip test
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Aug 4, 2023
1 parent 8f9ab9f commit 83a87d3
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions packages/cli/test/behavior/buy_ship_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,44 @@ import 'package:cli/behavior/buy_ship.dart';
import 'package:cli/behavior/central_command.dart';
import 'package:cli/cache/caches.dart';
import 'package:cli/logger.dart';
import 'package:cli/nav/route.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class _MockAgent extends Mock implements Agent {}

class _MockAgentCache extends Mock implements AgentCache {}

class _MockApi extends Mock implements Api {}

class _MockBehaviorState extends Mock implements BehaviorState {}

class _MockCaches extends Mock implements Caches {}

class _MockCentralCommand extends Mock implements CentralCommand {}

class _MockFleetApi extends Mock implements FleetApi {}

class _MockLogger extends Mock implements Logger {}

class _MockMarketCache extends Mock implements MarketCache {}

class _MockRoutePlanner extends Mock implements RoutePlanner {}

class _MockShip extends Mock implements Ship {}

class _MockShipCache extends Mock implements ShipCache {}

class _MockShipEngine extends Mock implements ShipEngine {}

class _MockShipNav extends Mock implements ShipNav {}

class _MockShipyardPrices extends Mock implements ShipyardPrices {}

class _MockShipyardTransaction extends Mock implements ShipyardTransaction {}

class _MockSystemsApi extends Mock implements SystemsApi {}

class _MockSystemsCache extends Mock implements SystemsCache {}

class _MockTransactionLog extends Mock implements TransactionLog {}
Expand All @@ -34,15 +49,7 @@ class _MockWaypoint extends Mock implements Waypoint {}

class _MockWaypointCache extends Mock implements WaypointCache {}

class _MockBehaviorState extends Mock implements BehaviorState {}

class _MockAgent extends Mock implements Agent {}

class _MockSystemsApi extends Mock implements SystemsApi {}

class _MockFleetApi extends Mock implements FleetApi {}

class _MockShipyardTransaction extends Mock implements ShipyardTransaction {}
class _MockRoutePlan extends Mock implements RoutePlan {}

void main() {
test('advanceBuyShip smoke test', () async {
Expand All @@ -65,13 +72,22 @@ void main() {
when(() => caches.systems).thenReturn(systemsCache);
when(() => caches.shipyardPrices).thenReturn(shipyardPrices);
when(() => caches.ships).thenReturn(shipCache);
final routePlanner = _MockRoutePlanner();
when(() => caches.routePlanner).thenReturn(routePlanner);

final now = DateTime(2021);
DateTime getNow() => now;
const shipSymbol = ShipSymbol('A', 1);
when(() => ship.symbol).thenReturn(shipSymbol.symbol);
when(() => ship.nav).thenReturn(shipNav);
when(() => shipNav.status).thenReturn(ShipNavStatus.DOCKED);
const fuelCapacity = 100;
when(() => ship.fuel)
.thenReturn(ShipFuel(current: 100, capacity: fuelCapacity));
final shipEngine = _MockShipEngine();
when(() => ship.engine).thenReturn(shipEngine);
const shipSpeed = 30;
when(() => shipEngine.speed).thenReturn(shipSpeed);

final symbol = WaypointSymbol.fromString('S-A-W');
when(() => agentCache.headquartersSymbol).thenReturn(symbol);
Expand Down Expand Up @@ -104,14 +120,22 @@ void main() {
when(() => shipCache.frameCounts).thenReturn({});
final state = _MockBehaviorState();

const shipType = ShipType.ORE_HOUND;
const shipType = ShipType.HEAVY_FREIGHTER;
when(() => shipyardPrices.medianPurchasePrice(shipType)).thenReturn(1);
when(
() => shipyardPrices.recentPurchasePrice(
shipyardSymbol: symbol,
shipType: shipType,
),
).thenReturn(1);
when(() => shipyardPrices.pricesFor(shipType)).thenReturn([
ShipyardPrice(
waypointSymbol: symbol,
shipType: shipType,
purchasePrice: 1,
timestamp: DateTime(2021),
)
]);

when(
() => centralCommand.shipTypeToBuy(
Expand Down Expand Up @@ -165,6 +189,16 @@ void main() {

when(() => centralCommand.maxMedianShipPriceMultipler).thenReturn(1.05);

final route = _MockRoutePlan();
when(
() => routePlanner.planRoute(
start: symbol,
end: symbol,
fuelCapacity: fuelCapacity,
shipSpeed: shipSpeed,
),
).thenReturn(route);

final logger = _MockLogger();
expect(
() async {
Expand All @@ -183,7 +217,7 @@ void main() {
},
throwsA(
const JobException(
'Purchased A-1 (SHIP_ORE_HOUND)!',
'Purchased A-1 (SHIP_HEAVY_FREIGHTER)!',
Duration(minutes: 10),
disable: DisableBehavior.allShips,
),
Expand Down

0 comments on commit 83a87d3

Please sign in to comment.