@tonder.io/ionic-lite-sdk 0.0.42-beta.1 → 0.0.42-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +28 -28
- package/README.md +532 -532
- package/dist/classes/BaseInlineCheckout.d.ts +1 -1
- package/dist/classes/liteCheckout.d.ts +1 -1
- package/dist/data/cardApi.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/types/liteInlineCheckout.d.ts +1 -1
- package/jest.config.ts +14 -14
- package/package.json +41 -41
- package/rollup.config.js +16 -16
- package/src/classes/3dsHandler.ts +347 -347
- package/src/classes/BaseInlineCheckout.ts +424 -424
- package/src/classes/errorResponse.ts +16 -16
- package/src/classes/liteCheckout.ts +589 -591
- package/src/data/api.ts +20 -20
- package/src/data/businessApi.ts +18 -18
- package/src/data/cardApi.ts +91 -87
- package/src/data/checkoutApi.ts +84 -84
- package/src/data/customerApi.ts +31 -31
- package/src/data/openPayApi.ts +12 -12
- package/src/data/paymentMethodApi.ts +37 -37
- package/src/data/skyflowApi.ts +20 -20
- package/src/helpers/constants.ts +63 -63
- package/src/helpers/mercadopago.ts +15 -15
- package/src/helpers/skyflow.ts +91 -91
- package/src/helpers/utils.ts +120 -120
- package/src/helpers/validations.ts +55 -55
- package/src/index.ts +12 -12
- package/src/shared/catalog/paymentMethodsCatalog.ts +247 -247
- package/src/shared/constants/messages.ts +10 -10
- package/src/shared/constants/paymentMethodAPM.ts +63 -63
- package/src/shared/constants/tonderUrl.ts +8 -8
- package/src/types/card.ts +35 -35
- package/src/types/checkout.ts +123 -123
- package/src/types/commons.ts +143 -143
- package/src/types/customer.ts +22 -22
- package/src/types/liteInlineCheckout.ts +216 -216
- package/src/types/paymentMethod.ts +23 -23
- package/src/types/requests.ts +114 -114
- package/src/types/responses.ts +192 -192
- package/src/types/skyflow.ts +17 -17
- package/src/types/transaction.ts +101 -101
- package/src/types/validations.d.ts +11 -11
- package/tests/classes/liteCheckout.test.ts +57 -57
- package/tests/methods/createOrder.test.ts +141 -141
- package/tests/methods/createPayment.test.ts +121 -121
- package/tests/methods/customerRegister.test.ts +118 -118
- package/tests/methods/getBusiness.test.ts +114 -114
- package/tests/methods/getCustomerCards.test.ts +112 -112
- package/tests/methods/registerCustomerCard.test.ts +117 -117
- package/tests/methods/startCheckoutRouter.test.ts +119 -119
- package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
- package/tests/utils/defaultMock.ts +21 -21
- package/tests/utils/mockClasses.ts +659 -659
- package/tsconfig.json +18 -18
package/src/types/transaction.ts
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
export interface ITransaction {
|
|
2
|
-
id: number;
|
|
3
|
-
provider: string;
|
|
4
|
-
country: string;
|
|
5
|
-
currency_code: string;
|
|
6
|
-
transaction_status: string;
|
|
7
|
-
created: string;
|
|
8
|
-
modified: string;
|
|
9
|
-
operation_date: string;
|
|
10
|
-
transaction_reference: string;
|
|
11
|
-
transaction_type: string;
|
|
12
|
-
status: string;
|
|
13
|
-
amount: string;
|
|
14
|
-
related_transaction_reference?: null | string;
|
|
15
|
-
reason?: null | string;
|
|
16
|
-
is_refunded?: null | boolean;
|
|
17
|
-
is_disputed?: null | boolean;
|
|
18
|
-
number_of_payment_attempts: number;
|
|
19
|
-
card_brand?: null | string;
|
|
20
|
-
number_of_installments: number;
|
|
21
|
-
payment?: {
|
|
22
|
-
id: number;
|
|
23
|
-
created: string;
|
|
24
|
-
modified: string;
|
|
25
|
-
amount: string;
|
|
26
|
-
status: string;
|
|
27
|
-
date: string;
|
|
28
|
-
paid_date: null | string;
|
|
29
|
-
source: null | string;
|
|
30
|
-
customer_order_reference: null | string;
|
|
31
|
-
client: number;
|
|
32
|
-
business: number;
|
|
33
|
-
shipping_address?: null | string;
|
|
34
|
-
billing_address?: null | string;
|
|
35
|
-
order: number;
|
|
36
|
-
};
|
|
37
|
-
checkout: {
|
|
38
|
-
id: string;
|
|
39
|
-
created: string;
|
|
40
|
-
modified: string;
|
|
41
|
-
checkout_data: {
|
|
42
|
-
name: string;
|
|
43
|
-
amount: number;
|
|
44
|
-
source: string;
|
|
45
|
-
id_ship: string;
|
|
46
|
-
currency: string;
|
|
47
|
-
order_id: number;
|
|
48
|
-
token_id: string;
|
|
49
|
-
last_name: string;
|
|
50
|
-
id_product: string;
|
|
51
|
-
ip_address: string;
|
|
52
|
-
payment_id: number;
|
|
53
|
-
return_url: string;
|
|
54
|
-
title_ship: string;
|
|
55
|
-
business_id: number;
|
|
56
|
-
checkout_id: string;
|
|
57
|
-
description: string;
|
|
58
|
-
browser_info: {
|
|
59
|
-
language: string;
|
|
60
|
-
time_zone: number;
|
|
61
|
-
user_agent: string;
|
|
62
|
-
color_depth: number;
|
|
63
|
-
screen_width: number;
|
|
64
|
-
screen_height: number;
|
|
65
|
-
javascript_enabled: boolean;
|
|
66
|
-
};
|
|
67
|
-
email_client: string;
|
|
68
|
-
phone_number: string;
|
|
69
|
-
instance_id_ship: string;
|
|
70
|
-
quantity_product: number;
|
|
71
|
-
device_session_id: null | string;
|
|
72
|
-
number_of_payment_attempts: number;
|
|
73
|
-
};
|
|
74
|
-
number_of_payment_attempts: number;
|
|
75
|
-
tried_psps: string[];
|
|
76
|
-
rejected_transactions: string[];
|
|
77
|
-
routing_step: number;
|
|
78
|
-
route_length: number;
|
|
79
|
-
last_status: string;
|
|
80
|
-
ip_address: string;
|
|
81
|
-
is_dynamic_routing: boolean;
|
|
82
|
-
is_route_finished: boolean;
|
|
83
|
-
business: number;
|
|
84
|
-
payment: number;
|
|
85
|
-
};
|
|
86
|
-
currency: {
|
|
87
|
-
id: number;
|
|
88
|
-
name: string;
|
|
89
|
-
code: string;
|
|
90
|
-
symbol: string;
|
|
91
|
-
country: null | string;
|
|
92
|
-
};
|
|
93
|
-
payment_method?: null | {
|
|
94
|
-
id: number;
|
|
95
|
-
name: string;
|
|
96
|
-
display_name: string;
|
|
97
|
-
category: string;
|
|
98
|
-
is_apm: boolean;
|
|
99
|
-
};
|
|
100
|
-
issuing_country?: null | string;
|
|
101
|
-
}
|
|
1
|
+
export interface ITransaction {
|
|
2
|
+
id: number;
|
|
3
|
+
provider: string;
|
|
4
|
+
country: string;
|
|
5
|
+
currency_code: string;
|
|
6
|
+
transaction_status: string;
|
|
7
|
+
created: string;
|
|
8
|
+
modified: string;
|
|
9
|
+
operation_date: string;
|
|
10
|
+
transaction_reference: string;
|
|
11
|
+
transaction_type: string;
|
|
12
|
+
status: string;
|
|
13
|
+
amount: string;
|
|
14
|
+
related_transaction_reference?: null | string;
|
|
15
|
+
reason?: null | string;
|
|
16
|
+
is_refunded?: null | boolean;
|
|
17
|
+
is_disputed?: null | boolean;
|
|
18
|
+
number_of_payment_attempts: number;
|
|
19
|
+
card_brand?: null | string;
|
|
20
|
+
number_of_installments: number;
|
|
21
|
+
payment?: {
|
|
22
|
+
id: number;
|
|
23
|
+
created: string;
|
|
24
|
+
modified: string;
|
|
25
|
+
amount: string;
|
|
26
|
+
status: string;
|
|
27
|
+
date: string;
|
|
28
|
+
paid_date: null | string;
|
|
29
|
+
source: null | string;
|
|
30
|
+
customer_order_reference: null | string;
|
|
31
|
+
client: number;
|
|
32
|
+
business: number;
|
|
33
|
+
shipping_address?: null | string;
|
|
34
|
+
billing_address?: null | string;
|
|
35
|
+
order: number;
|
|
36
|
+
};
|
|
37
|
+
checkout: {
|
|
38
|
+
id: string;
|
|
39
|
+
created: string;
|
|
40
|
+
modified: string;
|
|
41
|
+
checkout_data: {
|
|
42
|
+
name: string;
|
|
43
|
+
amount: number;
|
|
44
|
+
source: string;
|
|
45
|
+
id_ship: string;
|
|
46
|
+
currency: string;
|
|
47
|
+
order_id: number;
|
|
48
|
+
token_id: string;
|
|
49
|
+
last_name: string;
|
|
50
|
+
id_product: string;
|
|
51
|
+
ip_address: string;
|
|
52
|
+
payment_id: number;
|
|
53
|
+
return_url: string;
|
|
54
|
+
title_ship: string;
|
|
55
|
+
business_id: number;
|
|
56
|
+
checkout_id: string;
|
|
57
|
+
description: string;
|
|
58
|
+
browser_info: {
|
|
59
|
+
language: string;
|
|
60
|
+
time_zone: number;
|
|
61
|
+
user_agent: string;
|
|
62
|
+
color_depth: number;
|
|
63
|
+
screen_width: number;
|
|
64
|
+
screen_height: number;
|
|
65
|
+
javascript_enabled: boolean;
|
|
66
|
+
};
|
|
67
|
+
email_client: string;
|
|
68
|
+
phone_number: string;
|
|
69
|
+
instance_id_ship: string;
|
|
70
|
+
quantity_product: number;
|
|
71
|
+
device_session_id: null | string;
|
|
72
|
+
number_of_payment_attempts: number;
|
|
73
|
+
};
|
|
74
|
+
number_of_payment_attempts: number;
|
|
75
|
+
tried_psps: string[];
|
|
76
|
+
rejected_transactions: string[];
|
|
77
|
+
routing_step: number;
|
|
78
|
+
route_length: number;
|
|
79
|
+
last_status: string;
|
|
80
|
+
ip_address: string;
|
|
81
|
+
is_dynamic_routing: boolean;
|
|
82
|
+
is_route_finished: boolean;
|
|
83
|
+
business: number;
|
|
84
|
+
payment: number;
|
|
85
|
+
};
|
|
86
|
+
currency: {
|
|
87
|
+
id: number;
|
|
88
|
+
name: string;
|
|
89
|
+
code: string;
|
|
90
|
+
symbol: string;
|
|
91
|
+
country: null | string;
|
|
92
|
+
};
|
|
93
|
+
payment_method?: null | {
|
|
94
|
+
id: number;
|
|
95
|
+
name: string;
|
|
96
|
+
display_name: string;
|
|
97
|
+
category: string;
|
|
98
|
+
is_apm: boolean;
|
|
99
|
+
};
|
|
100
|
+
issuing_country?: null | string;
|
|
101
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare function validateCardNumber(cardNumber: string): boolean;
|
|
2
|
-
|
|
3
|
-
export declare function validateCardholderName(name: string): boolean;
|
|
4
|
-
|
|
5
|
-
export declare function validateCVV(cvv: string): boolean;
|
|
6
|
-
|
|
7
|
-
export declare function validateExpirationMonth(month: string): boolean;
|
|
8
|
-
|
|
9
|
-
export declare function validateExpirationYear(year: string): boolean;
|
|
10
|
-
|
|
11
|
-
export declare function validateExpirationDateParts(month: string, year: string): boolean;
|
|
1
|
+
export declare function validateCardNumber(cardNumber: string): boolean;
|
|
2
|
+
|
|
3
|
+
export declare function validateCardholderName(name: string): boolean;
|
|
4
|
+
|
|
5
|
+
export declare function validateCVV(cvv: string): boolean;
|
|
6
|
+
|
|
7
|
+
export declare function validateExpirationMonth(month: string): boolean;
|
|
8
|
+
|
|
9
|
+
export declare function validateExpirationYear(year: string): boolean;
|
|
10
|
+
|
|
11
|
+
export declare function validateExpirationDateParts(month: string, year: string): boolean;
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import "../utils/defaultMock";
|
|
2
|
-
import { LiteCheckout } from "../../src";
|
|
3
|
-
import { constructorFields } from "../utils/defaultMock";
|
|
4
|
-
import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
interface Window {
|
|
8
|
-
OpenPay: any;
|
|
9
|
-
Skyflow: any;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe("LiteCheckout", () => {
|
|
14
|
-
let checkoutConstructor: IInlineLiteCheckoutOptions,
|
|
15
|
-
liteCheckout: LiteCheckout,
|
|
16
|
-
fetchSpy: jest.SpyInstance,
|
|
17
|
-
liteCheckoutSpy: jest.SpyInstance;
|
|
18
|
-
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
window.fetch = jest.fn();
|
|
21
|
-
|
|
22
|
-
checkoutConstructor = {
|
|
23
|
-
...constructorFields,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
liteCheckout = new LiteCheckout(constructorFields);
|
|
27
|
-
|
|
28
|
-
fetchSpy = jest.spyOn(global, "fetch");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
jest.restoreAllMocks();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("Has required properties", () => {
|
|
36
|
-
expect(checkoutConstructor).toEqual(constructorFields);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("Can instance LiteCheckout", () => {
|
|
40
|
-
expect(liteCheckout).toBeInstanceOf(LiteCheckout);
|
|
41
|
-
expect(liteCheckout.apiKeyTonder).toEqual(constructorFields.apiKey);
|
|
42
|
-
expect(liteCheckout.baseUrl).toEqual(constructorFields.baseUrl);
|
|
43
|
-
expect(liteCheckout.abortController.signal).toEqual(constructorFields.signal);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
1
|
+
import "../utils/defaultMock";
|
|
2
|
+
import { LiteCheckout } from "../../src";
|
|
3
|
+
import { constructorFields } from "../utils/defaultMock";
|
|
4
|
+
import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
OpenPay: any;
|
|
9
|
+
Skyflow: any;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("LiteCheckout", () => {
|
|
14
|
+
let checkoutConstructor: IInlineLiteCheckoutOptions,
|
|
15
|
+
liteCheckout: LiteCheckout,
|
|
16
|
+
fetchSpy: jest.SpyInstance,
|
|
17
|
+
liteCheckoutSpy: jest.SpyInstance;
|
|
18
|
+
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
window.fetch = jest.fn();
|
|
21
|
+
|
|
22
|
+
checkoutConstructor = {
|
|
23
|
+
...constructorFields,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
liteCheckout = new LiteCheckout(constructorFields);
|
|
27
|
+
|
|
28
|
+
fetchSpy = jest.spyOn(global, "fetch");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
jest.restoreAllMocks();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("Has required properties", () => {
|
|
36
|
+
expect(checkoutConstructor).toEqual(constructorFields);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("Can instance LiteCheckout", () => {
|
|
40
|
+
expect(liteCheckout).toBeInstanceOf(LiteCheckout);
|
|
41
|
+
expect(liteCheckout.apiKeyTonder).toEqual(constructorFields.apiKey);
|
|
42
|
+
expect(liteCheckout.baseUrl).toEqual(constructorFields.baseUrl);
|
|
43
|
+
expect(liteCheckout.abortController.signal).toEqual(constructorFields.signal);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
});
|
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import "../utils/defaultMock";
|
|
2
|
-
import { LiteCheckout } from "../../src";
|
|
3
|
-
import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
4
|
-
import { constructorFields } from "../utils/defaultMock";
|
|
5
|
-
import { OrderResponseClass, OrderClass, OrderEmptyValuesResponse } from "../utils/mockClasses";
|
|
6
|
-
import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
interface Window {
|
|
10
|
-
OpenPay: any;
|
|
11
|
-
Skyflow: any;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe("createOrder", () => {
|
|
16
|
-
let checkoutConstructor: IInlineLiteCheckoutOptions,
|
|
17
|
-
liteCheckout: LiteCheckout,
|
|
18
|
-
fetchSpy: jest.SpyInstance,
|
|
19
|
-
liteCheckoutSpy: jest.SpyInstance;
|
|
20
|
-
|
|
21
|
-
beforeEach(async () => {
|
|
22
|
-
window.fetch = jest.fn();
|
|
23
|
-
|
|
24
|
-
checkoutConstructor = {
|
|
25
|
-
...constructorFields,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
liteCheckout = new LiteCheckout(constructorFields);
|
|
29
|
-
|
|
30
|
-
fetchSpy = jest.spyOn(global, "fetch");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(() => {
|
|
34
|
-
jest.restoreAllMocks();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("createOrder success", async () => {
|
|
38
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
39
|
-
|
|
40
|
-
fetchSpy.mockImplementation(() =>
|
|
41
|
-
Promise.resolve({
|
|
42
|
-
json: () => Promise.resolve([{ ...new OrderResponseClass() }]),
|
|
43
|
-
ok: true,
|
|
44
|
-
})
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const response = await liteCheckout.createOrder({
|
|
48
|
-
...new OrderClass(),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
expect(response).toStrictEqual([{ ...new OrderResponseClass() }]);
|
|
52
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
53
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith({ ...new OrderClass() });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("createOrder empty", async () => {
|
|
57
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
58
|
-
|
|
59
|
-
fetchSpy.mockImplementation(() =>
|
|
60
|
-
Promise.resolve({
|
|
61
|
-
json: () => Promise.resolve(),
|
|
62
|
-
ok: true,
|
|
63
|
-
})
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const response = await liteCheckout.createOrder({
|
|
67
|
-
...new OrderClass(),
|
|
68
|
-
});
|
|
69
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
70
|
-
expect(liteCheckoutSpy).toHaveReturned();
|
|
71
|
-
expect(response).toBeUndefined();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("createOrder errorResponse", async () => {
|
|
75
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
76
|
-
|
|
77
|
-
fetchSpy.mockImplementation(() =>
|
|
78
|
-
Promise.resolve({
|
|
79
|
-
json: () => Promise.resolve(),
|
|
80
|
-
ok: false,
|
|
81
|
-
status: 400,
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
let error;
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
const response = await liteCheckout.createOrder({
|
|
89
|
-
...new OrderClass(),
|
|
90
|
-
})
|
|
91
|
-
} catch (e) {
|
|
92
|
-
error = e;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
96
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("createOrder empty values", async () => {
|
|
100
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
101
|
-
|
|
102
|
-
fetchSpy.mockImplementation(() =>
|
|
103
|
-
Promise.resolve({
|
|
104
|
-
json: () => Promise.resolve(OrderEmptyValuesResponse),
|
|
105
|
-
ok: false,
|
|
106
|
-
status: 400,
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
let error: ErrorResponse;
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
const response = (await liteCheckout.createOrder({
|
|
114
|
-
...new OrderClass(),
|
|
115
|
-
})) as ErrorResponse;
|
|
116
|
-
} catch (e: any) {
|
|
117
|
-
error = e;
|
|
118
|
-
expect(error.body).toStrictEqual(OrderEmptyValuesResponse);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("createOrder errorCatch", async () => {
|
|
123
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
124
|
-
|
|
125
|
-
fetchSpy.mockRejectedValue("error");
|
|
126
|
-
|
|
127
|
-
let error: ErrorResponse;
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
const response = (await liteCheckout.createOrder({
|
|
131
|
-
...new OrderClass(),
|
|
132
|
-
})) as ErrorResponse;
|
|
133
|
-
} catch (e: any) {
|
|
134
|
-
error = e;
|
|
135
|
-
expect(error.message).toStrictEqual("error");
|
|
136
|
-
expect(error.name).toStrictEqual("catch");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
140
|
-
expect(liteCheckoutSpy).rejects.toThrow();
|
|
141
|
-
});
|
|
1
|
+
import "../utils/defaultMock";
|
|
2
|
+
import { LiteCheckout } from "../../src";
|
|
3
|
+
import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
4
|
+
import { constructorFields } from "../utils/defaultMock";
|
|
5
|
+
import { OrderResponseClass, OrderClass, OrderEmptyValuesResponse } from "../utils/mockClasses";
|
|
6
|
+
import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
OpenPay: any;
|
|
11
|
+
Skyflow: any;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("createOrder", () => {
|
|
16
|
+
let checkoutConstructor: IInlineLiteCheckoutOptions,
|
|
17
|
+
liteCheckout: LiteCheckout,
|
|
18
|
+
fetchSpy: jest.SpyInstance,
|
|
19
|
+
liteCheckoutSpy: jest.SpyInstance;
|
|
20
|
+
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
window.fetch = jest.fn();
|
|
23
|
+
|
|
24
|
+
checkoutConstructor = {
|
|
25
|
+
...constructorFields,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
liteCheckout = new LiteCheckout(constructorFields);
|
|
29
|
+
|
|
30
|
+
fetchSpy = jest.spyOn(global, "fetch");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
jest.restoreAllMocks();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("createOrder success", async () => {
|
|
38
|
+
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
39
|
+
|
|
40
|
+
fetchSpy.mockImplementation(() =>
|
|
41
|
+
Promise.resolve({
|
|
42
|
+
json: () => Promise.resolve([{ ...new OrderResponseClass() }]),
|
|
43
|
+
ok: true,
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const response = await liteCheckout.createOrder({
|
|
48
|
+
...new OrderClass(),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(response).toStrictEqual([{ ...new OrderResponseClass() }]);
|
|
52
|
+
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
53
|
+
expect(liteCheckoutSpy).toHaveBeenCalledWith({ ...new OrderClass() });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("createOrder empty", async () => {
|
|
57
|
+
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
58
|
+
|
|
59
|
+
fetchSpy.mockImplementation(() =>
|
|
60
|
+
Promise.resolve({
|
|
61
|
+
json: () => Promise.resolve(),
|
|
62
|
+
ok: true,
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const response = await liteCheckout.createOrder({
|
|
67
|
+
...new OrderClass(),
|
|
68
|
+
});
|
|
69
|
+
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
70
|
+
expect(liteCheckoutSpy).toHaveReturned();
|
|
71
|
+
expect(response).toBeUndefined();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("createOrder errorResponse", async () => {
|
|
75
|
+
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
76
|
+
|
|
77
|
+
fetchSpy.mockImplementation(() =>
|
|
78
|
+
Promise.resolve({
|
|
79
|
+
json: () => Promise.resolve(),
|
|
80
|
+
ok: false,
|
|
81
|
+
status: 400,
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
let error;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const response = await liteCheckout.createOrder({
|
|
89
|
+
...new OrderClass(),
|
|
90
|
+
})
|
|
91
|
+
} catch (e) {
|
|
92
|
+
error = e;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
96
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("createOrder empty values", async () => {
|
|
100
|
+
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
101
|
+
|
|
102
|
+
fetchSpy.mockImplementation(() =>
|
|
103
|
+
Promise.resolve({
|
|
104
|
+
json: () => Promise.resolve(OrderEmptyValuesResponse),
|
|
105
|
+
ok: false,
|
|
106
|
+
status: 400,
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
let error: ErrorResponse;
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const response = (await liteCheckout.createOrder({
|
|
114
|
+
...new OrderClass(),
|
|
115
|
+
})) as ErrorResponse;
|
|
116
|
+
} catch (e: any) {
|
|
117
|
+
error = e;
|
|
118
|
+
expect(error.body).toStrictEqual(OrderEmptyValuesResponse);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("createOrder errorCatch", async () => {
|
|
123
|
+
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
124
|
+
|
|
125
|
+
fetchSpy.mockRejectedValue("error");
|
|
126
|
+
|
|
127
|
+
let error: ErrorResponse;
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const response = (await liteCheckout.createOrder({
|
|
131
|
+
...new OrderClass(),
|
|
132
|
+
})) as ErrorResponse;
|
|
133
|
+
} catch (e: any) {
|
|
134
|
+
error = e;
|
|
135
|
+
expect(error.message).toStrictEqual("error");
|
|
136
|
+
expect(error.name).toStrictEqual("catch");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
140
|
+
expect(liteCheckoutSpy).rejects.toThrow();
|
|
141
|
+
});
|
|
142
142
|
});
|