Skip to content

Commit dd9e709

Browse files
Show errors correctly (#505)
* fix(dapp): show errors correctly * fix(sdk): Improve lenght error test * fix(sdk): Improve lenght error tests * fix(sdk): Improve lenght error tests --------- Co-authored-by: Mario Sarcevic <mario.sarcevic@iota.org>
1 parent fe1db39 commit dd9e709

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

sdk/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ export function validateIotaName(
105105
if (!allowSubnames && parts.length > 2) {
106106
return 'No subnames allowed';
107107
}
108-
if (!NAME_DOT_REGEX.test(name)) {
109-
return 'Invalid characters. Only a-z, 0-9, and hyphens (not at the beginning or end) are allowed';
110-
}
111108
for (const part of parts.slice(0, -1)) {
112109
if (part.length < minLength || part.length > maxLength) {
113110
return `Name must be ${minLength}-${maxLength} characters long`;
114111
}
115112
}
113+
if (!NAME_DOT_REGEX.test(name)) {
114+
return 'Invalid characters. Only a-z, 0-9, and hyphens (not at the beginning or end) are allowed';
115+
}
116116
return null;
117117
}

sdk/test/name-validation.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,15 @@ describe('Name validation with error', () => {
105105
});
106106

107107
test('should check the length', () => {
108-
expect(validateIotaName('name.iota', 10)).not.toBeNull();
109-
expect(validateIotaName('nameeeeeeeeeee.iota', 3, 10)).not.toBeNull();
108+
expect(validateIotaName('name.iota', 10)).toEqual('Name must be 10-64 characters long');
109+
expect(validateIotaName('nameeeeeeeeeee.iota', 3, 10)).toEqual(
110+
'Name must be 3-10 characters long',
111+
);
112+
expect(
113+
validateIotaName(
114+
'veryveryveryveryveryveryveryveryveryveryveryverylongnamewithmorethan64chars.iota',
115+
),
116+
).toEqual('Name must be 3-64 characters long');
110117
});
111118

112119
test('should check the subnames', () => {

0 commit comments

Comments
 (0)