Skip to content

Commit

Permalink
Merge pull request #33 from tictactrip/feat/studioStopClusterFormat
Browse files Browse the repository at this point in the history
feat(ground-place-sdk/src/classes/groundplaces): stopCluster name is not in CITY, REGION, COUNTRY format
  • Loading branch information
EMILIE-NDIONE authored Jan 2, 2024
2 parents a894ccf + 60b4362 commit 98fd539
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions __tests__/groundplaces/updateStopCluster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import * as mockSmallGroundPlacesFile from '../../mocks/smallGroundPlacesFile.js
import { GroundPlacesFile } from '../../src/types';

describe('#updateStopCluster', () => {
it('should not update the name of the StopCluster and throw error', () => {
const groundPlacesService: GroundPlacesController = new GroundPlacesController();
let thrownError: Error;
groundPlacesService.init(mockSmallGroundPlacesFile as GroundPlacesFile);

try {
groundPlacesService.updateStopCluster('c|FRstrasbou@u0ts2', { name: 'Strasbourg, Hauts-de-france France' });
} catch (error) {
thrownError = error;
}

expect(thrownError).toEqual(
new Error(
'The StopCluster name you entered (Strasbourg, Hauts-de-france France) does not respect the following format: CITY, REGION, COUNTRY, please correct!',
),
);
});

it('should update the name of the StopCluster', () => {
const groundPlacesService: GroundPlacesController = new GroundPlacesController();

Expand Down
7 changes: 7 additions & 0 deletions src/classes/groundplaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ export class GroundPlacesController {
try {
this.storageService.updatePlace(stopClusterGpuid, propertiesToUpdate, GroundPlaceType.CLUSTER);

// If stopCluster name doesn't respect this format: CITY, REGION, COUNTRY
if (propertiesToUpdate?.name && propertiesToUpdate?.name.split(',').length !== 3) {
throw new Error(
`The StopCluster name you entered (${propertiesToUpdate?.name}) does not respect the following format: CITY, REGION, COUNTRY, please correct!`,
);
}

// If latitude and/or longitude have updates wanted, first check that the new distance is correct with all StopGroup childs
if (propertiesToUpdate.latitude || propertiesToUpdate.longitude) {
const stopClusterUpdated: StopCluster = this.storageService.getStopClusterByGpuid(stopClusterGpuid);
Expand Down

0 comments on commit 98fd539

Please sign in to comment.