Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(location): add validation for description property in PlaceIndex class #30974

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-location-alpha/lib/place-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ export class PlaceIndex extends PlaceIndexBase {
public readonly placeIndexUpdateTime: string;

constructor(scope: Construct, id: string, props: PlaceIndexProps = {}) {
if (props.description && !Token.isUnresolved(props.description) && props.description.length > 1000) {
throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`);
}

if (props.placeIndexName && !Token.isUnresolved(props.placeIndexName) && !/^[-.\w]{1,100}$/.test(props.placeIndexName)) {
throw new Error(`Invalid place index name. The place index name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.placeIndexName}`);
}
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-location-alpha/test/place-index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ test('create a place index', () => {
});
});

test('create a place index with description', () => {
new PlaceIndex(stack, 'PlaceIndex', {
description: 'my-description',
});

Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', {
DataSource: 'Esri',
IndexName: 'PlaceIndex',
Description: 'my-description',
});
});

test('creates a place index with empty description', () => {
new PlaceIndex(stack, 'PlaceIndex', {
description: '',
});

Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', {
Description: '',
});
});

test('throws with invalid description', () => {
expect(() => new PlaceIndex(stack, 'PlaceIndex', {
description: 'a'.repeat(1001),
})).toThrow('`description` must be between 0 and 1000 characters. Received: 1001 characters');
});

test('throws with invalid name', () => {
expect(() => new PlaceIndex(stack, 'PlaceIndex', {
placeIndexName: 'inv@lid',
Expand Down
Loading