diff --git a/lib/endpoints/buildings/shipyard.test.ts b/lib/endpoints/buildings/shipyard.test.ts index bd8499b..8b31e08 100644 --- a/lib/endpoints/buildings/shipyard.test.ts +++ b/lib/endpoints/buildings/shipyard.test.ts @@ -3,26 +3,23 @@ import _ from 'lodash'; import { getLacuna } from '../../__utils__/get-lacuna'; import { int } from '../../core/util'; import { expectMatchesApiSchema } from '../../__utils__/validate-schema'; +import { findBuilding } from '../../__utils__/find-building'; let lacuna: Lacuna; -let buildingId: string; +let buildingId: number; beforeAll(async () => { lacuna = await getLacuna(); - const { result } = await lacuna.empire.getStatus(); - const { empire } = result!; - const { result: buildingsResult } = await lacuna.body.getBuildings({ - body_id: empire.home_planet_id, - }); - const { buildings } = buildingsResult!; - buildingId = _.chain(buildings) - .keys() - .filter((key) => buildings[key].name === 'Shipyard') - .first() - .value(); + const found = await findBuilding(lacuna, 'Shipyard'); + buildingId = found?.buildingId; }); test('view', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Shipyard building on the fixture account'); + return; + } + const { result } = await lacuna.shipyard.view({ building_id: int(buildingId) }); expect(result?.building).toBeDefined(); @@ -31,6 +28,11 @@ test('view', async () => { }); test('viewBuildQueue', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Shipyard building on the fixture account'); + return; + } + const { result } = await lacuna.shipyard.viewBuildQueue({ building_id: int(buildingId) }); expect(result?.cost_to_subsidize).toBeDefined(); @@ -40,6 +42,11 @@ test('viewBuildQueue', async () => { }); test('getBuildable', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Shipyard building on the fixture account'); + return; + } + const { result } = await lacuna.shipyard.getBuildable({ building_id: int(buildingId) }); expect(result?.buildable).toBeDefined(); diff --git a/lib/endpoints/buildings/space-port.test.ts b/lib/endpoints/buildings/space-port.test.ts index ac3a8f9..52c5eca 100644 --- a/lib/endpoints/buildings/space-port.test.ts +++ b/lib/endpoints/buildings/space-port.test.ts @@ -3,30 +3,25 @@ import _ from 'lodash'; import { getLacuna } from '../../__utils__/get-lacuna'; import { int } from '../../core/util'; import { expectMatchesApiSchema } from '../../__utils__/validate-schema'; +import { findBuilding } from '../../__utils__/find-building'; let lacuna: Lacuna; -let buildingId: string; let homePlanetId: number; +let buildingId: number; beforeAll(async () => { lacuna = await getLacuna(); - const { result } = await lacuna.empire.getStatus(); - const { empire } = result!; - homePlanetId = empire.home_planet_id; - - const { result: buildingsResult } = await lacuna.body.getBuildings({ - body_id: homePlanetId, - }); - const { buildings } = buildingsResult!; - - buildingId = _.chain(buildings) - .keys() - .filter((key) => buildings[key].name === 'Space Port') - .first() - .value(); + const found = await findBuilding(lacuna, 'Space Port'); + buildingId = found?.buildingId; + homePlanetId = found?.bodyId; }); test('view', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.view({ building_id: int(buildingId) }); expect(result).toBeDefined(); @@ -36,6 +31,11 @@ test('view', async () => { }); test('viewAllShips', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.viewAllShips({ building_id: int(buildingId) }); expect(result).toBeDefined(); @@ -45,6 +45,11 @@ test('viewAllShips', async () => { }); test('viewTravellingShips', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.viewTravellingShips({ building_id: int(buildingId) }); expect(result).toBeDefined(); @@ -54,6 +59,11 @@ test('viewTravellingShips', async () => { }); test('viewOrbitingShips', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.viewOrbitingShips({ building_id: int(buildingId) }); expect(result).toBeDefined(); @@ -63,6 +73,11 @@ test('viewOrbitingShips', async () => { }); test('viewForeignShips', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.viewForeignShips({ building_id: int(buildingId) }); expect(result).toBeDefined(); @@ -72,6 +87,11 @@ test('viewForeignShips', async () => { }); test('viewBattleLogs', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.viewBattleLogs({ building_id: int(buildingId) }); expect(result).toBeDefined(); @@ -81,6 +101,11 @@ test('viewBattleLogs', async () => { }); test('getFleetFor', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.getFleetFor({ from_body_id: homePlanetId, target: { body_id: homePlanetId }, @@ -92,6 +117,11 @@ test('getFleetFor', async () => { }); test('getShipsFor', async () => { + if (buildingId === undefined) { + console.warn('Skipping: no Space Port building on the fixture account'); + return; + } + const { result } = await lacuna.spacePort.getShipsFor({ from_body_id: homePlanetId, target: { body_id: homePlanetId },