Skip to content

Commit

Permalink
feat(sentry_webhook): handle outreachConsent Sentry tag (#1606)
Browse files Browse the repository at this point in the history
* feat(sentry_webhook): handle `outreachConsent` Sentry tag

* Strict type check.
  • Loading branch information
sbruens authored Oct 4, 2024
1 parent 2f4b35f commit 91046e3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sentry_webhook/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Outline Sentry Webhook

The Outline Sentry webhook is a [Google Cloud Function](https://cloud.google.com/functions/) that receives a Sentry event and posts it to Salesforce.
The Outline Sentry webhook is a [Google Cloud Run functions](https://cloud.google.com/functions/) that receives a Sentry event and posts it to Salesforce.

## Requirements

Expand Down
15 changes: 15 additions & 0 deletions src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('postSentryEventToSalesforce', () => {
['build.number', '0.0.0-debug'],
['accessKeySource', 'test source'],
['unknown:tag', 'foo'],
['outreachConsent', 'True'],
],
};

Expand All @@ -116,8 +117,22 @@ describe('postSentryEventToSalesforce', () => {
'&00N5a00000DXxmo=MacOS' +
'&00N5a00000DXxmq=test%20version' +
'&00N5a00000DXy64=0.0.0-debug' +
'&00N5a00000DbyEw=true' +
'&00N5a00000DXxms=test%20source'
);
expect(mockRequest.end).toHaveBeenCalled();
});

it('drops "False" values for `outreachConsent`', () => {
const event: SentryEvent = {
user: {email: '[email protected]'},
message: 'my message',
tags: [['outreachConsent', 'False']],
};

postSentryEventToSalesforce(event, 'outline-clients');

expect(mockRequest.write.calls.argsFor(0)[0]).not.toContain('00N5a00000DbyEw');
expect(mockRequest.end).toHaveBeenCalled();
});
});
7 changes: 7 additions & 0 deletions src/sentry_webhook/post_sentry_event_to_salesforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface SalesforceFormFields {
build: string;
role: string;
isUpdatedForm: string;
outreachConsent: string;
}

// Defines the Salesforce form values.
Expand All @@ -57,6 +58,7 @@ const SALESFORCE_FORM_FIELDS_DEV: SalesforceFormFields = {
build: '00N75000000wmdC',
role: '00N75000000wYiX',
isUpdatedForm: '00N75000000wmd7',
outreachConsent: '',
};
const SALESFORCE_FORM_FIELDS_PROD: SalesforceFormFields = {
orgId: 'orgid',
Expand All @@ -73,6 +75,7 @@ const SALESFORCE_FORM_FIELDS_PROD: SalesforceFormFields = {
build: '00N5a00000DXy64',
role: '00N5a00000DXxmr',
isUpdatedForm: '00N5a00000DXy5a',
outreachConsent: '00N5a00000DbyEw',
};
const SALESFORCE_FORM_VALUES_DEV: SalesforceFormValues = {
orgId: '00D750000004dFg',
Expand Down Expand Up @@ -181,6 +184,10 @@ function getSalesforceFormData(
form.push(encodeFormData(formFields.os, toOSPicklistValue(tags.get('os.name'))));
form.push(encodeFormData(formFields.version, tags.get('sentry:release')));
form.push(encodeFormData(formFields.build, tags.get('build.number')));
const outreachConsent = (tags.get('outreachConsent') ?? 'False').toLowerCase();
if (outreachConsent === 'true') {
form.push(encodeFormData(formFields.outreachConsent, outreachConsent));
}
const formVersion = Number(tags.get('formVersion') ?? 1);
if (formVersion === 2) {
form.push(encodeFormData(formFields.isUpdatedForm, 'true'));
Expand Down

0 comments on commit 91046e3

Please sign in to comment.