Skip to content

Commit

Permalink
Merge branch 'fix/has-roles-when-currentUser-is-string' of github.com…
Browse files Browse the repository at this point in the history
…:dac09/redwood into fix/has-roles-when-currentUser-is-string

* 'fix/has-roles-when-currentUser-is-string' of github.com:dac09/redwood:
  Fix react/prop-types lint warnings (redwoodjs#4674)
  Allow the number 0 for numericality validation values (redwoodjs#4700)
  • Loading branch information
dac09 committed Mar 10, 2022
2 parents f1751a4 + fcf9974 commit 3f48a0b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
30 changes: 24 additions & 6 deletions packages/api/src/validations/__tests__/validations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ describe('validate numericality', () => {
expect(() =>
validate(2.2, 'number', { numericality: { lessThan: 2.1 } })
).toThrow(ValidationErrors.LessThanNumericalityValidationError)
expect(() =>
validate(2, 'number', { numericality: { lessThan: 0 } })
).toThrow(ValidationErrors.LessThanNumericalityValidationError)

expect(() =>
validate(2, 'number', { numericality: { lessThan: 3 } })
Expand All @@ -470,7 +473,7 @@ describe('validate numericality', () => {
} catch (e) {
expect(e.message).toEqual('number must be less than 1')
}
expect.assertions(7)
expect.assertions(8)
})

it('checks if value is less than or equal to required number', () => {
Expand All @@ -486,6 +489,9 @@ describe('validate numericality', () => {
expect(() =>
validate(2.2, 'number', { numericality: { lessThanOrEqual: 2 } })
).toThrow(ValidationErrors.LessThanOrEqualNumericalityValidationError)
expect(() =>
validate(2, 'number', { numericality: { lessThanOrEqual: 0 } })
).toThrow(ValidationErrors.LessThanOrEqualNumericalityValidationError)

expect(() =>
validate(2.2, 'number', { numericality: { lessThanOrEqual: 2.3 } })
Expand All @@ -500,7 +506,7 @@ describe('validate numericality', () => {
} catch (e) {
expect(e.message).toEqual('number must be less than or equal to 2')
}
expect.assertions(7)
expect.assertions(8)
})

it('checks if value is greater than required number', () => {
Expand All @@ -519,6 +525,9 @@ describe('validate numericality', () => {
expect(() =>
validate(3.0, 'number', { numericality: { greaterThan: 3 } })
).toThrow(ValidationErrors.GreaterThanNumericalityValidationError)
expect(() =>
validate(-1, 'number', { numericality: { greaterThan: 0 } })
).toThrow(ValidationErrors.GreaterThanNumericalityValidationError)

expect(() =>
validate(3, 'number', { numericality: { greaterThan: 2 } })
Expand All @@ -533,7 +542,7 @@ describe('validate numericality', () => {
} catch (e) {
expect(e.message).toEqual('number must be greater than 3')
}
expect.assertions(8)
expect.assertions(9)
})

it('checks if value is greater than or equal to required number', () => {
Expand All @@ -543,6 +552,9 @@ describe('validate numericality', () => {
expect(() =>
validate(3.0, 'number', { numericality: { greaterThanOrEqual: 3.1 } })
).toThrow(ValidationErrors.GreaterThanOrEqualNumericalityValidationError)
expect(() =>
validate(-1, 'number', { numericality: { greaterThanOrEqual: 0 } })
).toThrow(ValidationErrors.GreaterThanOrEqualNumericalityValidationError)

expect(() =>
validate(3, 'number', { numericality: { greaterThan: 2 } })
Expand All @@ -567,7 +579,7 @@ describe('validate numericality', () => {
} catch (e) {
expect(e.message).toEqual('number must be greater than or equal to 3')
}
expect.assertions(7)
expect.assertions(8)
})

it('checks if value is not equal to required number', () => {
Expand All @@ -583,6 +595,9 @@ describe('validate numericality', () => {
expect(() =>
validate(2.9, 'number', { numericality: { equal: 3 } })
).toThrow(ValidationErrors.EqualNumericalityValidationError)
expect(() => validate(2, 'number', { numericality: { equal: 0 } })).toThrow(
ValidationErrors.EqualNumericalityValidationError
)

expect(() =>
validate(2, 'number', { numericality: { equal: 2 } })
Expand All @@ -603,7 +618,7 @@ describe('validate numericality', () => {
} catch (e) {
expect(e.message).toEqual('number must equal 3')
}
expect.assertions(9)
expect.assertions(10)
})

it('checks if not equal to required number', () => {
Expand All @@ -616,6 +631,9 @@ describe('validate numericality', () => {
expect(() =>
validate(3.0, 'number', { numericality: { otherThan: 3 } })
).toThrow(ValidationErrors.OtherThanNumericalityValidationError)
expect(() =>
validate(0, 'number', { numericality: { otherThan: 0 } })
).toThrow(ValidationErrors.OtherThanNumericalityValidationError)

expect(() =>
validate(2, 'number', { numericality: { otherThan: 3 } })
Expand All @@ -633,7 +651,7 @@ describe('validate numericality', () => {
} catch (e) {
expect(e.message).toEqual('number must not equal 3')
}
expect.assertions(7)
expect.assertions(8)
})

it('checks for a value being even', () => {
Expand Down
15 changes: 9 additions & 6 deletions packages/api/src/validations/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,38 +407,41 @@ const VALIDATORS = {
if (options.integer && !Number.isInteger(value)) {
validationError('integerNumericality', name, options)
}
if (options.lessThan && (value as number) >= options.lessThan) {
if (options.lessThan != null && (value as number) >= options.lessThan) {
validationError('lessThanNumericality', name, options, {
lessThan: options.lessThan,
})
}
if (
options.lessThanOrEqual &&
options.lessThanOrEqual != null &&
(value as number) > options.lessThanOrEqual
) {
validationError('lessThanOrEqualNumericality', name, options, {
lessThanOrEqual: options.lessThanOrEqual,
})
}
if (options.greaterThan && (value as number) <= options.greaterThan) {
if (
options.greaterThan != null &&
(value as number) <= options.greaterThan
) {
validationError('greaterThanNumericality', name, options, {
greaterThan: options.greaterThan,
})
}
if (
options.greaterThanOrEqual &&
options.greaterThanOrEqual != null &&
(value as number) < options.greaterThanOrEqual
) {
validationError('greaterThanOrEqualNumericality', name, options, {
greaterThanOrEqual: options.greaterThanOrEqual,
})
}
if (options.equal && value !== options.equal) {
if (options.equal != null && value !== options.equal) {
validationError('equalNumericality', name, options, {
equal: options.equal,
})
}
if (options.otherThan && value === options.otherThan) {
if (options.otherThan != null && value === options.otherThan) {
validationError('otherThanNumericality', name, options, {
otherThan: options.otherThan,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ function Route(props: RouteProps | RedirectRouteProps | NotFoundRouteProps) {
return <InternalRoute {...props} />
}

const InternalRoute: React.VFC<InternalRouteProps> = ({
const InternalRoute = ({
path,
page,
name,
redirect,
notfound,
}) => {
}: InternalRouteProps) => {
const routerState = useRouterState()
const activePageContext = useActivePageContext()

Expand Down
5 changes: 1 addition & 4 deletions packages/router/src/splash-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ interface SplashPageProps {
routes: any[]
}

const SplashPage: React.VFC<SplashPageProps> = ({
hasGeneratedRoutes,
routes,
}) => {
const SplashPage = ({ hasGeneratedRoutes, routes }: SplashPageProps) => {
const version = useVersion()
return (
<>
Expand Down

0 comments on commit 3f48a0b

Please sign in to comment.