In this PR, we are refactoring two things: - leverage field.defaultValue for Select and MultiSelect settings form (instead of option.isDefault) - use quoted string (ex: "'USD'") for string default values to embrace backend format --------- Co-authored-by: Thaïs Guigon <guigon.thais@gmail.com>
39 lines
922 B
TypeScript
39 lines
922 B
TypeScript
import { SafeParseError } from 'zod';
|
|
|
|
import { simpleQuotesStringSchema } from '../simpleQuotesStringSchema';
|
|
|
|
describe('simpleQuotesStringSchema', () => {
|
|
it('validates a string with simple quotes', () => {
|
|
// Given
|
|
const input = "'with simple quotes'";
|
|
|
|
// When
|
|
const result = simpleQuotesStringSchema.parse(input);
|
|
|
|
// Then
|
|
expect(result).toBe(input);
|
|
});
|
|
|
|
it.each([
|
|
// Given
|
|
['no simple quotes'],
|
|
["'only at start"],
|
|
["only at end'"],
|
|
["mid'dle"],
|
|
[''],
|
|
])('fails for strings not wrapped in simple quotes (%s)', (input) => {
|
|
// When
|
|
const result = simpleQuotesStringSchema.safeParse(input);
|
|
|
|
// Then
|
|
expect(result.success).toBe(false);
|
|
expect((result as SafeParseError<string>).error.errors).toEqual([
|
|
{
|
|
code: 'custom',
|
|
message: 'String should be wrapped in simple quotes',
|
|
path: [],
|
|
},
|
|
]);
|
|
});
|
|
});
|