mirror of
https://github.com/forcedotcom/afv-library.git
synced 2026-08-08 16:25:58 +08:00
fix: replace stub eval data with real adk-core datasets
Replace fabricated eval stubs with actual gold files and seed-data from adk-core: payment_overdue (formula field), AssetFedexValidationRule (validation rule with lookup deps), QueueableWithCalloutRecipes (Apex with class dependencies).
This commit is contained in:
parent
708e54e6ce
commit
e4a1676b01
@ -0,0 +1,20 @@
|
|||||||
|
public with sharing class RestClient {
|
||||||
|
public enum HttpVerb {
|
||||||
|
GET,
|
||||||
|
POST,
|
||||||
|
PUT,
|
||||||
|
PATCH,
|
||||||
|
DEL
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HttpResponse makeApiCall(
|
||||||
|
String namedCredential,
|
||||||
|
HttpVerb method,
|
||||||
|
String path
|
||||||
|
) {
|
||||||
|
HttpRequest request = new HttpRequest();
|
||||||
|
request.setEndpoint('callout:' + namedCredential + '/' + path);
|
||||||
|
request.setMethod(method.name());
|
||||||
|
return new Http().send(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,3 @@
|
|||||||
<!-- STUB — review and update expected output before running eval -->
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
<apiVersion>62.0</apiVersion>
|
<apiVersion>62.0</apiVersion>
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
@isTest
|
||||||
|
public class TestFactory {
|
||||||
|
public static List<SObject> invalidateSObjectList(List<SObject> records) {
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>62.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
Generate seed-data for an Apex dataset. The gold file is a QueueableWithCalloutRecipes class that implements Queueable and Database.AllowsCallouts. It references RestClient.makeApiCall() and TestFactory.invalidateSObjectList(). The dataset path is domains/apex/datasets/QueueableWithCalloutRecipes/. My target org is myDevOrg.
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* @description Demmonstrates the use of the Queueable interface to make
|
||||||
|
* callouts. The methods in this class are called by the system at run time.
|
||||||
|
* To enqueue this job and see it's results, use `System.enqueueJob(new QueueableWithCalloutRecipes());`
|
||||||
|
*
|
||||||
|
* More on the Queable interface:
|
||||||
|
* https://sfdc.co/queueable-apex
|
||||||
|
*
|
||||||
|
* @group Async Apex Recipes
|
||||||
|
* @see RestClient
|
||||||
|
*/
|
||||||
|
public with sharing class QueueableWithCalloutRecipes implements Queueable, Database.AllowsCallouts {
|
||||||
|
// This allows us to cause a DML failure in execute batch, enabling testing.
|
||||||
|
@testVisible
|
||||||
|
private static Boolean throwError = false;
|
||||||
|
@testVisible
|
||||||
|
private static Boolean circuitBreakerThrown = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Internal custom exception class
|
||||||
|
*/
|
||||||
|
public class QueueableWithCalloutRecipesException extends Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description This is the only required method to implement Queueable.
|
||||||
|
* Queueable classes that also implement Database.allowsCallouts can make
|
||||||
|
* HTTP requests to external services. In this recipe we make a GET request
|
||||||
|
* to developer.salesforce.com
|
||||||
|
* @param qc dependency injected by the system
|
||||||
|
* @example
|
||||||
|
* ```
|
||||||
|
* System.enqueueJob(new QueueableWithCalloutRecipes());
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public static void execute(QueueableContext qc) {
|
||||||
|
HttpResponse response = RestClient.makeApiCall(
|
||||||
|
'GoogleBooksAPI',
|
||||||
|
RestClient.HttpVerb.GET,
|
||||||
|
'volumes?q=salesforce'
|
||||||
|
);
|
||||||
|
List<Account> accounts = [
|
||||||
|
SELECT Id
|
||||||
|
FROM Account
|
||||||
|
ORDER BY Id
|
||||||
|
LIMIT 1000
|
||||||
|
];
|
||||||
|
for (Account acct : accounts) {
|
||||||
|
acct.Description = String.valueOf(response.getStatusCode());
|
||||||
|
}
|
||||||
|
if (Test.isRunningTest() && throwError) {
|
||||||
|
accounts = (List<Account>) TestFactory.invalidateSObjectList(
|
||||||
|
accounts
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
update accounts;
|
||||||
|
} catch (DmlException dmle) {
|
||||||
|
System.debug(
|
||||||
|
LoggingLevel.INFO,
|
||||||
|
'real life use cases should do something more than just logging the error: ' +
|
||||||
|
dmle.getMessage()
|
||||||
|
);
|
||||||
|
if (Test.isRunningTest()) {
|
||||||
|
QueueableWithCalloutRecipes.circuitBreakerThrown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +0,0 @@
|
|||||||
// STUB — review and update expected output before running eval
|
|
||||||
public abstract class BaseProcessor {
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
Generate seed-data for an Apex dataset where the gold file is an OrderProcessor class that extends BaseProcessor and implements Queueable. The dataset path is skills/generating-apex/tests/evals/generating-apex-order-processor/. My target org is myDevOrg.
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<!-- STUB — review and update expected output before running eval -->
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
|
|
||||||
<deploymentStatus>Deployed</deploymentStatus>
|
|
||||||
<label>Adoption</label>
|
|
||||||
<nameField>
|
|
||||||
<label>Adoption Name</label>
|
|
||||||
<type>Text</type>
|
|
||||||
</nameField>
|
|
||||||
<pluralLabel>Adoptions</pluralLabel>
|
|
||||||
<sharingModel>ReadWrite</sharingModel>
|
|
||||||
</CustomObject>
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<!-- STUB — review and update expected output before running eval -->
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
|
|
||||||
<deploymentStatus>Deployed</deploymentStatus>
|
|
||||||
<label>Animal</label>
|
|
||||||
<nameField>
|
|
||||||
<label>Animal Name</label>
|
|
||||||
<type>Text</type>
|
|
||||||
</nameField>
|
|
||||||
<pluralLabel>Animals</pluralLabel>
|
|
||||||
<sharingModel>ReadWrite</sharingModel>
|
|
||||||
</CustomObject>
|
|
||||||
@ -1 +0,0 @@
|
|||||||
I need seed-data stubs for a Flow dataset. The gold file is a record-triggered Flow on Adoption__c that creates a related record on Animal__c via a Lookup field. Target org is myDevOrg. The dataset is at skills/generating-flow/tests/evals/generating-flow-adoption-trigger/.
|
|
||||||
@ -1,4 +1,3 @@
|
|||||||
<!-- STUB — review and update expected output before running eval -->
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
<fullName>Payment_Due_Date__c</fullName>
|
<fullName>Payment_Due_Date__c</fullName>
|
||||||
|
|||||||
@ -1,15 +1,22 @@
|
|||||||
<!-- STUB — review and update expected output before running eval -->
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
<fullName>Payment_Status__c</fullName>
|
<fullName>Payment_Status__c</fullName>
|
||||||
<label>Payment Status</label>
|
<label>Payment Status</label>
|
||||||
<type>Picklist</type>
|
<type>Picklist</type>
|
||||||
<valueSet>
|
<valueSet>
|
||||||
|
<restricted>false</restricted>
|
||||||
<valueSetDefinition>
|
<valueSetDefinition>
|
||||||
|
<sorted>false</sorted>
|
||||||
<value>
|
<value>
|
||||||
<fullName>UNPAID</fullName>
|
<fullName>UNPAID</fullName>
|
||||||
|
<default>false</default>
|
||||||
<label>UNPAID</label>
|
<label>UNPAID</label>
|
||||||
</value>
|
</value>
|
||||||
|
<value>
|
||||||
|
<fullName>PAID</fullName>
|
||||||
|
<default>false</default>
|
||||||
|
<label>PAID</label>
|
||||||
|
</value>
|
||||||
</valueSetDefinition>
|
</valueSetDefinition>
|
||||||
</valueSet>
|
</valueSet>
|
||||||
</CustomField>
|
</CustomField>
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Generate seed-data for the dataset at skills/generating-validation-rule/tests/evals/generating-validation-rule-formula-deps/. The gold file is a validation rule on Contract that uses a formula referencing Payment_Due_Date__c and ISPICKVAL(Payment_Status__c, "UNPAID"). My target org is myDevOrg.
|
Generate seed-data for a CustomFormulaField dataset. The gold file is a formula field on Contract that checks if a payment is overdue — it references Payment_Due_Date__c and ISPICKVAL(Payment_Status__c, "UNPAID"). The dataset path is domains/CustomFormulaField/datasets/payment_overdue/. My target org is myDevOrg.
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<fullName>Payment_Overdue__c</fullName>
|
||||||
|
<label>Payment Overdue</label>
|
||||||
|
<type>Text</type>
|
||||||
|
<formula><![CDATA[IF(
|
||||||
|
AND(
|
||||||
|
Payment_Due_Date__c < TODAY(),
|
||||||
|
ISPICKVAL(Payment_Status__c, "UNPAID")
|
||||||
|
),
|
||||||
|
"PAYMENT OVERDUE",
|
||||||
|
null
|
||||||
|
)]]></formula>
|
||||||
|
<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
|
||||||
|
<description>Returns 'PAYMENT OVERDUE' when Payment_Due_Date__c is before today and Payment_Status__c is UNPAID; otherwise null.</description>
|
||||||
|
<trackHistory>false</trackHistory>
|
||||||
|
<trackTrending>false</trackTrending>
|
||||||
|
<required>false</required>
|
||||||
|
<externalId>false</externalId>
|
||||||
|
<unique>false</unique>
|
||||||
|
</CustomField>
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<fullName>AssetProvided__c</fullName>
|
||||||
|
<label>Asset Provided</label>
|
||||||
|
<referenceTo>Account</referenceTo>
|
||||||
|
<relationshipName>AssetProvided</relationshipName>
|
||||||
|
<type>Lookup</type>
|
||||||
|
</CustomField>
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<fullName>AssetServicedBy__c</fullName>
|
||||||
|
<label>Asset Serviced By</label>
|
||||||
|
<referenceTo>Account</referenceTo>
|
||||||
|
<relationshipName>AssetServicedBy</relationshipName>
|
||||||
|
<type>Lookup</type>
|
||||||
|
</CustomField>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
Generate seed-data for a ValidationRule dataset. The gold file is a validation rule on Asset that blocks insert/update when AssetProvided Name contains FedEx, AssetServicedBy Owner CompanyName contains FedEx, and Asset was modified within last 3 months. The dataset path is domains/ValidationRule/datasets/AssetFedexValidationRule/. My target org is myDevOrg.
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ValidationRule xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<fullName>AssetFedExValidation</fullName>
|
||||||
|
<active>true</active>
|
||||||
|
<description>Block insert/update if AssetProvided Name contains 'FedEx', AssetServicedBy Owner CompanyName contains 'FedEx', and Asset LastModified is not more than last 3 months</description>
|
||||||
|
<errorConditionFormula>
|
||||||
|
<![CDATA[AND(
|
||||||
|
/* Ensure lookups exist */
|
||||||
|
NOT(ISBLANK(AssetProvided__c)),
|
||||||
|
NOT(ISBLANK(AssetServicedBy__c)),
|
||||||
|
/* Name of AssetProvided contains FedEx (case-insensitive) */
|
||||||
|
CONTAINS( UPPER( AssetProvided__r.Name ), "FEDEX" ),
|
||||||
|
/* Owner CompanyName of AssetServicedBy contains FedEx (case-insensitive) */
|
||||||
|
CONTAINS( UPPER( AssetServicedBy__r.Owner.CompanyName ), "FEDEX" ),
|
||||||
|
/* Asset LastModified is within last 3 months (inclusive) */
|
||||||
|
DATEVALUE(LastModifiedDate) >= ADDMONTHS(TODAY(), -3)
|
||||||
|
)]]>
|
||||||
|
</errorConditionFormula>
|
||||||
|
<errorMessage>Cannot insert/update: Asset conditions not met.</errorMessage>
|
||||||
|
</ValidationRule>
|
||||||
Loading…
Reference in New Issue
Block a user