Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd92783
commit 7444bbc
Showing
4 changed files
with
155 additions
and
5 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -12,4 +12,5 @@ logs | ||
results | results | ||
|
|
||
node_modules | node_modules | ||
npm-debug.log | npm-debug.log | ||
examples/json |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
var Record = function(data) { | |||
|
|||
if(data.attributes) { | |||
this.attributes = data.attributes; | |||
delete data.attributes; | |||
} | |||
|
|||
this.fieldValues = {} | |||
this._data = data; | |||
|
|||
var key; | |||
|
|||
for(key in data) { | |||
(function (record, key) { | |||
record.__defineGetter__(key, function() { | |||
return record._data[key]; | |||
}); | |||
record.__defineSetter__(key, function(val) { | |||
record._data[key] = val; | |||
record.fieldValues[key] = val; | |||
}); | |||
}(this, key)); | |||
} | |||
} | |||
|
|||
Record.prototype.getFieldValues = function() { | |||
var fvs = this.fieldValues; | |||
for (var fieldKey in this) { | |||
if(fieldKey !== 'url' && fieldKey !== 'type' && fieldKey !== 'id' | |||
&& fieldKey.substring(0,1) !== '_' && fieldKey !== 'fieldValues' | |||
&& !this.__lookupGetter__(fieldKey) && typeof this[fieldKey] !== 'function') { | |||
if(!fvs[fieldKey]) { | |||
fvs[fieldKey] = this[fieldKey]; | |||
} | |||
} | |||
} | |||
return fvs; | |||
} | |||
|
|||
|
|||
module.exports = Record; |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,87 @@ | |||
var Record = require('../lib/record'); | |||
|
|||
var accountRec = { | |||
"attributes": { | |||
"type": "Account", | |||
"url": "/services/data/v24.0/sobjects/Account/001Q000000RpQagIAF" | |||
}, | |||
"Id": "001Q000000RpQagIAF", | |||
"IsDeleted": false, | |||
"MasterRecordId": null, | |||
"Name": "Portal House Account", | |||
"Type": null, | |||
"ParentId": null, | |||
"BillingStreet": null, | |||
"BillingCity": null, | |||
"BillingState": null, | |||
"BillingPostalCode": null, | |||
"BillingCountry": null, | |||
"ShippingStreet": null, | |||
"ShippingCity": null, | |||
"ShippingState": null, | |||
"ShippingPostalCode": null, | |||
"ShippingCountry": null, | |||
"Phone": null, | |||
"Fax": null, | |||
"Website": null, | |||
"Industry": null, | |||
"AnnualRevenue": null, | |||
"NumberOfEmployees": null, | |||
"Description": null, | |||
"OwnerId": "00530000004sFb6AAE", | |||
"CreatedDate": "2012-04-02T23:06:57.000+0000", | |||
"CreatedById": "00530000004sFb6AAE", | |||
"LastModifiedDate": "2012-04-02T23:06:57.000+0000", | |||
"LastModifiedById": "00530000004sFb6AAE", | |||
"SystemModstamp": "2012-05-03T19:24:28.000+0000", | |||
"LastActivityDate": "2012-05-03", | |||
"IsCustomerPortal": true, | |||
"Jigsaw": null, | |||
"JigsawCompanyId": null, | |||
"AccountSource": null, | |||
"SicDesc": null | |||
} | |||
|
|||
describe('#constructor', function() { | |||
|
|||
it('should allow me to set properties', function() { | |||
|
|||
var myRecord = new Record(accountRec); | |||
|
|||
myRecord.Fax = '248-443-3456'; | |||
|
|||
myRecord.Fax.should.equal('248-443-3456'); | |||
myRecord.fieldValues.Fax.should.equal('248-443-3456'); | |||
|
|||
}); | |||
|
|||
it('should allow me to set properties multiple times', function() { | |||
|
|||
var myRecord = new Record(accountRec); | |||
|
|||
myRecord.Fax = '248-443-3456'; | |||
myRecord.Fax = '248-443-3457'; | |||
myRecord.Fax = '248-443-3458'; | |||
|
|||
myRecord.Fax.should.equal('248-443-3458'); | |||
myRecord.fieldValues.Fax.should.equal('248-443-3458'); | |||
|
|||
}); | |||
|
|||
}); | |||
|
|||
describe('#getFieldValues', function() { | |||
|
|||
it('should return existing and custom set properties', function() { | |||
|
|||
var myRecord = new Record(accountRec); | |||
|
|||
// set a new Fax | |||
myRecord.Fax = '248-443-3456'; | |||
myRecord.Custom_Field__c = 'This is something'; | |||
|
|||
myRecord.getFieldValues().should.have.keys('Fax', 'Custom_Field__c'); | |||
|
|||
}); | |||
|
|||
}); |