b2b-commerce-on-lightning-quickstart icon indicating copy to clipboard operation
b2b-commerce-on-lightning-quickstart copied to clipboard

Provide Apex unit tests for the Apex used by the LWC reference components

Open peterTrifecta opened this issue 4 years ago • 1 comments

Currently https://github.com/forcedotcom/b2b-commerce-on-lightning-quickstart/tree/master/examples/lwc/force-app/main/default/classes has no unit tests.

With the recommended pattern being to copy the reference component code as a starting point when customization is needed, it would be useful for the Apex unit tests to be included as a starting point to be copied.

peterTrifecta avatar Jan 27 '21 12:01 peterTrifecta

This is really needed. Without it, I think that the reference implementation will lead to developers implementing fragile, unreliable unit tests. The ConnectApi methods are not callable in unit tests. If unit test code attempts to call them an error: "System.UnsupportedOperationException: ConnectApi methods are not supported in data siloed tests. Please use @IsTest(SeeAllData=true)." is generated. Using SeeAllData=true is not a good practice, since code should definitely not rely on specific products, categories, etc., existing in an org. Therefore, a pattern that uses mocks is necessary or some other work around that does not rely on SeeAllData=true.

This is going to lead to developers just relying on SeeAllData=true (that's what the error message tells them to do), making their unit tests fragile and leaving customers with a situation where if they change certain data in their org it will break the unit tests that were written for them, preventing the customers from deploying.

peterTrifecta avatar Feb 09 '21 13:02 peterTrifecta