Skip to content

Commit

Permalink
#967: Allow users to EXPORT configuration (#1095)
Browse files Browse the repository at this point in the history
* Config export/download

* Update how debugging is handled to be safe to not remove.

* Remove special exception error handling

* Updated code incorporating discussion feedback

* Update dialog text

* Fix test

* Incorporated review feedback

* Set debugger to false.

* Disable debug helper

---------

Co-authored-by: Nada Ismail <[email protected]>
  • Loading branch information
jmather-c and nadaismail-stripe authored Jul 10, 2023
1 parent 618b3a0 commit bf54279
Show file tree
Hide file tree
Showing 22 changed files with 1,031 additions and 420 deletions.
40 changes: 36 additions & 4 deletions sfdx/force-app/main/default/classes/ConfigExportVFCont_Test.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
/**
* temp empty until jmater-c's branch goes in
* Created by jmather-c on 5/1/23.
*/

@IsTest
public with sharing class ConfigExportVFCont_Test {
}
@IsTest
public with sharing class ConfigExportVFCont_Test {
@IsTest
static public void TestGetConfig() {
Setup_Connection_Data__mdt testSetupData = test_setupAssistant.getTestStripeConnectionKey();
test_setupAssistant.setTestGlobalKey(testSetupData);
test_setupAssistant.insertTestConnectedRecord();
Test.setMock(HttpCalloutMock.class, new test_setupAssistant.UnifiedConfigMock());
ConfigExportVFController controller = new ConfigExportVFController();

Test.startTest();
String response = controller.getConfig();
Map<String, Object> resultsMap = (Map<String, Object>)JSON.deserializeUntyped(response);
Test.stopTest();

Map<String, Object> allMappingConfigurations = (Map<String, Object>)resultsMap.get('allMappingConfigurations');
Map<String, Object> default_mappings = (Map<String, Object>)allMappingConfigurations.get('default_mappings');
Map<String, Object> field_defaults = (Map<String, Object>)allMappingConfigurations.get('field_defaults');
Map<String, Object> field_mappings = (Map<String, Object>)allMappingConfigurations.get('field_mappings');
Map<String, Object> required_mappings = (Map<String, Object>)allMappingConfigurations.get('required_mappings');

System.assertNotEquals(allMappingConfigurations, null);
System.assertEquals(default_mappings, null);
System.assertEquals(required_mappings, null);
System.assertNotEquals(field_defaults, null);
System.assertNotEquals(field_mappings, null);
System.assertEquals('2 days', (String)resultsMap.get('sync_record_retention'));
System.assertEquals('yesterday', (String)resultsMap.get('sync_start_date'));

System.assertEquals('testOrderFilter', (String)resultsMap.get('order_filter'));
System.assertEquals('testAccountFilter', (String)resultsMap.get('account_filter'));
System.assertEquals('testProduct2Filter', (String)resultsMap.get('product_filter'));
System.assertEquals('testPricebookEntryFilter', (String)resultsMap.get('pricebook_entry_filter'));
}
}
38 changes: 38 additions & 0 deletions sfdx/force-app/main/default/classes/ConfigExportVFController.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Created by jmather-c on 4/27/23.
*/

public with sharing class ConfigExportVFController {
ConfigPayloadHelper payloadHelper = new ConfigPayloadHelper();

public String getConfig() {
Stripe_Connection__c stripeConnectRec = Stripe_Connection__c.getOrgDefaults();
Boolean isConnected = utilities.isConnected(stripeConnectRec);
responseData rd = new responseData();

if (isConnected == false) {
rd.put('error', 'Unable to connect to remote system.');
return rd.getResultsJsonString();
}

try {
//construct call out to rubys configuration endpoint
String route = constants.RUBY_SERVICE_BASE_URI + '/v1/configuration';
HttpResponse response = utilities.makeCallout(route,'GET');

//if the call out is successful pull out all mapping objects and add to list
Map<String, Object> responseBody;
if(response.getStatusCode() == 200) {
responseBody = (Map<String,Object>)JSON.deserializeUntyped(response.getBody());
payloadHelper.extractSettingsData(responseBody, rd, false);
payloadHelper.extractFieldMappingData(responseBody, rd, false);
payloadHelper.extractFilterSettingsData(responseBody, rd);
} else {
errorLogger.create('getConfiguration', String.valueOf(response.getStatusCode()), (String)response.getStatus(), 'Failed to get mapping configuration from ruby service.');
}
} catch (Exception e) {
rd.addError(e);
}
return rd.getResultsJsonString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

0 comments on commit bf54279

Please sign in to comment.