Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sentry_webhook): update form fields #1433

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('postSentryEventToSalesforce', () => {
'orgid=00D750000004dFg' +
'&recordType=0123F000000MWTS' +
'&email=foo%40bar.com' +
'&00N3F000002Rqhq=' +
'&00N0b00000BqOA4=' +
'&description=my%20message' +
'&type=Outline%20client'
);
Expand All @@ -92,8 +92,10 @@ describe('postSentryEventToSalesforce', () => {
message: 'my message',
tags: [
['category', 'test category'],
['subject', 'test subject'],
['os.name', 'test os'],
['sentry:release', 'test version'],
['build.number', 'test build'],
['unknown:tag', 'foo'],
],
};
Expand All @@ -108,10 +110,25 @@ describe('postSentryEventToSalesforce', () => {
'&00N0b00000BqOA4=' +
'&description=my%20message' +
'&type=Outline%20client' +
'&00N5a00000DXy19=test%20category' +
'&00N5a00000DXxmo=test%20os' +
'&00N5a00000DXxmq=test%20version'
'&OC_Outline_Issue_v2__c=test%20category' +
'&subject=test%20subject' +
'&OC_Operating_System__c=test%20os' +
'&OC_Outline_Manager_Client_Version__c=test%20version' +
'&Build__c=test%20build' +
'&OC_Where_did_you_get_your_access_key__c='
);
expect(mockRequest.end).toHaveBeenCalled();
});

it('sets the correct form version tag', () => {
const event: SentryEvent = {
user: {email: '[email protected]'},
message: 'my message',
tags: [['formVersion', '2']],
};

postSentryEventToSalesforce(event, 'outline-clients');

expect(mockRequest.write.calls.argsFor(0)[0]).toContain('&Updated_App_Contact_Form__c=true');
});
});
43 changes: 23 additions & 20 deletions src/sentry_webhook/post_sentry_event_to_salesforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ interface SalesforceFormFields {
orgId: string;
recordType: string;
email: string;
subject: string;
description: string;
category: string;
accessKeySource: string;
cloudProvider: string;
sentryEventUrl: string;
os: string;
version: string;
build: string;
type: string;
isUpdatedForm: string;
}

// Defines the Salesforce form values.
Expand All @@ -38,29 +42,21 @@ interface SalesforceFormValues {
const SALESFORCE_DEV_HOST = 'google-jigsaw--jigsawuat.sandbox.my.salesforce.com';
const SALESFORCE_PROD_HOST = 'webto.salesforce.com';
const SALESFORCE_PATH = '/servlet/servlet.WebToCase';
const SALESFORCE_FORM_FIELDS_DEV: SalesforceFormFields = {
const SALESFORCE_FORM_FIELDS: SalesforceFormFields = {
orgId: 'orgid',
recordType: 'recordType',
email: 'email',
subject: 'subject',
description: 'description',
category: '00N3F000002Rqho',
cloudProvider: '00N3F000002Rqhs',
sentryEventUrl: '00N3F000002Rqhq',
os: '00N3F000002cLcN',
version: '00N3F000002cLcI',
type: 'type',
};
const SALESFORCE_FORM_FIELDS_PROD: SalesforceFormFields = {
orgId: 'orgid',
recordType: 'recordType',
email: 'email',
description: 'description',
category: '00N5a00000DXy19',
cloudProvider: '00N5a00000DXxmn',
category: 'OC_Outline_Issue_v2__c',
accessKeySource: 'OC_Where_did_you_get_your_access_key__c',
cloudProvider: 'OC_Cloud_Provider__c',
sentryEventUrl: '00N0b00000BqOA4',
os: '00N5a00000DXxmo',
version: '00N5a00000DXxmq',
os: 'OC_Operating_System__c',
version: 'OC_Outline_Manager_Client_Version__c',
build: 'Build__c',
type: 'type',
isUpdatedForm: 'Updated_App_Contact_Form__c',
};
const SALESFORCE_FORM_VALUES_DEV: SalesforceFormValues = {
orgId: '00D750000004dFg',
Expand All @@ -84,11 +80,10 @@ export function postSentryEventToSalesforce(event: SentryEvent, project: string)
// Sentry development projects are marked with 'dev', i.e. outline-client-dev.
const isProd = project.indexOf('-dev') === -1;
const salesforceHost = isProd ? SALESFORCE_PROD_HOST : SALESFORCE_DEV_HOST;
const formFields = isProd ? SALESFORCE_FORM_FIELDS_PROD : SALESFORCE_FORM_FIELDS_DEV;
const formValues = isProd ? SALESFORCE_FORM_VALUES_PROD : SALESFORCE_FORM_VALUES_DEV;
const isClient = project.indexOf('client') !== -1;
const formData = getSalesforceFormData(
formFields,
SALESFORCE_FORM_FIELDS,
formValues,
event,
event.user!.email!,
Expand Down Expand Up @@ -141,9 +136,17 @@ function getSalesforceFormData(
if (event.tags) {
const tags = new Map<string, string>(event.tags);
form.push(encodeFormData(formFields.category, tags.get('category')));
form.push(encodeFormData(formFields.subject, tags.get('subject')));
form.push(encodeFormData(formFields.os, tags.get('os.name')));
form.push(encodeFormData(formFields.version, tags.get('sentry:release')));
if (!isClient) {
form.push(encodeFormData(formFields.build, tags.get('build.number')));
const formVersion = Number(tags.get('formVersion') ?? 1);
if (formVersion === 2) {
form.push(encodeFormData(formFields.isUpdatedForm, 'true'));
}
if (isClient) {
form.push(encodeFormData(formFields.accessKeySource, tags.get('accessKeySource')));
} else {
form.push(encodeFormData(formFields.cloudProvider, tags.get('cloudProvider')));
}
}
Expand Down
Loading