Skip to content

Commit

Permalink
Added condition to set default values for enums (hyperledger-archives…
Browse files Browse the repository at this point in the history
…#3444)

Signed-off-by: Erin Hughes <[email protected]>
  • Loading branch information
erin-hughes authored and jt-nti committed Feb 26, 2018
1 parent 93a02ab commit 60e4338
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/composer-common/lib/model/typed.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ class Typed {
const dateTime = new Date();
dateTime.setTime(Date.parse(defaultValue));
this.setPropertyValue(field.getName(), dateTime);
} else {
// following precident set in jsonpopulator.js - if we get this far the field should be an enum
this.setPropertyValue(field.getName(), defaultValue);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion packages/composer-common/test/model/typed.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ describe('Typed', () => {
'DateTime': '2017-09-26T22:35:53.871Z',
'Double': 3.142,
'Integer': 32768,
'Long': 10485760
'Long': 10485760,
'Test': 'THREE',
};

Object.keys(defaultValues).forEach((defaultValueType) => {
Expand All @@ -88,6 +89,11 @@ describe('Typed', () => {
const defaultValue = defaultValues[defaultValueType];
modelManager.addModelFile(`
namespace org.acme.defaults
enum Test {
o ONE
o TWO
o THREE
}
asset DefaultAsset identified by assetId {
o String assetId
o ${defaultValueType} value default=${JSON.stringify(defaultValue)}
Expand Down

0 comments on commit 60e4338

Please sign in to comment.