Skip to content

Commit

Permalink
HARMONY-1894: Fix error message for exceeding label max characters
Browse files Browse the repository at this point in the history
  • Loading branch information
indiejames committed Sep 27, 2024
1 parent 0c92c27 commit 180267f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions services/harmony/app/models/label.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Transaction } from '../util/db';

/**
* Returns an error message if a label is empty or exceeds 255 characters in length
* Returns an error message if a label exceeds 255 characters in length
*
* @param tag - The image tag to check
* @returns An error message if the tag is not valid, null otherwise
*/
export function checkLabel(label: string): string {
if (label.length < 1 || label.length > 255) {
const message = 'Labels must consist of at least one 1 and no more than 255 characters.';
if (label.length > 255) {
const message = 'Labels may not exceed 255 characters in length.';
return message;
}
return null;
Expand Down
3 changes: 1 addition & 2 deletions services/harmony/test/models/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ describe('checkLabel', function () {
it('should return an error message for invalid labels', function () {
// Examples of invalid labels
const invalidLabels = [
'', // empty
'a'.repeat(256), // Exceeds maximum length
];

const errorMessage = 'Labels must consist of at least one 1 and no more than 255 characters.';
const errorMessage = 'Labels may not exceed 255 characters in length.';

invalidLabels.forEach(label => {
const result = checkLabel(label);
Expand Down
2 changes: 1 addition & 1 deletion services/harmony/test/parameters/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('labels', function () {
});

it('returns a meaningful error message', async function () {
expect(this.res.text).to.include('Labels must consist of at least one 1 and no more than 255 characters');
expect(this.res.text).to.include('Labels may not exceed 255 characters in length.');
});
});
}
Expand Down

0 comments on commit 180267f

Please sign in to comment.