@tonder.io/ionic-lite-sdk 0.0.20-beta → 0.0.22-beta
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/README.md +4 -1
- package/dist/types/requests.d.ts +7 -6
- package/package.json +1 -1
- package/src/types/requests.ts +7 -6
- package/src/types/responses.ts +1 -1
- package/tests/methods/createOrder.test.ts +21 -1
- package/tests/methods/customerRegister.test.ts +3 -3
- package/tests/utils/mockClasses.ts +64 -7
package/README.md
CHANGED
|
@@ -210,11 +210,14 @@ const jsonResponseOrder = await liteCheckout.createOrder(
|
|
|
210
210
|
const now = new Date();
|
|
211
211
|
const dateString = now.toISOString();
|
|
212
212
|
|
|
213
|
+
const { id: customerId } = await liteCheckout.customerRegister(customerEmail);
|
|
214
|
+
|
|
213
215
|
const paymentData = {
|
|
214
216
|
business_pk: business.pk,
|
|
215
217
|
amount: total,
|
|
216
218
|
date: dateString,
|
|
217
|
-
|
|
219
|
+
order_id: jsonResponseOrder.id,
|
|
220
|
+
client_id: customerId,
|
|
218
221
|
};
|
|
219
222
|
|
|
220
223
|
const jsonResponsePayment = await liteCheckout.createPayment(
|
package/dist/types/requests.d.ts
CHANGED
|
@@ -3,19 +3,20 @@ import { SkyflowRecord } from "./skyflow";
|
|
|
3
3
|
export interface CreateOrderRequest {
|
|
4
4
|
business: string;
|
|
5
5
|
client: string;
|
|
6
|
-
billing_address_id?:
|
|
7
|
-
shipping_address_id?:
|
|
6
|
+
billing_address_id?: number | null;
|
|
7
|
+
shipping_address_id?: number | null;
|
|
8
8
|
amount: number;
|
|
9
|
-
status
|
|
9
|
+
status?: string;
|
|
10
10
|
reference: string | number;
|
|
11
11
|
is_oneclick: boolean;
|
|
12
12
|
items: OrderItem[];
|
|
13
13
|
}
|
|
14
14
|
export type CreatePaymentRequest = {
|
|
15
|
-
business_pk
|
|
15
|
+
business_pk?: string | number;
|
|
16
16
|
amount: number;
|
|
17
|
-
date
|
|
18
|
-
|
|
17
|
+
date?: string;
|
|
18
|
+
order_id?: string | number;
|
|
19
|
+
client_id?: string | number;
|
|
19
20
|
};
|
|
20
21
|
export type StartCheckoutRequest = {
|
|
21
22
|
card: any;
|
package/package.json
CHANGED
package/src/types/requests.ts
CHANGED
|
@@ -4,20 +4,21 @@ import { SkyflowRecord } from "./skyflow";
|
|
|
4
4
|
export interface CreateOrderRequest {
|
|
5
5
|
business: string,
|
|
6
6
|
client: string,
|
|
7
|
-
billing_address_id?:
|
|
8
|
-
shipping_address_id?:
|
|
7
|
+
billing_address_id?: number | null,
|
|
8
|
+
shipping_address_id?: number | null,
|
|
9
9
|
amount: number,
|
|
10
|
-
status
|
|
10
|
+
status?: string,
|
|
11
11
|
reference: string | number,
|
|
12
12
|
is_oneclick: boolean,
|
|
13
13
|
items: OrderItem[]
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export type CreatePaymentRequest = {
|
|
17
|
-
business_pk
|
|
17
|
+
business_pk?: string | number,
|
|
18
18
|
amount: number,
|
|
19
|
-
date
|
|
20
|
-
|
|
19
|
+
date?: string,
|
|
20
|
+
order_id?: string | number
|
|
21
|
+
client_id?: string | number
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export type StartCheckoutRequest = {
|
package/src/types/responses.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
|
4
4
|
import { LiteCheckoutConstructor } from "../../src/classes/liteCheckout";
|
|
5
5
|
import { IErrorResponse } from "../../src/types/responses";
|
|
6
6
|
import { constructorFields } from "../utils/defaultMock";
|
|
7
|
-
import { OrderResponseClass, OrderClass } from "../utils/mockClasses";
|
|
7
|
+
import { OrderResponseClass, OrderClass, OrderClassEmptyValues, OrderEmptyValuesResponse } from "../utils/mockClasses";
|
|
8
8
|
|
|
9
9
|
declare global {
|
|
10
10
|
interface Window {
|
|
@@ -90,6 +90,26 @@ describe("createOrder", () => {
|
|
|
90
90
|
expect(response).toBeInstanceOf(ErrorResponse);
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
+
it("createOrder empty values", async () => {
|
|
94
|
+
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
95
|
+
|
|
96
|
+
fetchSpy.mockImplementation(() =>
|
|
97
|
+
Promise.resolve({
|
|
98
|
+
json: () => Promise.resolve(OrderEmptyValuesResponse),
|
|
99
|
+
ok: false,
|
|
100
|
+
status: 400,
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const response = (await liteCheckout.createOrder({
|
|
105
|
+
...new OrderClassEmptyValues(),
|
|
106
|
+
})) as IErrorResponse;
|
|
107
|
+
|
|
108
|
+
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
109
|
+
expect(response.body).toStrictEqual(OrderEmptyValuesResponse);
|
|
110
|
+
expect(liteCheckoutSpy).rejects.toThrow();
|
|
111
|
+
});
|
|
112
|
+
|
|
93
113
|
it("createOrder errorCatch", async () => {
|
|
94
114
|
liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
|
|
95
115
|
|
|
@@ -4,7 +4,7 @@ import { ErrorResponse } from "../../src/classes/errorResponse";
|
|
|
4
4
|
import { LiteCheckoutConstructor } from "../../src/classes/liteCheckout";
|
|
5
5
|
import { IErrorResponse } from "../../src/types/responses";
|
|
6
6
|
import { constructorFields } from "../utils/defaultMock";
|
|
7
|
-
import { BusinessClass } from "../utils/mockClasses";
|
|
7
|
+
import { BusinessClass, CustomerRegisterClass } from "../utils/mockClasses";
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
declare global {
|
|
@@ -43,7 +43,7 @@ describe("customerRegister", () => {
|
|
|
43
43
|
Promise.resolve({
|
|
44
44
|
json: () =>
|
|
45
45
|
Promise.resolve({
|
|
46
|
-
...new
|
|
46
|
+
...new CustomerRegisterClass(),
|
|
47
47
|
}),
|
|
48
48
|
ok: true,
|
|
49
49
|
})
|
|
@@ -51,7 +51,7 @@ describe("customerRegister", () => {
|
|
|
51
51
|
|
|
52
52
|
const response = await liteCheckout.customerRegister("email@gmail.com");
|
|
53
53
|
|
|
54
|
-
expect(response).toStrictEqual({ ...new
|
|
54
|
+
expect(response).toStrictEqual({ ...new CustomerRegisterClass() });
|
|
55
55
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
56
56
|
expect(liteCheckoutSpy).toHaveBeenCalledWith("email@gmail.com");
|
|
57
57
|
});
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
CreatePaymentRequest,
|
|
5
5
|
RegisterCustomerCardRequest,
|
|
6
6
|
StartCheckoutRequest,
|
|
7
|
-
TokensRequest
|
|
7
|
+
TokensRequest
|
|
8
8
|
} from "../../src/types/requests";
|
|
9
9
|
import {
|
|
10
10
|
CreateOrderResponse,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
GetCustomerCardsResponse,
|
|
14
14
|
RegisterCustomerCardResponse,
|
|
15
15
|
StartCheckoutResponse,
|
|
16
|
+
CustomerRegisterResponse
|
|
16
17
|
} from "../../src/types/responses";
|
|
17
18
|
|
|
18
19
|
export class BusinessClass implements Business {
|
|
@@ -69,8 +70,8 @@ export class BusinessClass implements Business {
|
|
|
69
70
|
export class OrderClass implements CreateOrderRequest {
|
|
70
71
|
business!: string;
|
|
71
72
|
client!: string;
|
|
72
|
-
billing_address_id!:
|
|
73
|
-
shipping_address_id!:
|
|
73
|
+
billing_address_id!: number | null;
|
|
74
|
+
shipping_address_id!: number | null;
|
|
74
75
|
amount!: number;
|
|
75
76
|
status!: string;
|
|
76
77
|
reference!: string;
|
|
@@ -81,8 +82,8 @@ export class OrderClass implements CreateOrderRequest {
|
|
|
81
82
|
return {
|
|
82
83
|
business: "The business pk",
|
|
83
84
|
client: "Client auth token",
|
|
84
|
-
billing_address_id:
|
|
85
|
-
shipping_address_id:
|
|
85
|
+
billing_address_id: null,
|
|
86
|
+
shipping_address_id: null,
|
|
86
87
|
amount: 25,
|
|
87
88
|
status: "PENDING",
|
|
88
89
|
reference: "XXXXXXX",
|
|
@@ -95,6 +96,35 @@ export class OrderClass implements CreateOrderRequest {
|
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
|
|
99
|
+
export class OrderClassEmptyValues implements CreateOrderRequest {
|
|
100
|
+
business!: string;
|
|
101
|
+
client!: string;
|
|
102
|
+
billing_address_id!: number | null;
|
|
103
|
+
shipping_address_id!: number | null;
|
|
104
|
+
amount!: number;
|
|
105
|
+
status!: string;
|
|
106
|
+
reference!: string;
|
|
107
|
+
is_oneclick!: boolean;
|
|
108
|
+
items!: OrderItem[];
|
|
109
|
+
|
|
110
|
+
get mockObject(): CreateOrderRequest {
|
|
111
|
+
return {
|
|
112
|
+
business: "",
|
|
113
|
+
client: "Client auth token",
|
|
114
|
+
billing_address_id: 1,
|
|
115
|
+
shipping_address_id: 2,
|
|
116
|
+
amount: 25,
|
|
117
|
+
status: "PENDING",
|
|
118
|
+
reference: "",
|
|
119
|
+
is_oneclick: false,
|
|
120
|
+
items: [
|
|
121
|
+
{ ...new OrderItemClass() }
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
98
128
|
export class OrderItemClass implements OrderItem {
|
|
99
129
|
description!: string;
|
|
100
130
|
quantity!: number;
|
|
@@ -205,7 +235,8 @@ export class CreatePaymentRequestClass implements CreatePaymentRequest {
|
|
|
205
235
|
business_pk!: string;
|
|
206
236
|
amount!: number;
|
|
207
237
|
date!: string;
|
|
208
|
-
|
|
238
|
+
order_id!: string;
|
|
239
|
+
client_id!: number;
|
|
209
240
|
|
|
210
241
|
get mockObject(): CreatePaymentRequest {
|
|
211
242
|
const now = new Date();
|
|
@@ -214,7 +245,8 @@ export class CreatePaymentRequestClass implements CreatePaymentRequest {
|
|
|
214
245
|
business_pk: "NNNNNNNNNN",
|
|
215
246
|
amount: 25,
|
|
216
247
|
date: dateString,
|
|
217
|
-
|
|
248
|
+
order_id: "XXXXX",
|
|
249
|
+
client_id: 1
|
|
218
250
|
};
|
|
219
251
|
}
|
|
220
252
|
}
|
|
@@ -536,3 +568,28 @@ export class GetCustomerCardsResponseClass implements GetCustomerCardsResponse {
|
|
|
536
568
|
};
|
|
537
569
|
}
|
|
538
570
|
}
|
|
571
|
+
|
|
572
|
+
export const OrderEmptyValuesResponse = {
|
|
573
|
+
"business": [
|
|
574
|
+
"This field may not be blank."
|
|
575
|
+
],
|
|
576
|
+
"reference": [
|
|
577
|
+
"This field may not be null."
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export class CustomerRegisterClass implements CustomerRegisterResponse {
|
|
582
|
+
id!: number;
|
|
583
|
+
email!: string;
|
|
584
|
+
auth_token!: string;
|
|
585
|
+
first_name!: string;
|
|
586
|
+
last_name!: string;
|
|
587
|
+
|
|
588
|
+
get mockObject(): CustomerRegisterResponse {
|
|
589
|
+
return {
|
|
590
|
+
id: 10,
|
|
591
|
+
email: "email@gmail.com",
|
|
592
|
+
auth_token: "string"
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
}
|