Skip to content

Commit

Permalink
Tags => tag (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobuck-aws authored May 30, 2024
1 parent db8b822 commit 7064384
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const addTemplateTag = (construct: Construct, tag: string) => {

const appendTagToDescription = (existingDescription: string, newTag: string): string => {
// Check if the existing description already has tags
if (existingDescription.includes('(Tags:')) {
if (existingDescription.includes('(tag:')) {
// Extract the existing tags
const startIndex = existingDescription.indexOf('(Tags:') + 6;
const startIndex = existingDescription.indexOf('(tag:') + 6;
const endIndex = existingDescription.lastIndexOf(')');
const existingTags = existingDescription.substring(startIndex, endIndex).split(', ');

Expand All @@ -43,6 +43,6 @@ const appendTagToDescription = (existingDescription: string, newTag: string): st
}
} else {
// Append the new tag to the description
return `${existingDescription} (Tags: ${newTag})`;
return `${existingDescription} (tag: ${newTag})`;
}
};
12 changes: 6 additions & 6 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ describe('addTemplateTag', () => {
it('should append telemetry and tags to existing template description', () => {
const stackA = new Stack(app, 'TestStackA', { description: 'test' });
const newTag = 'new-tag';
const expectedDescription = `test - ${telemetryConst} (Tags: new-tag)`;
const expectedDescription = `test - ${telemetryConst} (tag: new-tag)`;
addTemplateTag(stackA, newTag);
expect(stackA.templateOptions.description).toBe(expectedDescription);
});

it('should append a new tag to the description if it does not have any tags', () => {
const stackB = new Stack(app, 'TestStackB');
const newTag = 'new-tag';
const expectedDescription = `${telemetryConst} (Tags: new-tag)`;
const expectedDescription = `${telemetryConst} (tag: new-tag)`;
addTemplateTag(stackB, newTag);
expect(stackB.templateOptions.description).toBe(expectedDescription);
});

it('should append a new tag to the existing tags in the description', () => {
const existingDescription = `This is a sample description - ${telemetryConst} (Tags: tag1, tag2)`;
const existingDescription = `This is a sample description - ${telemetryConst} (tag: tag1, tag2)`;
const stackC = new Stack(app, 'TestStackC', { description: existingDescription });
const newTag = 'new-tag';
const expectedDescription = `This is a sample description - ${telemetryConst} (Tags: tag1, tag2, new-tag)`;
const expectedDescription = `This is a sample description - ${telemetryConst} (tag: tag1, tag2, new-tag)`;
addTemplateTag(stackC, newTag);
expect(stackC.templateOptions.description).toBe(expectedDescription);
});

it('should not append a new tag if it already exists in the description', () => {
const existingDescription = `This is a sample description - ${telemetryConst} (Tags: tag1, tag2, new-tag)`;
const existingDescription = `This is a sample description - ${telemetryConst} (tag: tag1, tag2, new-tag)`;
const stackD = new Stack(app, 'TestStackD', { description: existingDescription });
const newTag = 'new-tag';
const expectedDescription = `This is a sample description - ${telemetryConst} (Tags: tag1, tag2, new-tag)`;
const expectedDescription = `This is a sample description - ${telemetryConst} (tag: tag1, tag2, new-tag)`;
addTemplateTag(stackD, newTag);
expect(stackD.templateOptions.description).toBe(expectedDescription);
});
Expand Down

0 comments on commit 7064384

Please sign in to comment.