Skip to content

Commit

Permalink
test: update tests tckt-363
Browse files Browse the repository at this point in the history
  • Loading branch information
kalasgarov committed Nov 13, 2024
1 parent a89b9df commit 2dd84f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
22 changes: 20 additions & 2 deletions packages/forms/src/patterns/phone-number/phone-number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ describe('PhoneNumberPattern tests', () => {
const invalidInput = '123456abc';

expect(schema.safeParse(validInput).success).toBe(true);
expect(schema.safeParse(invalidInput).success).toBe(false);
const invalidResult = schema.safeParse(invalidInput);
expect(invalidResult.success).toBe(false);
expect(invalidResult.error?.issues[0].message).toBe(
'Phone number may only contain digits, spaces, parentheses, hyphens, and periods.'
);
});

it('should create schema for optional phone input', () => {
Expand All @@ -30,9 +34,16 @@ describe('PhoneNumberPattern tests', () => {
const schema = createPhoneSchema(data);
const validInput = '+12223334444';
const emptyInput = '';
const invalidInput = '123456abc';

expect(schema.safeParse(validInput).success).toBe(true);
expect(schema.safeParse(emptyInput).success).toBe(true);

const invalidResult = schema.safeParse(invalidInput);
expect(invalidResult.success).toBe(false);
expect(invalidResult.error?.issues[0].message).toBe(
'Phone number may only contain digits, spaces, parentheses, hyphens, and periods.'
);
});

it('should fail with less than 10 digits', () => {
Expand All @@ -44,7 +55,11 @@ describe('PhoneNumberPattern tests', () => {
const schema = createPhoneSchema(data);
const shortInput = '123456789';

expect(schema.safeParse(shortInput).success).toBe(false);
const shortInputResult = schema.safeParse(shortInput);
expect(shortInputResult.success).toBe(false);
expect(shortInputResult.error?.issues[0].message).toBe(
'Phone number must contain at least 10 digits'
);
});
});

Expand Down Expand Up @@ -88,6 +103,9 @@ describe('PhoneNumberPattern tests', () => {
const result = phoneNumberConfig.parseUserInput(pattern, invalidInput);
if (!result.success) {
expect(result.error).toBeDefined();
expect(result.error?.message).toContain(
'Phone number may only contain digits, spaces, parentheses, hyphens, and periods.'
);
} else {
expect.fail('Unexpected validation success');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('SelectDropdownPattern tests', () => {
if (result.success) {
expect(result.data).toBe('value1');
} else {
throw new Error('Unexpected validation failure');
expect.fail('Unexpected validation failure');
}
});

Expand All @@ -105,11 +105,11 @@ describe('SelectDropdownPattern tests', () => {
console.log('Test parse result (error case):', result);
if (!result.success) {
expect(result.error).toBeDefined();
expect(result.error.message).toBe(
expect(result.error?.message).toBe(
"Invalid enum value. Expected 'value1' | 'value2', received 'invalid'"
);
} else {
throw new Error('Unexpected validation success');
expect.fail('Unexpected validation success');
}
});

Expand All @@ -132,7 +132,7 @@ describe('SelectDropdownPattern tests', () => {
expect(result.data.required).toBe(true);
expect(result.data.options.length).toBe(2);
} else {
throw new Error('Unexpected validation failure');
expect.fail('Unexpected validation failure');
}
});

Expand All @@ -150,7 +150,7 @@ describe('SelectDropdownPattern tests', () => {
if (!result.success) {
expect(result.error).toBeDefined();
} else {
throw new Error('Unexpected validation success');
expect.fail('Unexpected validation success');
}
});
});
Expand Down

0 comments on commit 2dd84f4

Please sign in to comment.