diff --git a/constants/Games.ts b/constants/Games.ts index 11d1850dd..2ab5aaf02 100644 --- a/constants/Games.ts +++ b/constants/Games.ts @@ -1,6 +1,6 @@ import { GameState } from '@root/helpers/gameStateHelpers'; import { isCompletePathology, isCompleteSokopath } from '@root/helpers/validators/isComplete'; -import validatePathologySolution, { validatePathologyLevelValid as validatePathologyLevel } from '@root/helpers/validators/validatePathology'; +import validatePathologySolution, { validatePathologyLevel } from '@root/helpers/validators/validatePathology'; import validateSokopathSolution, { validateSokopathLevel } from '@root/helpers/validators/validateSokopath'; import Level from '@root/models/db/level'; import AchievementCategory from './achievements/achievementCategory'; diff --git a/helpers/validators/validatePathology.ts b/helpers/validators/validatePathology.ts index 448f25f0d..acb5ca7d8 100644 --- a/helpers/validators/validatePathology.ts +++ b/helpers/validators/validatePathology.ts @@ -75,7 +75,7 @@ export default function validatePathologySolution(directions: Direction[], level return endIndices.includes(pos.y * level.width + pos.x); } -export function validatePathologyLevelValid(data: string): { valid: boolean, reasons: string[] } { +export function validatePathologyLevel(data: string): { valid: boolean, reasons: string[] } { // data must have at least ONE start and ONE end const reasons = []; const dataSplit = data.split('\n'); @@ -95,6 +95,10 @@ export function validatePathologyLevelValid(data: string): { valid: boolean, rea endCount++; } } + + if (TileTypeHelper.isOnExit(tileType)) { + reasons.push(`Invalid tile type: ${tileType}`); + } } } diff --git a/tests/helpers/helpers.test.ts b/tests/helpers/helpers.test.ts index b0626b34a..555bef2e8 100644 --- a/tests/helpers/helpers.test.ts +++ b/tests/helpers/helpers.test.ts @@ -1,7 +1,7 @@ import TileType from '@root/constants/tileType'; import { generatePassword } from '@root/helpers/generatePassword'; import { parseHostname, parseSubdomain } from '@root/helpers/parseUrl'; -import { validatePathologyLevelValid } from '@root/helpers/validators/validatePathology'; +import { validatePathologyLevel } from '@root/helpers/validators/validatePathology'; import { validateSokopathLevel } from '@root/helpers/validators/validateSokopath'; import TestId from '../../constants/testId'; import getDifficultyEstimate from '../../helpers/getDifficultyEstimate'; @@ -136,14 +136,16 @@ describe('helpers/*.ts', () => { expect(parseHostname('localhost')).toBe('localhost'); expect(parseHostname('')).toBe(null); }); - test('validatePathologyLevelValid', async () => { + test('validatePathologyLevel', async () => { const emptyGrid = '000'; const gridWithOnlyOneStart = '00' + TileType.Player; const gridWithOneStartAndOneEnd = '00' + TileType.Player + TileType.Exit; + const gridWithInvalidTile = '0' + TileType.PlayerOnExit + TileType.Player + TileType.Exit; - expect(validatePathologyLevelValid(emptyGrid).reasons).toMatchObject(['Must have exactly one player', 'Must have at least one exit']); - expect(validatePathologyLevelValid(gridWithOnlyOneStart).reasons).toMatchObject(['Must have at least one exit']); - expect(validatePathologyLevelValid(gridWithOneStartAndOneEnd).valid).toBe(true); + expect(validatePathologyLevel(emptyGrid).reasons).toMatchObject(['Must have exactly one player', 'Must have at least one exit']); + expect(validatePathologyLevel(gridWithOnlyOneStart).reasons).toMatchObject(['Must have at least one exit']); + expect(validatePathologyLevel(gridWithOneStartAndOneEnd).valid).toBe(true); + expect(validatePathologyLevel(gridWithInvalidTile).reasons).toMatchObject([`Invalid tile type: ${TileType.PlayerOnExit}`]); }); test('validiateSokopathLevelValid', async () => { const emptyGrid = '000';