From 70b04a8163c28542b4b4b7db6181e72cc04c5631 Mon Sep 17 00:00:00 2001 From: Bianca Yang Date: Tue, 5 Dec 2023 13:06:24 -0800 Subject: [PATCH] feat: Test that 'survey sent' Event is Triggered when Submitting Non-Empty Unsubscribe Survey (#18805) * test that 'survey sent' event was triggered * remove unneeded config changes * update env vars, update test to check event payload * make capture url slightly stricter --------- Co-authored-by: Bianca Yang --- .github/workflows/ci-e2e.yml | 2 +- cypress/e2e/billingv2.cy.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml index ca6ad9d5dcfa0..85e6aa15fe043 100644 --- a/.github/workflows/ci-e2e.yml +++ b/.github/workflows/ci-e2e.yml @@ -184,7 +184,7 @@ jobs: DISABLE_SECURE_SSL_REDIRECT=1 SECURE_COOKIES=0 OPT_OUT_CAPTURE=0 - SELF_CAPTURE=0 + SELF_CAPTURE=1 E2E_TESTING=1 SKIP_SERVICE_VERSION_REQUIREMENTS=1 EMAIL_HOST=email.test.posthog.net diff --git a/cypress/e2e/billingv2.cy.ts b/cypress/e2e/billingv2.cy.ts index 5fa21e7b99d2f..7074aed771e42 100644 --- a/cypress/e2e/billingv2.cy.ts +++ b/cypress/e2e/billingv2.cy.ts @@ -1,8 +1,14 @@ +import * as fflate from 'fflate' + +const UNSUBSCRIBE_SURVEY_ID = '018b6e13-590c-0000-decb-c727a2b3f462' + describe('Billing', () => { beforeEach(() => { cy.intercept('/api/billing-v2/', { fixture: 'api/billing-v2/billing-v2.json' }) cy.visit('/organization/billing') + + cy.intercept('POST', '**/e/?compression=gzip-js*').as('capture') }) it('Show and submit unsubscribe survey', () => { @@ -19,6 +25,19 @@ describe('Billing', () => { cy.get('[data-attr=unsubscribe-reason-survey-textarea]').type('Product analytics') cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() + cy.wait('@capture').then(({ request }) => { + const data = new Uint8Array(request.body) + const decoded = fflate.strFromU8(fflate.decompressSync(data)) + const decodedJSON = JSON.parse(decoded) + + // These should be a 'survey sent' event somewhere in the decodedJSON + const matchingEvents = decodedJSON.filter((event) => event.event === 'survey sent') + expect(matchingEvents.length).to.equal(1) + const matchingEvent = matchingEvents[0] + expect(matchingEvent.properties.$survey_id).to.equal(UNSUBSCRIBE_SURVEY_ID) + expect(matchingEvent.properties.$survey_response).to.equal('Product analytics') + expect(matchingEvent.properties.$survey_response_1).to.equal('product_analytics') + }) cy.get('.LemonModal').should('not.exist') cy.wait(['@unsubscribeProductAnalytics']) })