-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle empty strings on permissions gracefully in access service (…
…#8306) Splitting #8271 into smaller pieces. This first PR will focus on making access service handle empty string inputs gracefully and converting them to null before inserting them into the database.
- Loading branch information
1 parent
b037bfb
commit dcb0228
Showing
3 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { cleanPermissionEnvironment } from './access-service'; | ||
|
||
test('should convert all empty strings to null', () => { | ||
const permissions = [ | ||
{ | ||
name: 'UPDATE_PROJECT', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'UPDATE_FEATURE_VARIANTS', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'READ_PROJECT_API_TOKEN', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'CREATE_PROJECT_API_TOKEN', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'DELETE_PROJECT_API_TOKEN', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'UPDATE_PROJECT_SEGMENT', | ||
environment: '', | ||
}, | ||
]; | ||
|
||
const result = cleanPermissionEnvironment(permissions); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
name: 'UPDATE_PROJECT', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'UPDATE_FEATURE_VARIANTS', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'READ_PROJECT_API_TOKEN', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'CREATE_PROJECT_API_TOKEN', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'DELETE_PROJECT_API_TOKEN', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'UPDATE_PROJECT_SEGMENT', | ||
environment: null, | ||
}, | ||
]); | ||
}); | ||
|
||
test('should handle some permissions already having null values', () => { | ||
const permissions = [ | ||
{ | ||
name: 'UPDATE_PROJECT', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'UPDATE_FEATURE_VARIANTS', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'READ_PROJECT_API_TOKEN', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'CREATE_PROJECT_API_TOKEN', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'DELETE_PROJECT_API_TOKEN', | ||
environment: '', | ||
}, | ||
{ | ||
name: 'UPDATE_PROJECT_SEGMENT', | ||
environment: '', | ||
}, | ||
]; | ||
|
||
const result = cleanPermissionEnvironment(permissions); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
name: 'UPDATE_PROJECT', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'UPDATE_FEATURE_VARIANTS', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'READ_PROJECT_API_TOKEN', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'CREATE_PROJECT_API_TOKEN', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'DELETE_PROJECT_API_TOKEN', | ||
environment: null, | ||
}, | ||
{ | ||
name: 'UPDATE_PROJECT_SEGMENT', | ||
environment: null, | ||
}, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters