116 lines
3.6 KiB
OpenEdge ABL
116 lines
3.6 KiB
OpenEdge ABL
@isTest
|
|
public with sharing class DeleteCustomerFromShopify_Test {
|
|
|
|
@testSetup
|
|
static void setupTestData() {
|
|
// Create configuration record
|
|
HIC_ShopifySync__HIC_Configuration__c config = new HIC_ShopifySync__HIC_Configuration__c(
|
|
Name = 'Test Config',
|
|
HIC_ShopifySync__Store__c = 'Default',
|
|
HIC_ShopifySync__Enable_Lead__c = true,
|
|
HIC_ShopifySync__Person_Account__c = true,
|
|
HIC_ShopifySync__Upsert_Lead_basis_on_Email__c = true
|
|
);
|
|
insert config;
|
|
|
|
// Create lead
|
|
Lead testLead = new Lead(
|
|
FirstName = 'Test',
|
|
LastName = 'Lead',
|
|
Company = 'Test Company',
|
|
HIC_ShopifySync__Shopify_id__c = '12345',
|
|
Status = 'Open - Not Contacted'
|
|
);
|
|
insert testLead;
|
|
|
|
// Create account
|
|
Account testAccount = new Account(
|
|
Name = 'Test Account',
|
|
HIC_ShopifySync__Shopify_id__c = 'Person 12345'
|
|
);
|
|
insert testAccount;
|
|
|
|
// Create contact
|
|
Contact testContact = new Contact(
|
|
LastName = 'Test Contact',
|
|
AccountId = testAccount.Id,
|
|
HIC_ShopifySync__Shopify_id__c = 'Business 12345'
|
|
);
|
|
insert testContact;
|
|
}
|
|
|
|
@isTest
|
|
static void testDeleteLead() {
|
|
Test.startTest();
|
|
|
|
// Prepare the request and response
|
|
RestRequest req = new RestRequest();
|
|
RestResponse res = new RestResponse();
|
|
|
|
req.requestBody = Blob.valueOf('{"id": "12345"}');
|
|
req.httpMethod = 'POST';
|
|
RestContext.request = req;
|
|
RestContext.response = res;
|
|
|
|
// Invoke the method
|
|
DeleteCustomerFromShopify.DeleteCustomer();
|
|
|
|
// Verify the lead is deleted
|
|
List<Lead> leads = [SELECT Id FROM Lead WHERE HIC_ShopifySync__Shopify_id__c = '12345'];
|
|
System.assertEquals(0, leads.size());
|
|
|
|
Test.stopTest();
|
|
}
|
|
|
|
@isTest
|
|
static void testDeleteAccountContact() {
|
|
Test.startTest();
|
|
|
|
// Prepare the request and response
|
|
RestRequest req = new RestRequest();
|
|
RestResponse res = new RestResponse();
|
|
|
|
req.requestBody = Blob.valueOf('{"id": "12345"}');
|
|
req.httpMethod = 'POST';
|
|
RestContext.request = req;
|
|
RestContext.response = res;
|
|
|
|
// Invoke the method
|
|
DeleteCustomerFromShopify.DeleteCustomer();
|
|
|
|
Test.stopTest();
|
|
}
|
|
|
|
@isTest
|
|
static void testmethod1() {
|
|
|
|
HIC_ShopifySync__HIC_Configuration__c config = [SELECT Name FROM HIC_ShopifySync__HIC_Configuration__c WHERE Name = 'Test Config'];
|
|
config.HIC_ShopifySync__Enable_Lead__c = false;
|
|
config.HIC_ShopifySync__Update_Identified_Lead_Records__c = false;
|
|
config.HIC_ShopifySync__Upsert_Lead_basis_on_Email__c = false;
|
|
config.HIC_ShopifySync__Person_Account__c = false;
|
|
update config;
|
|
|
|
Test.startTest();
|
|
|
|
// Prepare the request and response
|
|
RestRequest req = new RestRequest();
|
|
RestResponse res = new RestResponse();
|
|
|
|
req.requestBody = Blob.valueOf('{"id": "99999"}');
|
|
req.httpMethod = 'POST';
|
|
RestContext.request = req;
|
|
RestContext.response = res;
|
|
|
|
Account acc = new Account(name='DeleteCustomerFromShopify_Test');
|
|
acc.HIC_ShopifySync__Shopify_id__c = 'Business 99999';
|
|
insert acc;
|
|
|
|
// Invoke the method
|
|
DeleteCustomerFromShopify.DeleteCustomer();
|
|
|
|
// No DML operations should be performed since no config is found
|
|
Test.stopTest();
|
|
}
|
|
|
|
} |