@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
|
@@ -1,122 +1,122 @@
|
|
|
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
|
-
});
|
|
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
122
|
});
|
|
@@ -1,119 +1,119 @@
|
|
|
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
|
-
});
|
|
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
119
|
});
|