@tonder.io/ionic-lite-sdk 0.0.57 → 0.0.58-beta.DEV-1845.1
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/dist/classes/liteCheckout.d.ts +7 -2
- package/dist/helpers/skyflow.d.ts +20 -0
- package/dist/index.js +1 -1
- package/dist/shared/constants/skyflow.contants.d.ts +36 -0
- package/dist/shared/styles/skyflow.styles.d.ts +14 -0
- package/dist/types/card.d.ts +14 -0
- package/dist/types/commons.d.ts +82 -0
- package/dist/types/jsx-web-components.d.ts +17 -0
- package/dist/types/liteInlineCheckout.d.ts +8 -0
- package/dist/types/requests.d.ts +1 -1
- package/dist/ui/components/input/CardCVVInput.d.ts +19 -0
- package/package.json +2 -2
- package/src/classes/3dsHandler.ts +0 -1
- package/src/classes/liteCheckout.ts +67 -17
- package/src/helpers/mercadopago.ts +1 -3
- package/src/helpers/skyflow.ts +307 -34
- package/src/shared/constants/skyflow.contants.ts +63 -0
- package/src/shared/styles/skyflow.styles.ts +63 -0
- package/src/types/card.ts +12 -0
- package/src/types/commons.ts +95 -1
- package/src/types/liteInlineCheckout.ts +9 -1
- package/src/types/requests.ts +1 -1
- package/tests/classes/liteCheckout.test.ts +0 -57
- package/tests/methods/createOrder.test.ts +0 -142
- package/tests/methods/createPayment.test.ts +0 -122
- package/tests/methods/customerRegister.test.ts +0 -119
- package/tests/methods/getBusiness.test.ts +0 -114
- package/tests/methods/getCustomerCards.test.ts +0 -113
- package/tests/methods/registerCustomerCard.test.ts +0 -118
- package/tests/methods/startCheckoutRouter.test.ts +0 -120
- package/tests/methods/startCheckoutRouterFull.test.ts +0 -139
- package/tests/utils/defaultMock.ts +0 -22
- package/tests/utils/mockClasses.ts +0 -659
package/src/types/commons.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ICustomer } from "./customer";
|
|
2
2
|
import {IProcessPaymentRequest, IStartCheckoutResponse} from "./checkout";
|
|
3
|
+
import CollectorContainer from "skyflow-js/types/core/external/collect/collect-container";
|
|
4
|
+
import ComposableContainer from "skyflow-js/types/core/external/collect/compose-collect-container";
|
|
5
|
+
import RevealContainer from "skyflow-js/types/core/external/reveal/reveal-container";
|
|
6
|
+
import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
|
|
7
|
+
import ComposableElement from "skyflow-js/types/core/external/collect/compose-collect-element";
|
|
8
|
+
import RevealElement from "skyflow-js/types/core/external/reveal/reveal-element";
|
|
9
|
+
import {LabelStyles} from "skyflow-js/types/utils/common";
|
|
10
|
+
|
|
3
11
|
|
|
4
12
|
export type Business = {
|
|
5
13
|
business: {
|
|
@@ -120,9 +128,29 @@ export interface IInlineLiteCheckoutOptions
|
|
|
120
128
|
collectorIds?: {
|
|
121
129
|
tdsIframe?: string
|
|
122
130
|
}
|
|
131
|
+
customization?: ILiteCustomizationOptions;
|
|
132
|
+
events?: IEvents;
|
|
123
133
|
}
|
|
124
134
|
|
|
125
|
-
|
|
135
|
+
export interface ICardFormEvents {
|
|
136
|
+
cardHolderEvents?: IInputEvents;
|
|
137
|
+
cardNumberEvents?: IInputEvents;
|
|
138
|
+
cvvEvents?: IInputEvents;
|
|
139
|
+
monthEvents?: IInputEvents;
|
|
140
|
+
yearEvents?: IInputEvents;
|
|
141
|
+
}
|
|
142
|
+
export interface IInputEvents {
|
|
143
|
+
onChange?: (event: IEventSecureInput) => void;
|
|
144
|
+
onFocus?: (event: IEventSecureInput) => void;
|
|
145
|
+
onBlur?: (event: IEventSecureInput) => void;
|
|
146
|
+
}
|
|
147
|
+
export interface IEventSecureInput {
|
|
148
|
+
elementType: string;
|
|
149
|
+
isEmpty: boolean;
|
|
150
|
+
isFocused: boolean;
|
|
151
|
+
isValid: boolean;
|
|
152
|
+
}
|
|
153
|
+
export interface IEvents extends ICardFormEvents {}
|
|
126
154
|
export interface IApiError {
|
|
127
155
|
code: string;
|
|
128
156
|
body: Record<string, string> | string;
|
|
@@ -140,3 +168,69 @@ export interface IPublicError {
|
|
|
140
168
|
export type CustomizationOptions = {
|
|
141
169
|
redirectOnComplete?: boolean
|
|
142
170
|
}
|
|
171
|
+
|
|
172
|
+
export interface InCollectorContainer {
|
|
173
|
+
container: CollectorContainer | ComposableContainer | RevealContainer;
|
|
174
|
+
elements: (CollectElement | ComposableElement | RevealElement)[];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface ILiteCustomizationOptions extends CustomizationOptions {
|
|
178
|
+
styles?: IStyles;
|
|
179
|
+
labels?: IFormLabels;
|
|
180
|
+
placeholders?: IFormPlaceholder;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface IFormLabels {
|
|
184
|
+
name?: string;
|
|
185
|
+
card_number?: string;
|
|
186
|
+
cvv?: string;
|
|
187
|
+
expiry_date?: string;
|
|
188
|
+
expiration_year?: string;
|
|
189
|
+
expiration_month?: string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface IFormPlaceholder {
|
|
193
|
+
name?: string;
|
|
194
|
+
card_number?: string;
|
|
195
|
+
cvv?: string;
|
|
196
|
+
expiration_month?: string;
|
|
197
|
+
expiration_year?: string;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface IStyles {
|
|
201
|
+
cardForm?: ILiteCardFormStyles;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface ILiteCardFormStyles extends StylesBaseVariant, IElementStyle {}
|
|
205
|
+
|
|
206
|
+
export interface StylesBaseVariant {
|
|
207
|
+
base?: Record<string, any>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface IElementStyle {
|
|
211
|
+
inputStyles?: CollectInputStylesVariant;
|
|
212
|
+
labelStyles?: LabelStyles;
|
|
213
|
+
errorStyles?: StylesBaseVariant;
|
|
214
|
+
}
|
|
215
|
+
export interface StylesFocusVariant {
|
|
216
|
+
focus?: Record<string, any>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface CollectInputStylesVariant
|
|
220
|
+
extends StylesBaseVariant,
|
|
221
|
+
StylesFocusVariant {
|
|
222
|
+
complete?: Record<string, any>;
|
|
223
|
+
invalid?: Record<string, any>;
|
|
224
|
+
empty?: Record<string, any>;
|
|
225
|
+
cardIcon?: Record<string, any>;
|
|
226
|
+
dropdownIcon?: Record<string, any>;
|
|
227
|
+
dropdown?: Record<string, any>;
|
|
228
|
+
dropdownListItem?: Record<string, any>;
|
|
229
|
+
global: Record<string, any>;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface CollectLabelStylesVariant
|
|
233
|
+
extends StylesBaseVariant,
|
|
234
|
+
StylesFocusVariant {
|
|
235
|
+
requiredAsterisk?: Record<string, any>;
|
|
236
|
+
}
|
|
@@ -223,5 +223,13 @@ export interface ILiteCheckout {
|
|
|
223
223
|
public_key: string,
|
|
224
224
|
is_sandbox: boolean,
|
|
225
225
|
): Promise<string | ErrorResponse>;
|
|
226
|
-
}
|
|
227
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Displays and renders card input fields in the checkout.
|
|
229
|
+
* Uses the provided configuration to show the required fields in the payment form.
|
|
230
|
+
* @param {import("./card").IMountCardFieldsRequest} event - Configuration for the card fields to render.
|
|
231
|
+
* @returns {Promise<void>} Resolves when the fields have been successfully rendered.
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
mountCardFields(event: import("./card").IMountCardFieldsRequest): Promise<void>;
|
|
235
|
+
}
|
package/src/types/requests.ts
CHANGED
|
@@ -1,57 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import "../utils/defaultMock";
|
|
2
|
-
import { LiteCheckout } from "../../src";
|
|
3
|
-
import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
4
|
-
import { constructorFields } from "../utils/defaultMock";
|
|
5
|
-
import { CreatePaymentResponseClass, CreatePaymentRequestClass } from "../utils/mockClasses";
|
|
6
|
-
import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare global {
|
|
10
|
-
interface Window {
|
|
11
|
-
OpenPay: any;
|
|
12
|
-
Skyflow: any;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe("createPayment", () => {
|
|
17
|
-
let checkoutConstructor: IInlineLiteCheckoutOptions,
|
|
18
|
-
liteCheckout: LiteCheckout,
|
|
19
|
-
fetchSpy: jest.SpyInstance,
|
|
20
|
-
liteCheckoutSpy: jest.SpyInstance;
|
|
21
|
-
|
|
22
|
-
beforeEach(async () => {
|
|
23
|
-
window.fetch = jest.fn();
|
|
24
|
-
|
|
25
|
-
checkoutConstructor = {
|
|
26
|
-
...constructorFields,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
liteCheckout = new LiteCheckout(constructorFields);
|
|
30
|
-
|
|
31
|
-
fetchSpy = jest.spyOn(global, "fetch");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
jest.restoreAllMocks();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("createPayment success", async () => {
|
|
39
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
|
|
40
|
-
|
|
41
|
-
fetchSpy.mockImplementation(() =>
|
|
42
|
-
Promise.resolve({
|
|
43
|
-
json: () => Promise.resolve([{ ...new CreatePaymentResponseClass() }]),
|
|
44
|
-
ok: true,
|
|
45
|
-
})
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const response = await liteCheckout.createPayment({
|
|
49
|
-
...new CreatePaymentRequestClass(),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(response).toStrictEqual([{ ...new CreatePaymentResponseClass() }]);
|
|
53
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
54
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith({
|
|
55
|
-
...new CreatePaymentRequestClass(),
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("createPayment empty", async () => {
|
|
60
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
|
|
61
|
-
|
|
62
|
-
fetchSpy.mockImplementation(() =>
|
|
63
|
-
Promise.resolve({
|
|
64
|
-
json: () => Promise.resolve(),
|
|
65
|
-
ok: true,
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const response = await liteCheckout.createPayment({
|
|
70
|
-
...new CreatePaymentRequestClass(),
|
|
71
|
-
});
|
|
72
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
73
|
-
expect(liteCheckoutSpy).toHaveReturned();
|
|
74
|
-
expect(response).toBeUndefined();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("createPayment errorResponse", async () => {
|
|
78
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
|
|
79
|
-
|
|
80
|
-
fetchSpy.mockImplementation(() =>
|
|
81
|
-
Promise.resolve({
|
|
82
|
-
json: () => Promise.resolve(),
|
|
83
|
-
ok: false,
|
|
84
|
-
status: 400,
|
|
85
|
-
})
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
let error;
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
const response = await liteCheckout.createPayment({
|
|
92
|
-
...new CreatePaymentRequestClass(),
|
|
93
|
-
})
|
|
94
|
-
} catch (e) {
|
|
95
|
-
error = e;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
99
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("createPayment errorCatch", async () => {
|
|
103
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
|
|
104
|
-
|
|
105
|
-
fetchSpy.mockRejectedValue("error");
|
|
106
|
-
|
|
107
|
-
let error: ErrorResponse;
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
const response = (await liteCheckout.createPayment({
|
|
111
|
-
...new CreatePaymentRequestClass(),
|
|
112
|
-
})) as ErrorResponse;
|
|
113
|
-
} catch (e: any) {
|
|
114
|
-
error = e;
|
|
115
|
-
expect(error.message).toStrictEqual("error");
|
|
116
|
-
expect(error.name).toStrictEqual("catch");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
120
|
-
expect(liteCheckoutSpy).rejects.toThrow();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import "../utils/defaultMock";
|
|
2
|
-
import { LiteCheckout } from "../../src";
|
|
3
|
-
import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
4
|
-
import { constructorFields } from "../utils/defaultMock";
|
|
5
|
-
import { CustomerRegisterClass } from "../utils/mockClasses";
|
|
6
|
-
import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare global {
|
|
10
|
-
interface Window {
|
|
11
|
-
OpenPay: any;
|
|
12
|
-
Skyflow: any;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe("customerRegister", () => {
|
|
17
|
-
let checkoutConstructor: IInlineLiteCheckoutOptions,
|
|
18
|
-
liteCheckout: LiteCheckout,
|
|
19
|
-
fetchSpy: jest.SpyInstance,
|
|
20
|
-
liteCheckoutSpy: jest.SpyInstance;
|
|
21
|
-
|
|
22
|
-
beforeEach(async () => {
|
|
23
|
-
window.fetch = jest.fn();
|
|
24
|
-
|
|
25
|
-
checkoutConstructor = {
|
|
26
|
-
...constructorFields,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
liteCheckout = new LiteCheckout(constructorFields);
|
|
30
|
-
|
|
31
|
-
fetchSpy = jest.spyOn(global, "fetch");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
jest.restoreAllMocks();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("customerRegister success", async () => {
|
|
39
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "customerRegister");
|
|
40
|
-
|
|
41
|
-
fetchSpy.mockImplementation(() =>
|
|
42
|
-
Promise.resolve({
|
|
43
|
-
json: () =>
|
|
44
|
-
Promise.resolve({
|
|
45
|
-
...new CustomerRegisterClass(),
|
|
46
|
-
}),
|
|
47
|
-
ok: true,
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const response = await liteCheckout.customerRegister("email@gmail.com");
|
|
52
|
-
|
|
53
|
-
expect(response).toStrictEqual({ ...new CustomerRegisterClass() });
|
|
54
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
55
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith("email@gmail.com");
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("customerRegister empty", async () => {
|
|
59
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "customerRegister");
|
|
60
|
-
|
|
61
|
-
fetchSpy.mockImplementation(() =>
|
|
62
|
-
Promise.resolve({
|
|
63
|
-
json: () => Promise.resolve(),
|
|
64
|
-
ok: true,
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const response = await liteCheckout.customerRegister("email@gmail.com");
|
|
69
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
70
|
-
expect(liteCheckoutSpy).toHaveReturned();
|
|
71
|
-
expect(response).toBeUndefined();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("customerRegister errorResponse", async () => {
|
|
75
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "customerRegister");
|
|
76
|
-
|
|
77
|
-
fetchSpy.mockImplementation(() =>
|
|
78
|
-
Promise.resolve({
|
|
79
|
-
json: () => Promise.resolve(),
|
|
80
|
-
ok: false,
|
|
81
|
-
status: 400,
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
let error: ErrorResponse;
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
const response = await liteCheckout.customerRegister(
|
|
89
|
-
"email@gmail.com"
|
|
90
|
-
)
|
|
91
|
-
} catch (e: any) {
|
|
92
|
-
error = e;
|
|
93
|
-
expect(error.code).toStrictEqual("400");
|
|
94
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("customerRegister errorCatch", async () => {
|
|
100
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "customerRegister");
|
|
101
|
-
|
|
102
|
-
fetchSpy.mockRejectedValue("error");
|
|
103
|
-
|
|
104
|
-
let error: ErrorResponse;
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
const response = (await liteCheckout.customerRegister(
|
|
108
|
-
"email@gmail.com"
|
|
109
|
-
)) as ErrorResponse;
|
|
110
|
-
} catch (e: any) {
|
|
111
|
-
error = e;
|
|
112
|
-
expect(error.message).toStrictEqual("error");
|
|
113
|
-
expect(error.name).toStrictEqual("catch");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
117
|
-
expect(liteCheckoutSpy).rejects.toThrow();
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import "../utils/defaultMock";
|
|
2
|
-
import { LiteCheckout } from "../../src";
|
|
3
|
-
import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
4
|
-
import { constructorFields } from "../utils/defaultMock";
|
|
5
|
-
import { BusinessClass } 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("getBusiness", () => {
|
|
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("getBusiness success", async () => {
|
|
38
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getBusiness");
|
|
39
|
-
|
|
40
|
-
fetchSpy.mockImplementation(() =>
|
|
41
|
-
Promise.resolve({
|
|
42
|
-
json: () =>
|
|
43
|
-
Promise.resolve({
|
|
44
|
-
...new BusinessClass(),
|
|
45
|
-
}),
|
|
46
|
-
ok: true,
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const response = await liteCheckout.getBusiness();
|
|
51
|
-
|
|
52
|
-
expect(response).toStrictEqual({ ...new BusinessClass() });
|
|
53
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("getBusiness empty", async () => {
|
|
57
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getBusiness");
|
|
58
|
-
|
|
59
|
-
fetchSpy.mockImplementation(() =>
|
|
60
|
-
Promise.resolve({
|
|
61
|
-
json: () => Promise.resolve(),
|
|
62
|
-
ok: true,
|
|
63
|
-
})
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const response = await liteCheckout.getBusiness();
|
|
67
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
68
|
-
expect(liteCheckoutSpy).toHaveReturned();
|
|
69
|
-
expect(response).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("getBusiness errorResponse", async () => {
|
|
73
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getBusiness");
|
|
74
|
-
|
|
75
|
-
fetchSpy.mockImplementation(() =>
|
|
76
|
-
Promise.resolve({
|
|
77
|
-
json: () => Promise.resolve(),
|
|
78
|
-
ok: false,
|
|
79
|
-
status: 400,
|
|
80
|
-
})
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
let error: ErrorResponse;
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
const response = (await liteCheckout.getBusiness());
|
|
87
|
-
} catch (e: any) {
|
|
88
|
-
error = e;
|
|
89
|
-
expect(error.code).toStrictEqual("400");
|
|
90
|
-
expect(error).toBeInstanceOf(ErrorResponse);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("getBusiness errorCatch", async () => {
|
|
95
|
-
liteCheckoutSpy = jest.spyOn(liteCheckout, "getBusiness");
|
|
96
|
-
|
|
97
|
-
fetchSpy.mockRejectedValue("error");
|
|
98
|
-
|
|
99
|
-
let error: ErrorResponse;
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const response = (await liteCheckout.getBusiness());
|
|
103
|
-
} catch (e: any) {
|
|
104
|
-
error = e;
|
|
105
|
-
expect(error.message).toStrictEqual("error");
|
|
106
|
-
expect(error.name).toStrictEqual("catch");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
110
|
-
expect(liteCheckoutSpy).rejects.toThrow();
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
|