Skip to content

Commit

Permalink
Set library value to none when there is no data-js-sdk-library attr
Browse files Browse the repository at this point in the history
  • Loading branch information
nbierdeman committed Mar 15, 2024
1 parent fc04d97 commit ff81409
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SDK_SETTINGS } from "@paypal/sdk-constants/src";

import { makeMockScriptElement } from "../test/helpers";

import { getJsLibrary } from "./tracking";
import {
getClientID,
getIntent,
Expand All @@ -17,7 +18,6 @@ import {
getMerchantID,
getClientAccessToken,
getSDKIntegrationSource,
getJsSdkLibrary,
getPageType,
getLocale,
getMerchantRequestedPopupsDisabled,
Expand Down Expand Up @@ -255,14 +255,22 @@ describe(`script cases`, () => {
expect(getSDKIntegrationSource()).toEqual(SDKIntegrationSource);
});

it("should return none when there is no js sdk library", () => {
const mockElement = makeMockScriptElement(mockScriptSrc);
// $FlowIgnore
getCurrentScript.mockReturnValue(mockElement);

expect(getJsLibrary()).toEqual("none");
});

it("should successfully get js sdk library", () => {
const jsSdkLibrary = "react-paypal-js";
const mockElement = makeMockScriptElement(mockScriptSrc);
mockElement.setAttribute(SDK_SETTINGS.JS_SDK_LIBRARY, jsSdkLibrary);
// $FlowIgnore
getCurrentScript.mockReturnValue(mockElement);

expect(getJsSdkLibrary()).toEqual(jsSdkLibrary);
expect(getJsLibrary()).toEqual(jsSdkLibrary);
});

it("should successfully get popup disabled attribute as true when set to true", () => {
Expand Down
12 changes: 11 additions & 1 deletion src/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ const getIntegrationSource = (): string => {
}
};

export const getJsLibrary = (): string => {
const jsSdkLibrary = getJsSdkLibrary();

if (jsSdkLibrary) {
return jsSdkLibrary;
} else {
return "none";
}
};

const getPageType = (): string => {
const pageType = getSDKPageType();

Expand All @@ -88,7 +98,7 @@ export function setupLogger() {
const logger = getLogger();
const pageType = getPageType();
const integrationSource = getIntegrationSource();
const jsSdkLibrary = getJsSdkLibrary();
const jsSdkLibrary = getJsLibrary();
const version = getVersion();
const userAction = getCommit()
? FPTI_USER_ACTION.COMMIT
Expand Down

0 comments on commit ff81409

Please sign in to comment.