fix: yup error messages

This commit is contained in:
José Oliveira 2021-03-23 18:28:35 +00:00 committed by Josh Harvey
parent afe10635b2
commit b367653e09

View file

@ -110,10 +110,10 @@ const Schema = Yup.object()
}) })
.test(({ threshold, triggerType }, context) => { .test(({ threshold, triggerType }, context) => {
const errorMessages = { const errorMessages = {
txAmount: threshold => 'Amount must be non negative', txAmount: threshold => 'Amount must be greater than or equal to 0',
txVolume: threshold => { txVolume: threshold => {
const thresholdMessage = 'Volume must be non negative' const thresholdMessage = 'Volume must be greater than or equal to 0'
const thresholdDaysMessage = 'Days must be positive' const thresholdDaysMessage = 'Days must be greater than 0'
let message = '' let message = ''
if (threshold.threshold < 0) message = message.concat(thresholdMessage) if (threshold.threshold < 0) message = message.concat(thresholdMessage)
if (threshold.thresholdDays <= 0) if (threshold.thresholdDays <= 0)
@ -124,8 +124,9 @@ const Schema = Yup.object()
return message return message
}, },
txVelocity: threshold => { txVelocity: threshold => {
const thresholdMessage = 'Transactions must be non negative' const thresholdMessage =
const thresholdDaysMessage = 'Days must be positive' 'Transactions must be greater than or equal to 0'
const thresholdDaysMessage = 'Days must be greater than 0'
let message = '' let message = ''
if (threshold.threshold <= 0) message = message.concat(thresholdMessage) if (threshold.threshold <= 0) message = message.concat(thresholdMessage)
if (threshold.thresholdDays <= 0) if (threshold.thresholdDays <= 0)
@ -135,7 +136,7 @@ const Schema = Yup.object()
console.log(message) console.log(message)
return message return message
}, },
consecutiveDays: threshold => 'Days must be non negative' consecutiveDays: threshold => 'Days must be greater than or equal to 0'
} }
const thresholdValidator = { const thresholdValidator = {
txAmount: threshold => threshold.threshold >= 0, txAmount: threshold => threshold.threshold >= 0,
@ -164,7 +165,7 @@ const Schema = Yup.object()
(requirement && requirementValidator(requirement)) || (requirement && requirementValidator(requirement)) ||
context.createError({ context.createError({
path: 'requirement', path: 'requirement',
message: 'Suspension days must be positive' message: 'Suspension days must be greater than 0'
}) })
) )
}) })