-
Notifications
You must be signed in to change notification settings - Fork 224
Description
Describe the bug
I found, that I run into an issue when I basically call setReadOnlyFields after I call makeRelationship(). This should normally not a big issue, as you can just change the order of operation, but in our case, we return the record and then mock additional values on the record.
To Reproduce
Basically:
- We create a basic WebCart record and build the record
- We process it further by adding CartItems
- We process it even further by adding CartTaxes
- between all steps, the record is passed, instead of a builder object
Now in our case, we create CartDeliveryGroups in step 1 and now, I want to set TotalProductCount in step 2, which fails with System.JSONException: QueryResult must start with '{'.
The code pretty much looks like this in compressed and simplified form:
public WebCart mockCart(WebCart cart, CartDeliveryGroup deliveryGroup, Decimal quantity) { WebCart[] carts = (List<WebCart>) fflib_ApexMocksUtils.makeRelationship( List<WebCart>.class, new List<WebCart>{ cart }, CartDeliveryGroup.CartId, new List<List<CartDeliveryGroup>>{ new List<CartDeliveryGroup>{ deliveryGroup } } ); cart = carts[0]; cart = (WebCart) fflib_ApexMocksUtils.setReadOnlyFields(cart, WebCart.class, new Map<String, Object> { 'TotalProductCount' => quantity }); return cart; }
I am pretty sure, you can basically adjust the code for makeRelationship() to also use InjectChildrenEventHandler for setReadOnlyFields(), but I didn't try this out yet.
Expected behavior
setReadonlyFields() should also run on a record with set children.