Skip to content

Commit 1d4d9bd

Browse files
Merge pull request #39 from andrejpavlovic/fix/support-falsey-facet-value
Fixed ignoring of falsey facet values by transaction builder
2 parents 80a1e45 + f6c4936 commit 1d4d9bd

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/transaction/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class Transaction<T extends Object, V> implements ITransaction<T> {
261261

262262
const facetValue = facetDataMap[idx];
263263

264-
if (facetValue) {
264+
if (facetValue !== undefined) {
265265
acc[f.args.propertyName] = facetValue;
266266
}
267267

tests/mutation.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,45 @@ describe('Mutation handling', () => {
9797
console.log(transaction.getSetNQuadsString());
9898
});
9999

100+
it('should handle falsey facet correctly', () => {
101+
class OrderFacet {
102+
@Facet()
103+
order?: number;
104+
}
105+
106+
@Node()
107+
class Person {
108+
@Uid()
109+
id: string;
110+
111+
@Predicate({ type: () => Person, facet: OrderFacet })
112+
friends: IPredicate<Person, OrderFacet>;
113+
}
114+
115+
const data = [
116+
{
117+
uid: '0x1',
118+
'Person.name': 'John',
119+
'Person.friends|order': { '0': 0 },
120+
'Person.friends': [
121+
{
122+
uid: '0x2',
123+
'Person.name': 'Jane',
124+
}
125+
]
126+
}
127+
];
128+
129+
const transaction = TransactionBuilder.of(Person)
130+
.setRoot(data)
131+
.build();
132+
133+
const friends = transaction.tree[0].friends.get();
134+
const facet = transaction.tree[0].friends.getFacet(friends[0]);
135+
expect(facet).not.toBeUndefined();
136+
expect(facet!.order).toBe(0);
137+
})
138+
100139
it('should handle nested correctly', function() {
101140
class PersonKnows {
102141
@Facet()

0 commit comments

Comments
 (0)