forcedotcom / Einstein-GPT-for-Developers

Einstein GPT For Developers
BSD 3-Clause "New" or "Revised" License
31 stars 8 forks source link

Test creation shouldn't include system.runas unless specified #82

Open albarivas opened 1 month ago

albarivas commented 1 month ago

Summary

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');
        }
    }

Steps to Reproduce

  1. Create the method specified
  2. Ask E4D to generate test

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

jonifazo commented 1 month ago

Hi @albarivas - Thank you for this feedback. We will pass it on to the AI Research team.