-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from janis-commerce/feature/APPSRN-288-validaci…
…on-de-datos-core crashlytics core data validation was updated
- Loading branch information
Showing
12 changed files
with
18,603 additions
and
13,841 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,9 @@ | ||
export default [ | ||
'userName', | ||
'userSurname', | ||
'userEmail', | ||
'userId', | ||
'client', | ||
'language', | ||
'currency', | ||
]; |
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
const formatUserData = (data) => { | ||
if(!data || data && !Object.keys(data).length) return {}; | ||
const formatUserData = data => { | ||
if (!data || (data && !Object.keys(data).length)) return {}; | ||
|
||
const { | ||
email = '', | ||
sub = '', | ||
tname = '', | ||
locale = '', | ||
isDev = '', | ||
tcurrency = '', | ||
given_name = '', | ||
family_name = '' | ||
} = data; | ||
const { | ||
email = '', | ||
sub = '', | ||
tcode = '', | ||
locale = '', | ||
isDev = '', | ||
tcurrency = '', | ||
given_name = '', | ||
family_name = '', | ||
} = data; | ||
|
||
return { | ||
userName: given_name, | ||
userSurname: family_name, | ||
userEmail: email, | ||
userId: sub, | ||
client: tname, | ||
language: locale, | ||
currency: tcurrency, | ||
isDev, | ||
} | ||
return { | ||
userName: given_name, | ||
userSurname: family_name, | ||
userEmail: email, | ||
userId: sub, | ||
client: tcode, | ||
language: locale, | ||
currency: tcurrency, | ||
isDev, | ||
}; | ||
}; | ||
|
||
export default formatUserData; | ||
export default formatUserData; |
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,58 @@ | ||
import coreData from '../constant/coreData.js'; | ||
|
||
/** | ||
* @name valueIsValidType | ||
* @description is a utility that returns a boolean true value when the argument is a string or a number, otherwise returns false | ||
* @param {string | number} value is data to validate | ||
* @returns {boolean} | ||
* @example | ||
* | ||
* valueIsValidType('string') => true; | ||
* valueIsValidType(3) => true; | ||
* valueIsValidType(0) => true; | ||
* valueIsValidType('') => false; | ||
* valueIsValidType(null) => false; | ||
*/ | ||
|
||
export const valueIsValidType = value => | ||
typeof value === 'number' || (!!value && typeof value === 'string'); | ||
|
||
/** | ||
* @name includesAllProperties | ||
* @param {Object} data is an object with keys that you want to validate. | ||
* @param {String[]} properties are the keys that you want validate, in addition to those required by default | ||
* @returns {boolean} | ||
* @example | ||
* | ||
* includesAllProperties({name:'janis'}, ['name','address']) => false; | ||
* includesAllProperties({name:'janis',address:'costa rica 4988'}, ['name','address']) => true; | ||
* includesAllProperties({name:'', address: 'costa rica 4988},['name','address']) => false; | ||
*/ | ||
|
||
export const includesAllProperties = (data, properties = []) => { | ||
if (!data || !Object.keys(data).length) return false; | ||
|
||
if (!properties || !Array.isArray(properties)) return true; | ||
|
||
const validProperties = properties.filter(prop => typeof prop === 'string'); | ||
|
||
const dataKeys = Object.keys(data); | ||
|
||
return validProperties.every( | ||
value => dataKeys.includes(value) && valueIsValidType(data[value]), | ||
); | ||
}; | ||
|
||
/** | ||
* @name validateCoreData | ||
* @description This utility validates an object and returns true when all required core data keys are found in it, otherwise, returns false | ||
* @param {*} data object to be validated | ||
* @returns {boolean} | ||
* @example | ||
* validateCoreData({userName:'janis',userSurname:'fizzmod',userEmail:'janis@janis.im',userId:'janis123',client:'janis',language:'en-us,'currency':'currency'}) => true; | ||
* validateCoreData({userName:'',userSurname:'',userEmail:'janis@janis.im',userId:'janis123',client:'janis',language:'en-us,'currency':'currency'}) => false; | ||
* validateCoreData({}) => false; | ||
*/ | ||
|
||
export const validateCoreData = (data = {}) => | ||
includesAllProperties(data, coreData); |
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
Oops, something went wrong.