Skip to content
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

update the BT min Version, add patchVersion + update unit test #2435

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/connect/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,35 @@ 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_PATCH_VERSION = 3;
export const MIN_BT_VERSION = `${MIN_MAJOR_VERSION}.${MIN_MINOR_VERSION}.${MIN_PATCH_VERSION}-connect-alpha.6.1`; // Minimum for supporting AXO

export const DEFAULT_BT_VERSION = `3.107.1`;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to validate the patch version? Is the fastlane team asking for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me and Nik thought it something good to have but we can remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the DEFAULT_BT_VERSION & MIN_BT_VERSION having patch versions greater that 0, it seemed like a valid check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only thing i'm worried about is accidentally marking current integrations as invalid. Technically, if this check is working correctly, then the merchant's integration wouldn't work anyway.

but i would check with the fastlane team to see if they have any dashboards we can watch while the SDK deploys

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current logic anything below 3.97.3 will throw an error, the previous logic would only throw an error for versions less than 3.97

It seems like the min version is on this specific version 3.97.3-connect-alpha.6.1
If a merchant was on 3.97.1, no error would be thrown, but I don't think that version would have the Fastlane changes?

Is that logic correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this will break anything, but i also don't think it's necessary.
just for context, the first official version of BT to support Fastlane is 3.104.0. before that, the only other versions with Fastlane were:
3.95.0-connect-alpha.12
3.97.3-connect-alpha.6.1
3.103.0-fastlane-beta.7.3


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
27 changes: 15 additions & 12 deletions src/connect/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { describe, expect, test, vi } from "vitest";
import {
getConnectComponent,
getSdkVersion,
MIN_BT_VERSION,
DEFAULT_BT_VERSION,
} from "./component";

vi.mock("@paypal/sdk-client/src", () => {
Expand Down Expand Up @@ -113,11 +113,11 @@ describe("getConnectComponent: returns ConnectComponent", () => {
);
});

test("minified is set according to debug value", async () => {
test("loadAxo is call with default values", async () => {
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 @@ -128,23 +128,26 @@ describe("getSdkVersion", () => {
test("returns minimum supported braintree version for AXO if input version is null", () => {
const version = getSdkVersion(null);

expect(version).toEqual(MIN_BT_VERSION);
expect(version).toEqual(DEFAULT_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 result2 = getSdkVersion("3.97.3-alpha-test");
const result3 = getSdkVersion("4.34.3-beta-test");
const result4 = getSdkVersion("4.34.47");
const result5 = getSdkVersion("3.98.3");
const result6 = getSdkVersion("3.97.6");

expect(result1).toEqual("3.97.00");
expect(result2).toEqual("3.97.alpha-test");
expect(result3).toEqual("4.34.beta-test");
expect(result2).toEqual("3.97.3-alpha-test");
expect(result3).toEqual("4.34.3-beta-test");
expect(result4).toEqual("4.34.47");
expect(result5).toEqual("3.98.3");
expect(result6).toEqual("3.97.6");
});

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("3.97.00")).toThrowError();
expect(() => getSdkVersion("2.87.1-alpha-test")).toThrowError();
expect(() => getSdkVersion("3.34.2-beta-test")).toThrowError();
});
});
Loading