Skip to content

Commit d8446c3

Browse files
ravishekharRavi Shekhar
andauthored
add new methods to get paypal session id (#243)
* add new methods for paypal session id * type error in tests --------- Co-authored-by: Ravi Shekhar <[email protected]>
1 parent 97d985d commit d8446c3

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/globalSession.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22

3+
// These methods should be cleaned up in favor of paypalSession
34
import { getStorage, type Storage } from "@krakenjs/belter/src";
45
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
56

src/paypalSession.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* @flow */
2+
3+
import { getStorage, type Storage } from "@krakenjs/belter/src";
4+
5+
const STORAGE_LIFETIME_1_HOUR = 60 * 60 * 1000;
6+
export function getPayPalSessionStorage(): Storage {
7+
return getStorage({
8+
name: "paypal",
9+
lifetime: STORAGE_LIFETIME_1_HOUR,
10+
});
11+
}
12+
13+
export function getPayPalStorageID(): string {
14+
return getPayPalSessionStorage().getID();
15+
}
16+
17+
export function getPayPalSessionID(): string {
18+
return getPayPalSessionStorage().getSessionID();
19+
}

src/paypalSession.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* @flow */
2+
import { afterEach, describe, it, vi } from "vitest";
3+
import { memoize } from "@krakenjs/belter/src";
4+
5+
import {
6+
getPayPalSessionID,
7+
getPayPalSessionStorage,
8+
getPayPalStorageID,
9+
} from "./paypalSession";
10+
11+
describe("payaplSession cases", () => {
12+
afterEach(() => {
13+
vi.clearAllMocks();
14+
memoize.clear();
15+
});
16+
17+
it("should getStorageState", () => {
18+
const result = getPayPalSessionStorage();
19+
20+
if (typeof result.getID() !== "string") {
21+
throw new TypeError(`should get storage state object instance`);
22+
}
23+
});
24+
25+
it("should getPayPalSessionID", () => {
26+
const id = getPayPalSessionID();
27+
28+
if (typeof id !== "string") {
29+
throw new TypeError(
30+
`should get the session id, but got ${JSON.stringify(id)}`
31+
);
32+
}
33+
34+
if (!id.startsWith("uid_")) {
35+
throw new TypeError(`session id should start with uid_ but got ${id}`);
36+
}
37+
});
38+
39+
it("should getPayPalStorageID", () => {
40+
const id = getPayPalStorageID();
41+
42+
if (typeof id !== "string") {
43+
throw new TypeError(
44+
`should get the storage id, but got ${JSON.stringify(id)}`
45+
);
46+
}
47+
48+
if (!id.startsWith("uid_")) {
49+
throw new TypeError(`storage id should start with uid_ but got ${id}`);
50+
}
51+
});
52+
});

0 commit comments

Comments
 (0)