Skip to content

Commit

Permalink
Merge branch 'fix/avoid-null-cases-for-isempty-operator' into 'master'
Browse files Browse the repository at this point in the history
feat: Validated null cases for isEmpty operator

See merge request auto-cloud/cloudgraph/sdk!58
  • Loading branch information
tyler-dunkel committed Mar 18, 2022
2 parents b40db40 + d142342 commit e4defe3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules-engine/operators/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
}

// Verify empty/filled objects
if (typeof data === 'object') {
if (typeof data === 'object' && data !== null) {
const hasKeys = Object.keys(data).length
return shouldBeEmpty ? hasKeys === 0 : hasKeys > 0
}
Expand Down
15 changes: 15 additions & 0 deletions tests/operators/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,20 @@ describe('Common Operators', () => {
test('Should fail given a filled object', () => {
expect(CommonOperators.isEmpty({ key: 'one' }, true)).toBeFalsy()
})
test('Should fail given a null value', () => {
expect(CommonOperators.isEmpty(null, true)).toBeFalsy()
})
test('Should fail given an undefined value', () => {
expect(CommonOperators.isEmpty(undefined, true)).toBeFalsy()
})
test('Should fail given an integer', () => {
expect(CommonOperators.isEmpty(33, true)).toBeFalsy()
})
test('Should fail given a string', () => {
expect(CommonOperators.isEmpty('string', true)).toBeFalsy()
})
test('Should fail given a boolean', () => {
expect(CommonOperators.isEmpty(true, true)).toBeFalsy()
})
})
})

0 comments on commit e4defe3

Please sign in to comment.