Skip to content

Commit

Permalink
Change address book item name validation error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jmealy committed Dec 23, 2024
1 parent 71acb17 commit 9797af0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('CreateAddressBookItemDtoSchema', () => {
expect(result.success).toBe(true);
});

it('should not verify an CreateAddressBookItemDto with a shorter name', () => {
it('should not verify a CreateAddressBookItemDto with a shorter name', () => {
const createAddressBookItemDto = createAddressBookItemDtoBuilder()
.with('name', faker.string.alphanumeric({ length: 2 }))
.build();
Expand All @@ -28,15 +28,15 @@ describe('CreateAddressBookItemDtoSchema', () => {
code: 'too_small',
inclusive: true,
exact: false,
message: 'Address Books items names must be at least 3 characters long',
message: 'Address book entry names must be at least 3 characters long',
minimum: 3,
path: ['name'],
type: 'string',
},
]);
});

it('should not verify an CreateAddressBookItemDto with a number name', () => {
it('should not verify a CreateAddressBookItemDto with a number name', () => {
const createAddressBookItemDto = createAddressBookItemDtoBuilder()
// @ts-expect-error - should be strings
.with('name', faker.number.int())
Expand All @@ -57,7 +57,7 @@ describe('CreateAddressBookItemDtoSchema', () => {
]);
});

it('should not verify an CreateAddressBookItemDto with a longer name', () => {
it('should not verify a CreateAddressBookItemDto with a longer name', () => {
const createAddressBookItemDto = createAddressBookItemDtoBuilder()
.with('name', faker.string.alphanumeric({ length: 51 }))
.build();
Expand All @@ -71,15 +71,15 @@ describe('CreateAddressBookItemDtoSchema', () => {
code: 'too_big',
inclusive: true,
exact: false,
message: 'Address Books items names must be at most 50 characters long',
message: 'Address book entry names must be at most 50 characters long',
maximum: 50,
path: ['name'],
type: 'string',
},
]);
});

it('should not verify an CreateAddressBookItemDto with a malformed name', () => {
it('should not verify a CreateAddressBookItemDto with a malformed name', () => {
const createAddressBookItemDto = createAddressBookItemDtoBuilder()
.with('name', '////')
.build();
Expand All @@ -92,14 +92,14 @@ describe('CreateAddressBookItemDtoSchema', () => {
{
code: 'invalid_string',
message:
'Address Books items names must start with a letter or number and can contain alphanumeric characters, periods, underscores, or hyphens',
'Address book entry names must start with a letter or number and ca Contain alphanumeric characters, periods, underscores, or hyphens',
path: ['name'],
validation: 'regex',
},
]);
});

it('should not verify an CreateAddressBookItemDto with a malformed address', () => {
it('should not verify a CreateAddressBookItemDto with a malformed address', () => {
const createAddressBookItemDto = createAddressBookItemDtoBuilder()
.with('address', '0x123')
.build();
Expand All @@ -117,7 +117,7 @@ describe('CreateAddressBookItemDtoSchema', () => {
]);
});

it('should checksum the address of an CreateAddressBookItemDto', () => {
it('should checksum the address of a CreateAddressBookItemDto', () => {
const createAddressBookItemDto = createAddressBookItemDtoBuilder().build();
// @ts-expect-error - address should be `0x${string}`
createAddressBookItemDto.address =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('AddressBookItemNameSchema', () => {
inclusive: true,
exact: false,
message:
'Address Books items names must be at least 3 characters long',
'Address book entry names must be at least 3 characters long',
path: [],
},
]),
Expand All @@ -80,7 +80,7 @@ describe('AddressBookItemNameSchema', () => {
inclusive: true,
exact: false,
message:
'Address Books items names must be at most 50 characters long',
'Address book entry names must be at most 50 characters long',
path: [],
},
]),
Expand All @@ -99,7 +99,7 @@ describe('AddressBookItemNameSchema', () => {
validation: 'regex',
code: 'invalid_string',
message:
'Address Books items names must start with a letter or number and can contain alphanumeric characters, periods, underscores, or hyphens',
'Address book entry names must start with a letter or number and can contain alphanumeric characters, periods, underscores, or hyphens',
path: [],
},
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { z } from 'zod';
export const AddressBookItemNameSchema = z
.string()
.min(3, {
message: 'Address Books items names must be at least 3 characters long',
message: 'Address book entry names must be at least 3 characters long',
})
.max(50, {
message: 'Address Books items names must be at most 50 characters long',
message: 'Address book entry names must be at most 50 characters long',
})
.regex(/^[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*$/, {
message:
'Address Books items names must start with a letter or number and can contain alphanumeric characters, periods, underscores, or hyphens',
'Address book entry names must start with a letter or number and can contain alphanumeric characters, periods, underscores, or hyphens',
});

0 comments on commit 9797af0

Please sign in to comment.