• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DaniSomoza / galactic-commander / 12728621970

11 Jan 2025 11:55PM UTC coverage: 47.963% (-4.1%) from 52.086%
12728621970

Pull #12

github

web-flow
Merge e784abf9e into a8e301a23
Pull Request #12: [fleets] Explore planets

214 of 913 branches covered (23.44%)

Branch coverage included in aggregate %.

154 of 505 new or added lines in 55 files covered. (30.5%)

10 existing lines in 9 files now uncovered.

1564 of 2794 relevant lines covered (55.98%)

3.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

22.5
/packages/game-api-microservice/src/services/galaxyService.ts
1
import universeRepository from 'game-engine/dist/repositories/universeRepository'
2✔
2
import playerRepository from 'game-engine/dist/repositories/playerRepository'
2✔
3
import planetRepository from 'game-engine/dist/repositories/planetRepository'
2✔
4
import { GALAXIES, SECTORS_PER_GALAXIES, SYSTEM_PER_SECTORS } from 'game-engine/dist/types/IPlanet'
2✔
5
import NotFoundError from 'auth-microservice/dist/errors/NotFoundError'
2✔
6
import BadRequestError from 'auth-microservice/dist/errors/BadRequestError'
2✔
7

8
import cleanPlanetFields from '../utils/cleanPlanetFields'
2✔
9

10
type Coordinates = {
11
  galaxy: string
12
  sector: string
13
  system: string
14
}
15

16
async function getGalaxy(username: string, universeName: string, coordinates: Coordinates) {
NEW
17
  const galaxy = Number(coordinates.galaxy)
×
NEW
18
  const sector = Number(coordinates.sector)
×
NEW
19
  const system = Number(coordinates.system)
×
20

NEW
21
  const isValidGalaxy = galaxy > 0 && galaxy <= GALAXIES
×
NEW
22
  const isValidSector = sector > 0 && sector <= SECTORS_PER_GALAXIES
×
NEW
23
  const isValidSystem = system > 0 && system <= SYSTEM_PER_SECTORS
×
24

NEW
25
  if (!isValidGalaxy || !isValidSector || !isValidSystem || !universeName) {
×
NEW
26
    throw new BadRequestError('invalid coordinates', { universeName, galaxy, sector, system })
×
27
  }
28

NEW
29
  const universe = await universeRepository.findUniverseByName(universeName)
×
30

NEW
31
  if (!universe) {
×
NEW
32
    throw new NotFoundError('invalid universe', { universeName })
×
33
  }
34

NEW
35
  const universeId = universe._id.toString()
×
36

NEW
37
  const player = await playerRepository.findPlayerByUsername(username, universeId)
×
38

NEW
39
  if (!player) {
×
NEW
40
    throw new NotFoundError('invalid player', { username, universeName })
×
41
  }
42

NEW
43
  const planets = await planetRepository.findPlanetsBySystem(galaxy, sector, system)
×
44

NEW
45
  return {
×
NEW
46
    planets: planets.map((planet) => cleanPlanetFields(planet, player))
×
47
  }
48
}
49

50
const galaxyService = {
2✔
51
  getGalaxy
52
}
53

54
export default galaxyService
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc