Skip to content

Commit

Permalink
Fix Package-Id header name, use util for isPackagedEnvironment() (#670)
Browse files Browse the repository at this point in the history
* Fix Package-Id header name, use util for isPackagedEnvironment()

* docs todo

* Conditional fix
  • Loading branch information
mbianco-stripe authored Aug 16, 2022
1 parent b124b2b commit eaf31a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Auto-archived price metadata
- Prices which are not created directly from pricebooks (i.e. from order lines, or duplicated because of the one-price-per-subscription) are archived (active = false) after they are used
- Prices which are duplicated because of the one-price-per-subscription) have a special metadata key (salesforce_duplicate = true)
- Some good test clock docs https://groups.google.com/a/stripe.com/g/cloudflare/c/VjNW1Q4KD-0

Next:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public with sharing class Sentry_ExceptionFactoryTest {
System.assert(sentryExceptionFromString instanceof Sentry_Exception);
System.assert(basic instanceof BasicException);
System.assert(extended instanceof ExtendedException);
if(!String.isEmpty(constants.NAMESPACE_API)) {

if(utilities.isPackagedEnvironment()) {
System.assertEquals(constants.NAMESPACE + '.Sentry_ExceptionFactoryTest', ex.context.get('exceptionClass'));
} else {
System.assertEquals('Sentry_ExceptionFactoryTest', ex.context.get('exceptionClass'));
Expand Down
6 changes: 3 additions & 3 deletions sfdx/force-app/main/default/classes/test_setupAssistant.cls
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public with sharing class test_setupAssistant {
System.assertEquals(req.getHeader('Salesforce-Account-Id'), (String)constants.ORG_ID);
System.assertEquals(req.getHeader('Salesforce-Type'), String.valueOf(Sentry_Environment.getInstanceType()));
System.assertEquals(req.getHeader('Salesforce-Package-Namespace'), constants.NAMESPACE);
if(!String.isEmpty(constants.NAMESPACE_API)) {
if(utilities.isPackagedEnvironment()) {
System.assertEquals(req.getHeader('Package-Id'), (String)utilities.getPackageVersion());
}

Expand Down Expand Up @@ -580,8 +580,8 @@ public with sharing class test_setupAssistant {
System.assertEquals(req.getHeader('Salesforce-Account-Id'), (String)constants.ORG_ID);
System.assertEquals(req.getHeader('Salesforce-Type'), String.valueOf(Sentry_Environment.getInstanceType()));
System.assertEquals(req.getHeader('Salesforce-Package-Namespace'), constants.NAMESPACE);
if(!String.isEmpty(constants.NAMESPACE_API)) {
System.assertEquals(req.getHeader('Package-Id'), (String)utilities.getPackageVersion());
if(utilities.isPackagedEnvironment()) {
System.assertEquals(req.getHeader('Salesforce-Package-Id'), (String)utilities.getPackageVersion());
}
Stripe_Connection__c stripeConnectRec = Stripe_Connection__c.getOrgDefaults();

Expand Down
10 changes: 7 additions & 3 deletions sfdx/force-app/main/default/classes/utilities.cls
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
public with sharing class utilities {
public class SetupIsNotCompleteException extends Exception {}

public static Boolean isPackagedEnvironment() {
return !String.isEmpty(constants.NAMESPACE_API);
}

@AuraEnabled
public static String getPackageVersion() {
responseData rd = new responseData();

if(String.isEmpty(constants.NAMESPACE_API)) {
if(!isPackagedEnvironment()) {
rd.put('major', '0');
rd.put('minor', '0');
return rd.getJsonString();
Expand Down Expand Up @@ -263,8 +267,8 @@ public with sharing class utilities {
request.setHeader('Salesforce-Type', String.valueOf(Sentry_Environment.getInstanceType()));
request.setHeader('Salesforce-Package-Namespace', constants.NAMESPACE);

if(!String.isEmpty(constants.NAMESPACE_API)) {
request.setHeader('Package-Id', (String)getPackageVersion());
if(utilities.isPackagedEnvironment()) {
request.setHeader('Salesforce-Package-Id', (String)getPackageVersion());
}

/*
Expand Down

0 comments on commit eaf31a7

Please sign in to comment.