2022-11-17 04:16:49 +00:00
|
|
|
import { REP_UUID } from '../consts/REG_EXP_PATTERNS';
|
|
|
|
|
2023-04-04 03:25:23 +00:00
|
|
|
import testNotBlank from './testNotBlank';
|
|
|
|
|
2022-11-17 04:16:49 +00:00
|
|
|
const buildUUIDTestBatch: BuildInputTestBatchFunction = (
|
|
|
|
inputName,
|
|
|
|
onSuccess,
|
2023-03-04 00:28:48 +00:00
|
|
|
{ isRequired, onFinishBatch, ...defaults } = {},
|
2022-11-17 04:16:49 +00:00
|
|
|
onUUIDTestFailure,
|
|
|
|
) => ({
|
2022-11-25 04:56:46 +00:00
|
|
|
defaults: { ...defaults, onSuccess },
|
2023-03-04 00:28:48 +00:00
|
|
|
isRequired,
|
2022-11-25 04:56:46 +00:00
|
|
|
onFinishBatch,
|
2022-11-17 04:16:49 +00:00
|
|
|
tests: [
|
2023-04-04 03:25:23 +00:00
|
|
|
{
|
|
|
|
test: testNotBlank,
|
|
|
|
},
|
2022-11-17 04:16:49 +00:00
|
|
|
{
|
|
|
|
onFailure: (...args) => {
|
2023-04-04 03:25:23 +00:00
|
|
|
onUUIDTestFailure(<>{inputName} must be a valid UUID.</>, ...args);
|
2022-11-17 04:16:49 +00:00
|
|
|
},
|
|
|
|
test: ({ value }) => REP_UUID.test(value as string),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
export default buildUUIDTestBatch;
|