From 89c2929b3f48c8cc6daf50d0a76e85926a1781ce Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Wed, 6 Sep 2023 17:20:41 -0500 Subject: [PATCH] wip --- .../package.json | 1 + .../public/onetrust.html | 4 +-- .../consent-tools-vanilla/index.ts | 2 +- .../src/page-objects/base-page.ts | 36 +++++++++++++++++++ .../src/tests/consent-tools-vanilla.test.ts | 2 -- yarn.lock | 1 + 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/packages/consent/consent-tools-integration-tests/package.json b/packages/consent/consent-tools-integration-tests/package.json index d67ff3cd8..9d87c7da8 100644 --- a/packages/consent/consent-tools-integration-tests/package.json +++ b/packages/consent/consent-tools-integration-tests/package.json @@ -17,6 +17,7 @@ "hoistingLimits": "workspaces" }, "devDependencies": { + "@internal/test-helpers": "workspace:^", "@segment/analytics-consent-tools": "workspace:^", "@segment/analytics-consent-wrapper-onetrust": "workspace:^", "@segment/analytics-next": "workspace:^", diff --git a/packages/consent/consent-tools-integration-tests/public/onetrust.html b/packages/consent/consent-tools-integration-tests/public/onetrust.html index b945a8338..fcbb6af39 100644 --- a/packages/consent/consent-tools-integration-tests/public/onetrust.html +++ b/packages/consent/consent-tools-integration-tests/public/onetrust.html @@ -61,10 +61,10 @@ n.parentNode.insertBefore(t, n) analytics._loadOptions = e } - analytics._writeKey = '9lSrez3BlfLAJ7NOChrqWtILiATiycoc' + analytics._writeKey = 'foo' analytics.SNIPPET_VERSION = '4.15.3' - withOneTrust(analytics).load('9lSrez3BlfLAJ7NOChrqWtILiATiycoc') // modified + withOneTrust(analytics).load('foo') // modified analytics.page() } })() diff --git a/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts b/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts index 8feca96aa..7bf5e0a3d 100644 --- a/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts +++ b/packages/consent/consent-tools-integration-tests/src/page-bundles/consent-tools-vanilla/index.ts @@ -20,5 +20,5 @@ export const analytics = new AnalyticsBrowser() wrap(analytics) analytics.load({ - writeKey: '9lSrez3BlfLAJ7NOChrqWtILiATiycoc', + writeKey: 'foo', }) diff --git a/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts b/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts index eecad1dbb..a5209786d 100644 --- a/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts +++ b/packages/consent/consent-tools-integration-tests/src/page-objects/base-page.ts @@ -1,3 +1,4 @@ +import { CDNSettingsBuilder } from '@internal/test-helpers' import assert from 'assert' const waitUntilReady = () => @@ -16,6 +17,7 @@ export abstract class BasePage { assert(baseURL) await waitUntilReady() await browser.url(baseURL + '/' + this.page) + await this.mockCDNSettingsEndpoint() } async clearStorage() { @@ -23,6 +25,40 @@ export abstract class BasePage { await browser.execute(() => localStorage.clear()) } + /** + * Mock the CDN Settings endpoint so that this can run offline + */ + private mockCDNSettingsEndpoint() { + const createConsentSettings = (categories: string[] = []) => ({ + consentSettings: { + categories, + }, + }) + browser + .mock('https://cdn.segment.com/v1/projects/**/settings') + .then((mock) => + mock.respond( + new CDNSettingsBuilder({ writeKey: 'something' }) + .addActionDestinationSettings({ + creationName: 'FullStory', + ...createConsentSettings(['Analytics']), + }) + .addActionDestinationSettings({ + creationName: 'Actions Amplitude', + ...createConsentSettings(['Advertising']), + }) + .build(), + { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + }, + } + ) + ) + .catch(console.error) + } + /** * Hard reload the page */ diff --git a/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts b/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts index 5fe348f8d..7ff94a78d 100644 --- a/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts +++ b/packages/consent/consent-tools-integration-tests/src/tests/consent-tools-vanilla.test.ts @@ -3,10 +3,8 @@ import { expect } from 'expect' import { Context } from '@segment/analytics-next' // Verify that the consent tools wrapper is working as expected (no OneTrust) - it('should stamp each event', async () => { await page.load() - const commands = [ `analytics.track("hello world")`, `analytics.alias("foo", "bar")`, diff --git a/yarn.lock b/yarn.lock index d24e9f27b..c45f8b0dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2359,6 +2359,7 @@ __metadata: version: 0.0.0-use.local resolution: "@internal/consent-tools-integration-tests@workspace:packages/consent/consent-tools-integration-tests" dependencies: + "@internal/test-helpers": "workspace:^" "@segment/analytics-consent-tools": "workspace:^" "@segment/analytics-consent-wrapper-onetrust": "workspace:^" "@segment/analytics-next": "workspace:^"