Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let originalRecord = _.cloneDeep(data[0])
let pendingRecord = _.cloneDeep(data[0])
if (originalRecord.familyName) {
pendingRecord.familyName = (
originalRecord.familyName
+ Math.floor(Math.random() * 999999)
).slice(0, 20)
} else {
pendingRecord.familyName = '' + Math.floor(Math.random() * 999)
}
pendingRecord.emailAddresses.push({
email: 'addedFromRNContacts@example.com',
type: 'work'
})
console.log('begin updateContact')
Contacts.updateContact(pendingRecord, (err, data) => {
console.log('updateContact callback')
if (err) throw err
Contacts.getAll((err, data) => {
let updatedRecord = _.find(data, {recordID: originalRecord.recordID})
console.log('original record:', originalRecord)
console.log('updated record:', updatedRecord)
invariant(
updatedRecord.emailAddresses.length === originalRecord.emailAddresses.length + 1,
'Email address array is not length one greater than original record'
)
invariant(
updatedRecord.familyName === pendingRecord.familyName,
'family name was not updated'
)
})
})