Open albarivas opened 1 month ago
Asked E4D to create a test for:
@AuraEnabled(cacheable=true) public static Decimal getAveragePrice() { List<AggregateResult> price = [SELECT AVG(MSRP__c) avgPrice FROM Product__c]; return (Decimal)price[0].get('avgPrice'); }
And it came up with:
static void testAveragePrice() { System.runAs(new User(Id = UserInfo.getUserId())) { Test.startTest(); Decimal avgPrice = ProductController.getAveragePrice(); Test.stopTest(); List<Product__c> productList = [SELECT MSRP__c FROM Product__c]; Decimal expectedAveragePrice = productList[0].MSRP__c; for (Integer i = 1; i < productList.size(); i++) { expectedAveragePrice += productList[i].MSRP__c; } expectedAveragePrice = expectedAveragePrice / productList.size(); System.assertEquals(expectedAveragePrice, avgPrice, 'The average price should be calculated correctly'); } }
The one shared
It should not include system.runAs unless specified
Salesforce Extension Version in Code builder: 61.1.2
Salesforce Einstein For Developers Version in Code builder: 0.50.0
code-server: v4.18.0
Code: 1.83.1
Hi @albarivas - Thank you for this feedback. We will pass it on to the AI Research team.
Summary
Asked E4D to create a test for:
And it came up with:
Steps to Reproduce
Actual Result
The one shared
Expected result
It should not include system.runAs unless specified
Additional information
Salesforce Extension Version in Code builder: 61.1.2
Salesforce Einstein For Developers Version in Code builder: 0.50.0
code-server: v4.18.0
Code: 1.83.1