-
Notifications
You must be signed in to change notification settings - Fork 54
Stabilize tests #1450
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
Merged
Merged
Stabilize tests #1450
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
060e707
Use dependency injection in the Advertising component
carterworks 34cbec0
Use dependency injection in the makeSendServiceWorkerTrackingData fun…
carterworks 401e191
Add changeset
carterworks e81cf12
Update jsdoc comments for advertising component
carterworks aa46ad8
fix jsdoc comments
carterworks f2de2fa
unify dependency injection a bit
carterworks d59682b
Annotate testing code smells
carterworks b4b2960
Annotate more leaky patterns in tests
carterworks 518a614
Fix formatting & linting of test and script files
carterworks e2a80b4
Create and use a location helper for safe url modifications during tests
carterworks 1d4c798
Rewrite adConversionHandler tests
carterworks dfe4194
Remove dead mocks in advertising specs
carterworks 7151ba0
Make all module mocks docs compliant
carterworks dfc7de7
Use safer withTemporaryUrl function in some unit tests
carterworks c92fa64
Harden the mediaEvents integration tests
carterworks e4e6329
Fix viewThroughHandler mocks
carterworks 79ba414
Reset dom action nonces better in tests
carterworks de720ae
Remove location changing from advertising helper specs
carterworks 7e2f82b
Make serviceWorkerNotificationClickListener a default export
carterworks 71fecb9
Pass missing params into serviceWorkerPushListener
carterworks 1147d35
Fix jsdoc comment
carterworks e0cd653
Clean up event listeners
carterworks d831b02
Resolve other FIXME comments
carterworks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
packages/core/src/components/Advertising/handlers/createOnBeforeSendEventHandler.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /* | ||
| Copyright 2023 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { SURFER_ID, ID5_ID, RAMP_ID } from "../constants/index.js"; | ||
| import { AUTO, WAIT } from "../../../constants/consentStatus.js"; | ||
| import { CHROME } from "../../../constants/browser.js"; | ||
|
|
||
| const isAdvertisingDisabled = (advertising) => { | ||
| return ![AUTO, WAIT].includes( | ||
| advertising?.handleAdvertisingData?.toLowerCase(), | ||
| ); | ||
| }; | ||
|
|
||
| const waitForAdvertisingId = (advertising) => { | ||
| return advertising?.handleAdvertisingData?.toLowerCase() === WAIT; | ||
| }; | ||
|
|
||
| /** | ||
| * Creates an onBeforeSendEvent handler that appends advertising IDs to events. | ||
| * | ||
| * @param {Object} dependencies | ||
| * @param {Object} dependencies.cookieManager | ||
| * @param {Object} dependencies.logger | ||
| * @param {Object} dependencies.componentConfig | ||
| * @param {Function} dependencies.getBrowser | ||
| * @param {Object} dependencies.consent | ||
| * @param {Function} dependencies.collectSurferId | ||
| * @param {Function} dependencies.getID5Id | ||
| * @param {Function} dependencies.getRampId | ||
| * @param {Function} dependencies.appendAdvertisingIdQueryToEvent | ||
| * @param {Function} dependencies.getUrlParams | ||
| * @param {Function} dependencies.isThrottled | ||
| */ | ||
| export default ({ | ||
| cookieManager, | ||
| logger, | ||
| componentConfig, | ||
| getBrowser, | ||
| consent, | ||
| collectSurferId, | ||
| getID5Id, | ||
| getRampId, | ||
| appendAdvertisingIdQueryToEvent, | ||
| getUrlParams, | ||
| isThrottled, | ||
| }) => { | ||
| /** | ||
| * Appends advertising identity IDs to AEP event query if not already added. | ||
| * | ||
| * @param {Object} options | ||
| * @param {Object} options.event | ||
| * @param {Object} [options.advertising={}] | ||
| * @returns {Promise<void>} | ||
| */ | ||
| return async ({ event, advertising = {} }) => { | ||
| const { state } = consent.current(); | ||
| if (state !== "in") { | ||
| return; | ||
| } | ||
| const { skwcid, efid } = getUrlParams(); | ||
| const isClickThru = !!(skwcid && efid); | ||
| if ( | ||
| isAdvertisingDisabled(advertising) || | ||
| isClickThru || | ||
| (isThrottled(SURFER_ID, cookieManager) && | ||
| isThrottled(ID5_ID, cookieManager) && | ||
| isThrottled(RAMP_ID, cookieManager)) | ||
| ) | ||
| return; | ||
|
|
||
| try { | ||
| const useShortTimeout = waitForAdvertisingId(advertising); | ||
|
|
||
| let rampIdPromise = null; | ||
|
|
||
| if (!getBrowser || getBrowser() !== CHROME) { | ||
| rampIdPromise = getRampId( | ||
| logger, | ||
| componentConfig.rampIdJSPath, | ||
| cookieManager, | ||
| useShortTimeout, | ||
| useShortTimeout, | ||
| ); | ||
| } | ||
| const [surferIdResult, id5IdResult, rampIdResult] = | ||
| await Promise.allSettled([ | ||
| collectSurferId(cookieManager, getBrowser, useShortTimeout), | ||
| getID5Id( | ||
| logger, | ||
| componentConfig.id5PartnerId, | ||
| useShortTimeout, | ||
| useShortTimeout, | ||
| ), | ||
| rampIdPromise, | ||
| ]); | ||
|
|
||
| const availableIds = {}; | ||
| if ( | ||
| surferIdResult.status === "fulfilled" && | ||
| surferIdResult.value && | ||
| !isThrottled(SURFER_ID, cookieManager) | ||
| ) { | ||
| availableIds.surferId = surferIdResult.value; | ||
| } | ||
| if ( | ||
| id5IdResult.status === "fulfilled" && | ||
| id5IdResult.value && | ||
| !isThrottled(ID5_ID, cookieManager) | ||
| ) { | ||
| availableIds.id5Id = id5IdResult.value; | ||
| } | ||
| if ( | ||
| rampIdResult.status === "fulfilled" && | ||
| rampIdResult.value && | ||
| !isThrottled(RAMP_ID, cookieManager) | ||
| ) { | ||
| availableIds.rampId = rampIdResult.value; | ||
| } | ||
| // If no IDs are available and any ID is throttled, return , because we dont have new info to send | ||
| if ( | ||
| Object.keys(availableIds).length === 0 && | ||
| (isThrottled(SURFER_ID, cookieManager) || | ||
| isThrottled(ID5_ID, cookieManager) || | ||
| isThrottled(RAMP_ID, cookieManager)) | ||
| ) { | ||
| return; | ||
| } | ||
| appendAdvertisingIdQueryToEvent( | ||
| availableIds, | ||
| event, | ||
| cookieManager, | ||
| componentConfig, | ||
| ); | ||
| } catch (error) { | ||
| logger.error("Error in onBeforeSendEvent hook:", error); | ||
| } | ||
| }; | ||
| }; | ||
131 changes: 0 additions & 131 deletions
131
packages/core/src/components/Advertising/handlers/onBeforeSendEventHandler.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.