From baa7b01dc3a5789fb85d0e8772f4433b79cf120e Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Mon, 9 Oct 2023 13:03:10 -0400 Subject: [PATCH] feat(www): add a form field to distinguish new style form submissions in salesforce (#1748) * feat(www): add a form field to distinguish legacy from new submitted forms in sentry and salesforce * Add test for sending the values to error reporter. * Use a version instead of a boolean on the app side. --- src/www/shared/error_reporter.ts | 2 +- src/www/views/contact_view/index.spec.ts | 17 +++++++++++++++++ src/www/views/contact_view/index.ts | 5 ++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/www/shared/error_reporter.ts b/src/www/shared/error_reporter.ts index 60b84cf4a2..ffbb44c9e0 100644 --- a/src/www/shared/error_reporter.ts +++ b/src/www/shared/error_reporter.ts @@ -15,7 +15,7 @@ import * as Sentry from '@sentry/browser'; import {Integration as SentryIntegration} from '@sentry/types'; -export type Tags = {[id: string]: string}; +export type Tags = {[id: string]: string | boolean | number}; export interface OutlineErrorReporter { report(userFeedback: string, feedbackCategory: string, userEmail?: string, tags?: Tags): Promise; diff --git a/src/www/views/contact_view/index.spec.ts b/src/www/views/contact_view/index.spec.ts index 70bacf3098..6ad33017c8 100644 --- a/src/www/views/contact_view/index.spec.ts +++ b/src/www/views/contact_view/index.spec.ts @@ -145,6 +145,23 @@ describe('ContactView client variant', () => { expect(supportForm).not.toBeNull(); }); + it('reports correct values to error reporter on completion of support form', async () => { + const supportForm: SupportForm = el.shadowRoot!.querySelector('support-form')!; + supportForm.values.email = 'foo@bar.com'; + supportForm.values.subject = 'Test Subject'; + supportForm.values.accessKeySource = 'a friend'; + supportForm.values.description = 'Test Description'; + supportForm.valid = true; + supportForm.dispatchEvent(new CustomEvent('submit')); + await nextFrame(); + + expect(mockErrorReporter.report).toHaveBeenCalledWith('Test Description', 'general', 'foo@bar.com', { + subject: 'Test Subject', + accessKeySource: 'a friend', + formVersion: 2, + }); + }); + it('emits success event on completion of support form', async () => { const listener = oneEvent(el, 'success'); diff --git a/src/www/views/contact_view/index.ts b/src/www/views/contact_view/index.ts index 02e3037772..3298492557 100644 --- a/src/www/views/contact_view/index.ts +++ b/src/www/views/contact_view/index.ts @@ -177,7 +177,10 @@ export class ContactView extends LitElement { const {description, email, ...tags} = this.formValues as ValidFormValues; try { - await this.errorReporter.report(description, this.selectedIssueType?.toString() ?? 'unknown', email, {...tags}); + await this.errorReporter.report(description, this.selectedIssueType?.toString() ?? 'unknown', email, { + ...tags, + formVersion: 2, + }); } catch (e) { console.error(`Failed to send feedback report: ${e.message}`); this.isFormSubmitting = false;