Skip to content

Commit

Permalink
update the BT min Version, add patchVersion + update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai-Yen Nguyen committed Sep 20, 2024
1 parent 0c688c9 commit 5fdd7e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
22 changes: 18 additions & 4 deletions src/connect/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,34 @@ import {
import { FPTI_KEY } from "@paypal/sdk-constants";

const MIN_MAJOR_VERSION = 3;
const MIN_MINOR_VERSION = 97;
export const MIN_BT_VERSION = `${MIN_MAJOR_VERSION}.${MIN_MINOR_VERSION}.3-connect-alpha.6.1`; // Minimum for supporting AXO
const MIN_MINOR_VERSION = 107;
const MIN_PATCH_VERSION = 1;
export const MIN_BT_VERSION = `${MIN_MAJOR_VERSION}.${MIN_MINOR_VERSION}.${MIN_PATCH_VERSION}`; // Minimum for supporting AXO

export function getSdkVersion(version: string | null): string {
if (!version) {
return MIN_BT_VERSION;
}
const versionSplit = version.split(".");
// patch could have an alpha tag
const patchSplit = versionSplit[2].split("-");

const majorVersion = Number(versionSplit[0]);
const minorVersion = Number(versionSplit[1]);
const patchVersion = Number(patchSplit[0]);

const isMajorVersionSmaller = majorVersion < MIN_MAJOR_VERSION;
const isMajorVersionEqual = majorVersion === MIN_MAJOR_VERSION;

const isMinorVersionSmaller = minorVersion < MIN_MINOR_VERSION;
const isMinorVersionEqual = minorVersion === MIN_MINOR_VERSION;

const isPatchVersionSmaller = patchVersion < MIN_PATCH_VERSION;

if (
majorVersion < MIN_MAJOR_VERSION ||
(majorVersion === MIN_MAJOR_VERSION && minorVersion < MIN_MINOR_VERSION)
isMajorVersionSmaller ||
(isMajorVersionEqual && isMinorVersionSmaller) ||
(isMajorVersionEqual && isMinorVersionEqual && isPatchVersionSmaller)
) {
getLogger().metricCounter({
namespace: "connect.init.count",
Expand Down
21 changes: 12 additions & 9 deletions src/connect/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe("getConnectComponent: returns ConnectComponent", () => {
await getConnectComponent(mockProps);
expect(loadAxo).toHaveBeenCalledWith({
minified: true,
btSdkVersion: "3.97.3-connect-alpha.6.1",
btSdkVersion: "3.107.1",
metadata: undefined,
platform: "PPCP",
});
Expand All @@ -131,20 +131,23 @@ describe("getSdkVersion", () => {
expect(version).toEqual(MIN_BT_VERSION);
});
test("returns the version passed if it is supported for AXO", () => {
const result1 = getSdkVersion("3.97.00");
const result2 = getSdkVersion("3.97.alpha-test");
const result3 = getSdkVersion("4.34.beta-test");
const result1 = getSdkVersion("3.107.1");
const result2 = getSdkVersion("3.107.1-alpha-test");
const result3 = getSdkVersion("4.34.3-beta-test");
const result4 = getSdkVersion("4.34.47");
const result5 = getSdkVersion("3.108.0");

expect(result1).toEqual("3.97.00");
expect(result2).toEqual("3.97.alpha-test");
expect(result3).toEqual("4.34.beta-test");
expect(result1).toEqual("3.107.1");
expect(result2).toEqual("3.107.1-alpha-test");
expect(result3).toEqual("4.34.3-beta-test");
expect(result4).toEqual("4.34.47");
expect(result5).toEqual("3.108.0");
});

test("throws error if the version passed is not supported for AXO and is not null", () => {
expect(() => getSdkVersion("3.96.00")).toThrowError();
expect(() => getSdkVersion("2.87.alpha-test")).toThrowError();
expect(() => getSdkVersion("3.34.beta-test")).toThrowError();
expect(() => getSdkVersion("2.87.2-alpha-test")).toThrowError();
expect(() => getSdkVersion("3.34.1-beta-test")).toThrowError();
expect(() => getSdkVersion("3.107.0-alpha-test")).toThrowError();
});
});

0 comments on commit 5fdd7e6

Please sign in to comment.