@tonder.io/ionic-lite-sdk 0.0.25-beta → 0.0.26-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/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/classes/liteCheckout.ts +50 -30
- package/tests/methods/createOrder.test.ts +34 -17
- package/tests/methods/createPayment.test.ts +24 -10
- package/tests/methods/customerRegister.test.ts +24 -10
- package/tests/methods/getBusiness.test.ts +19 -6
- package/tests/methods/getCustomerCards.test.ts +24 -11
- package/tests/methods/getSkyflowToken.test.ts +33 -15
- package/tests/methods/registerCustomerCard.test.ts +23 -10
- package/tests/methods/startCheckoutRouter.test.ts +23 -10
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"skyflow-js";function t(e,t,o,
|
|
1
|
+
import e from"skyflow-js";function t(e,t,o,r){return new(o||(o=Promise))((function(i,n){function s(e){try{a(r.next(e))}catch(e){n(e)}}function d(e){try{a(r.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,d)}a((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class o{constructor({code:e,body:t,name:o,message:r,stack:i}){this.code=e,this.body=t,this.name=o,this.message=r,this.stack=i}}class r{constructor({signal:e,baseUrlTonder:t,apiKeyTonder:o}){this.baseUrlTonder=t,this.signal=e,this.apiKeyTonder=o}getOpenpayDeviceSessionID(e,o,r){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(o),t.setSandboxMode(r),yield t.deviceData.setup({signal:this.signal})}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{const e=yield fetch(`${this.baseUrlTonder}/api/v1/payments/business/${this.apiKeyTonder}`,{headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(e.ok)return yield e.json();throw yield this.buildErrorResponse(e)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/customer/`,o={email:e},r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal,body:JSON.stringify(o)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/orders/`,o=e,r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/business/${e.business_pk}/payments/`,o=e,r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/checkout-router/`,o=e,r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getSkyflowTokens({vault_id:o,vault_url:r,data:i}){return t(this,void 0,void 0,(function*(){const n=e.init({vaultID:o,vaultURL:r,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield this.getVaultToken()})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),s=yield this.getFieldsPromise(i,n);if((yield Promise.all(s)).some((e=>!e)))throw this.buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const e=yield n.collect();if(e)return e.records[0].fields;throw this.buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getVaultToken(){var e;return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(t.ok)return null===(e=yield t.json())||void 0===e?void 0:e.token;throw new Error(`HTTPCODE: ${t.status}`)}catch(e){throw new Error(`Failed to retrieve bearer token; ${"string"==typeof e?e:e.message}`)}}))}getFieldsPromise(e,o){return t(this,void 0,void 0,(function*(){const t=yield this.getFields(e,o);return t?t.map((t=>new Promise((o=>{var r;const i=document.createElement("div");i.hidden=!0,i.id=`id-${t.key}`,null===(r=document.querySelector("body"))||void 0===r||r.appendChild(i),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const r=e[t.key];return t.element.update({value:r}),o(t.element.isMounted())}}),120)}),120)})))):[]}))}registerCustomerCard(e,o){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/`,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal,body:JSON.stringify(o)});if(t.ok)return yield t.json();throw yield this.buildErrorResponse(t)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getCustomerCards(e,o=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${o}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return yield t.json();throw yield this.buildErrorResponse(t)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}deleteCustomerCard(e,o=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${o}`,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return!0;throw yield this.buildErrorResponse(t)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}buildErrorResponseFromCatch(e){return new o({code:(null==e?void 0:e.status)?e.status:e.code,body:null==e?void 0:e.body,name:e?"string"==typeof e?"catch":e.name:"Error",message:e?"string"==typeof e?e:e.message:"Error",stack:"string"==typeof e?void 0:e.stack})}buildErrorResponse(e,r=void 0){return t(this,void 0,void 0,(function*(){let t,i,n="Error";e&&"json"in e&&(t=yield null==e?void 0:e.json()),e&&"status"in e&&(i=e.status.toString()),e&&"text"in e&&(n=yield e.text());return new o({code:i,body:t,name:i,message:n,stack:r})}))}getFields(o,r){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(o).map((o=>t(this,void 0,void 0,(function*(){return{element:yield r.create({table:"cards",column:o,type:e.ElementType.INPUT_FIELD}),key:o}})))))}))}}export{r as LiteCheckout};
|
package/package.json
CHANGED
|
@@ -65,9 +65,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
65
65
|
|
|
66
66
|
if (getBusiness.ok) return (await getBusiness.json()) as Business;
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
throw await this.buildErrorResponse(getBusiness);
|
|
69
69
|
} catch (e) {
|
|
70
|
-
|
|
70
|
+
throw this.buildErrorResponseFromCatch(e);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -86,9 +86,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
if (response.ok) return await response.json() as CustomerRegisterResponse;
|
|
89
|
-
|
|
89
|
+
throw await this.buildErrorResponse(response);
|
|
90
90
|
} catch (e) {
|
|
91
|
-
|
|
91
|
+
throw this.buildErrorResponseFromCatch(e);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -105,9 +105,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
105
105
|
body: JSON.stringify(data),
|
|
106
106
|
});
|
|
107
107
|
if (response.ok) return await response.json() as CreateOrderResponse;
|
|
108
|
-
|
|
108
|
+
throw await this.buildErrorResponse(response);
|
|
109
109
|
} catch (e) {
|
|
110
|
-
|
|
110
|
+
throw this.buildErrorResponseFromCatch(e);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -124,9 +124,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
124
124
|
body: JSON.stringify(data),
|
|
125
125
|
});
|
|
126
126
|
if (response.ok) return await response.json() as CreatePaymentResponse;
|
|
127
|
-
|
|
127
|
+
throw await this.buildErrorResponse(response);
|
|
128
128
|
} catch (e) {
|
|
129
|
-
|
|
129
|
+
throw this.buildErrorResponseFromCatch(e);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -143,9 +143,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
143
143
|
body: JSON.stringify(data),
|
|
144
144
|
});
|
|
145
145
|
if (response.ok) return await response.json() as StartCheckoutResponse;
|
|
146
|
-
|
|
146
|
+
throw await this.buildErrorResponse(response);
|
|
147
147
|
} catch (e) {
|
|
148
|
-
|
|
148
|
+
throw this.buildErrorResponseFromCatch(e);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -175,14 +175,14 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
175
175
|
const mountFail = result.some((item: boolean) => !item);
|
|
176
176
|
|
|
177
177
|
if (mountFail) {
|
|
178
|
-
|
|
178
|
+
throw this.buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));
|
|
179
179
|
} else {
|
|
180
180
|
try {
|
|
181
181
|
const collectResponseSkyflowTonder = await collectContainer.collect() as any;
|
|
182
182
|
if (collectResponseSkyflowTonder) return collectResponseSkyflowTonder["records"][0]["fields"];
|
|
183
|
-
|
|
183
|
+
throw this.buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))
|
|
184
184
|
} catch (error) {
|
|
185
|
-
|
|
185
|
+
throw this.buildErrorResponseFromCatch(error);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
}
|
|
@@ -240,9 +240,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
if (response.ok) return await response.json() as RegisterCustomerCardResponse;
|
|
243
|
-
|
|
243
|
+
throw await this.buildErrorResponse(response);
|
|
244
244
|
} catch (error) {
|
|
245
|
-
|
|
245
|
+
throw this.buildErrorResponseFromCatch(error);
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -258,9 +258,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
258
258
|
});
|
|
259
259
|
|
|
260
260
|
if (response.ok) return await response.json() as GetCustomerCardsResponse;
|
|
261
|
-
|
|
261
|
+
throw await this.buildErrorResponse(response);
|
|
262
262
|
} catch (error) {
|
|
263
|
-
|
|
263
|
+
throw this.buildErrorResponseFromCatch(error);
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -276,33 +276,53 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
if (response.ok) return true;
|
|
279
|
-
|
|
279
|
+
throw await this.buildErrorResponse(response);
|
|
280
280
|
} catch (error) {
|
|
281
|
-
|
|
281
|
+
throw this.buildErrorResponseFromCatch(error);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
private buildErrorResponseFromCatch(e: any): ErrorResponse {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
286
|
+
|
|
287
|
+
const error = new ErrorResponse({
|
|
288
|
+
code: e?.status ? e.status : e.code,
|
|
289
|
+
body: e?.body,
|
|
290
|
+
name: e ? typeof e == "string" ? "catch" : (e as Error).name : "Error",
|
|
291
|
+
message: e ? (typeof e == "string" ? e : (e as Error).message) : "Error",
|
|
291
292
|
stack: typeof e == "string" ? undefined : (e as Error).stack,
|
|
292
293
|
})
|
|
294
|
+
|
|
295
|
+
return error;
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
private async buildErrorResponse(
|
|
296
299
|
response: Response,
|
|
297
300
|
stack: string | undefined = undefined
|
|
298
301
|
): Promise<ErrorResponse> {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
|
|
303
|
+
let body, status, message = "Error";
|
|
304
|
+
|
|
305
|
+
if(response && "json" in response) {
|
|
306
|
+
body = await response?.json();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if(response && "status" in response) {
|
|
310
|
+
status = response.status.toString();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if(response && "text" in response) {
|
|
314
|
+
message = await response.text();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const error = new ErrorResponse({
|
|
318
|
+
code: status,
|
|
319
|
+
body: body,
|
|
320
|
+
name: status,
|
|
321
|
+
message: message,
|
|
304
322
|
stack,
|
|
305
|
-
} as IErrorResponse)
|
|
323
|
+
} as IErrorResponse)
|
|
324
|
+
|
|
325
|
+
return error;
|
|
306
326
|
}
|
|
307
327
|
|
|
308
328
|
private async getFields(data: any, collectContainer: CollectContainer): Promise<{ element: CollectElement, key: string }[]> {
|
|
@@ -82,12 +82,19 @@ describe("createOrder", () => {
|
|
|
82
82
|
status: 400,
|
|
83
83
|
})
|
|
84
84
|
);
|
|
85
|
+
|
|
86
|
+
let error;
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
try {
|
|
89
|
+
const response = await liteCheckout.createOrder({
|
|
90
|
+
...new OrderClass(),
|
|
91
|
+
})
|
|
92
|
+
} catch (e) {
|
|
93
|
+
error = e;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
97
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
91
98
|
});
|
|
92
99
|
|
|
93
100
|
it("createOrder empty values", async () => {
|
|
@@ -101,13 +108,16 @@ describe("createOrder", () => {
|
|
|
101
108
|
})
|
|
102
109
|
);
|
|
103
110
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
let error: ErrorResponse;
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const response = (await liteCheckout.createOrder({
|
|
115
|
+
...new OrderClass(),
|
|
116
|
+
})) as ErrorResponse;
|
|
117
|
+
} catch (e: any) {
|
|
118
|
+
error = e;
|
|
119
|
+
expect(error.body).toStrictEqual(OrderEmptyValuesResponse);
|
|
120
|
+
}
|
|
111
121
|
});
|
|
112
122
|
|
|
113
123
|
it("createOrder errorCatch", async () => {
|
|
@@ -115,12 +125,19 @@ describe("createOrder", () => {
|
|
|
115
125
|
|
|
116
126
|
fetchSpy.mockRejectedValue("error");
|
|
117
127
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
let error: ErrorResponse;
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const response = (await liteCheckout.createOrder({
|
|
132
|
+
...new OrderClass(),
|
|
133
|
+
})) as ErrorResponse;
|
|
134
|
+
} catch (e: any) {
|
|
135
|
+
error = e;
|
|
136
|
+
expect(error.message).toStrictEqual("error");
|
|
137
|
+
expect(error.name).toStrictEqual("catch");
|
|
138
|
+
}
|
|
139
|
+
|
|
121
140
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
122
|
-
expect(response.message).toStrictEqual("error");
|
|
123
|
-
expect(response.name).toStrictEqual("catch");
|
|
124
141
|
expect(liteCheckoutSpy).rejects.toThrow();
|
|
125
142
|
});
|
|
126
143
|
});
|
|
@@ -86,11 +86,18 @@ describe("createPayment", () => {
|
|
|
86
86
|
})
|
|
87
87
|
);
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
let error;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const response = await liteCheckout.createPayment({
|
|
93
|
+
...new CreatePaymentRequestClass(),
|
|
94
|
+
})
|
|
95
|
+
} catch (e) {
|
|
96
|
+
error = e;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
100
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
94
101
|
});
|
|
95
102
|
|
|
96
103
|
it("createPayment errorCatch", async () => {
|
|
@@ -98,12 +105,19 @@ describe("createPayment", () => {
|
|
|
98
105
|
|
|
99
106
|
fetchSpy.mockRejectedValue("error");
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
let error: ErrorResponse;
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const response = (await liteCheckout.createPayment({
|
|
112
|
+
...new CreatePaymentRequestClass(),
|
|
113
|
+
})) as ErrorResponse;
|
|
114
|
+
} catch (e: any) {
|
|
115
|
+
error = e;
|
|
116
|
+
expect(error.message).toStrictEqual("error");
|
|
117
|
+
expect(error.name).toStrictEqual("catch");
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
105
|
-
expect(response.message).toStrictEqual("error");
|
|
106
|
-
expect(response.name).toStrictEqual("catch");
|
|
107
121
|
expect(liteCheckoutSpy).rejects.toThrow();
|
|
108
122
|
});
|
|
109
123
|
});
|
|
@@ -82,12 +82,19 @@ describe("customerRegister", () => {
|
|
|
82
82
|
status: 400,
|
|
83
83
|
})
|
|
84
84
|
);
|
|
85
|
+
|
|
86
|
+
let error: ErrorResponse;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const response = await liteCheckout.customerRegister(
|
|
90
|
+
"email@gmail.com"
|
|
91
|
+
)
|
|
92
|
+
} catch (e: any) {
|
|
93
|
+
error = e;
|
|
94
|
+
expect(error.code).toStrictEqual("400");
|
|
95
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
96
|
+
}
|
|
85
97
|
|
|
86
|
-
const response = (await liteCheckout.customerRegister(
|
|
87
|
-
"email@gmail.com"
|
|
88
|
-
)) as IErrorResponse;
|
|
89
|
-
expect(response.code).toStrictEqual("400");
|
|
90
|
-
expect(response).toBeInstanceOf(ErrorResponse);
|
|
91
98
|
});
|
|
92
99
|
|
|
93
100
|
it("customerRegister errorCatch", async () => {
|
|
@@ -95,12 +102,19 @@ describe("customerRegister", () => {
|
|
|
95
102
|
|
|
96
103
|
fetchSpy.mockRejectedValue("error");
|
|
97
104
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
let error: ErrorResponse;
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const response = (await liteCheckout.customerRegister(
|
|
109
|
+
"email@gmail.com"
|
|
110
|
+
)) as ErrorResponse;
|
|
111
|
+
} catch (e: any) {
|
|
112
|
+
error = e;
|
|
113
|
+
expect(error.message).toStrictEqual("error");
|
|
114
|
+
expect(error.name).toStrictEqual("catch");
|
|
115
|
+
}
|
|
116
|
+
|
|
101
117
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
102
|
-
expect(response.message).toStrictEqual("error");
|
|
103
|
-
expect(response.name).toStrictEqual("catch");
|
|
104
118
|
expect(liteCheckoutSpy).rejects.toThrow();
|
|
105
119
|
});
|
|
106
120
|
});
|
|
@@ -81,9 +81,15 @@ describe("getBusiness", () => {
|
|
|
81
81
|
})
|
|
82
82
|
);
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
let error: ErrorResponse;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const response = (await liteCheckout.getBusiness()) as IErrorResponse;
|
|
88
|
+
} catch (e: any) {
|
|
89
|
+
error = e;
|
|
90
|
+
expect(error.code).toStrictEqual("400");
|
|
91
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
92
|
+
}
|
|
87
93
|
});
|
|
88
94
|
|
|
89
95
|
it("getBusiness errorCatch", async () => {
|
|
@@ -91,10 +97,17 @@ describe("getBusiness", () => {
|
|
|
91
97
|
|
|
92
98
|
fetchSpy.mockRejectedValue("error");
|
|
93
99
|
|
|
94
|
-
|
|
100
|
+
let error: ErrorResponse;
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const response = (await liteCheckout.getBusiness()) as ErrorResponse;
|
|
104
|
+
} catch (e: any) {
|
|
105
|
+
error = e;
|
|
106
|
+
expect(error.message).toStrictEqual("error");
|
|
107
|
+
expect(error.name).toStrictEqual("catch");
|
|
108
|
+
}
|
|
109
|
+
|
|
95
110
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
96
|
-
expect(response.message).toStrictEqual("error");
|
|
97
|
-
expect(response.name).toStrictEqual("catch");
|
|
98
111
|
expect(liteCheckoutSpy).rejects.toThrow();
|
|
99
112
|
});
|
|
100
113
|
});
|
|
@@ -81,12 +81,18 @@ describe("getCustomerCards", () => {
|
|
|
81
81
|
status: 400,
|
|
82
82
|
})
|
|
83
83
|
);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
|
|
85
|
+
let error: ErrorResponse;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const response = (await liteCheckout.getCustomerCards(
|
|
89
|
+
"1234", "1234"
|
|
90
|
+
)) as IErrorResponse;
|
|
91
|
+
} catch (e: any) {
|
|
92
|
+
error = e;
|
|
93
|
+
expect(error.code).toStrictEqual("400");
|
|
94
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
95
|
+
}
|
|
90
96
|
});
|
|
91
97
|
|
|
92
98
|
it("getCustomerCards errorCatch", async () => {
|
|
@@ -94,12 +100,19 @@ describe("getCustomerCards", () => {
|
|
|
94
100
|
|
|
95
101
|
fetchSpy.mockRejectedValue("error");
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
let error: ErrorResponse;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const response = (await liteCheckout.getCustomerCards(
|
|
107
|
+
"1234", "1234"
|
|
108
|
+
)) as IErrorResponse;
|
|
109
|
+
} catch (e: any) {
|
|
110
|
+
error = e;
|
|
111
|
+
expect(error.message).toStrictEqual("error");
|
|
112
|
+
expect(error.name).toStrictEqual("catch");
|
|
113
|
+
}
|
|
114
|
+
|
|
100
115
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
101
|
-
expect(response.message).toStrictEqual("error");
|
|
102
|
-
expect(response.name).toStrictEqual("catch");
|
|
103
116
|
expect(liteCheckoutSpy).rejects.toThrow();
|
|
104
117
|
});
|
|
105
118
|
});
|
|
@@ -76,11 +76,17 @@ describe("getSkyflowToken", () => {
|
|
|
76
76
|
|
|
77
77
|
liteCheckoutSpy = jest.spyOn(liteCheckout, "getSkyflowTokens");
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
let error: ErrorResponse;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const response = await liteCheckout.getSkyflowTokens({
|
|
83
|
+
...new TokensRequestClass(),
|
|
84
|
+
}) as IErrorResponse;
|
|
85
|
+
} catch (e: any) {
|
|
86
|
+
error = e;
|
|
87
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
88
|
+
expect(error.message).toStrictEqual("Por favor, verifica todos los campos de tu tarjeta");
|
|
89
|
+
}
|
|
84
90
|
});
|
|
85
91
|
|
|
86
92
|
it("getSkyflowTokens error mount fields", async () => {
|
|
@@ -102,11 +108,17 @@ describe("getSkyflowToken", () => {
|
|
|
102
108
|
|
|
103
109
|
liteCheckoutSpy = jest.spyOn(liteCheckout, "getSkyflowTokens");
|
|
104
110
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
let error: ErrorResponse;
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const response = (await liteCheckout.getSkyflowTokens({
|
|
115
|
+
...new TokensRequestClass(),
|
|
116
|
+
})) as IErrorResponse;
|
|
117
|
+
} catch (e: any) {
|
|
118
|
+
error = e;
|
|
119
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
120
|
+
expect(error.message).toStrictEqual("Ocurrió un error al montar los campos de la tarjeta");
|
|
121
|
+
}
|
|
110
122
|
});
|
|
111
123
|
|
|
112
124
|
it("getSkyflowTokens error collect catch", async () => {
|
|
@@ -128,10 +140,16 @@ describe("getSkyflowToken", () => {
|
|
|
128
140
|
|
|
129
141
|
liteCheckoutSpy = jest.spyOn(liteCheckout, "getSkyflowTokens");
|
|
130
142
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
143
|
+
let error: ErrorResponse;
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
const response = (await liteCheckout.getSkyflowTokens({
|
|
147
|
+
...new TokensRequestClass(),
|
|
148
|
+
})) as IErrorResponse;
|
|
149
|
+
} catch (e: any) {
|
|
150
|
+
error = e;
|
|
151
|
+
expect(error.message).toStrictEqual("error");
|
|
152
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
153
|
+
}
|
|
136
154
|
});
|
|
137
155
|
});
|
|
@@ -82,11 +82,17 @@ describe("registerCustomerCard", () => {
|
|
|
82
82
|
})
|
|
83
83
|
);
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
let error: ErrorResponse;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const response = (await liteCheckout.registerCustomerCard(
|
|
89
|
+
"1234", { ...new RegisterCustomerCardRequestClass() }
|
|
90
|
+
)) as IErrorResponse;
|
|
91
|
+
} catch (e: any) {
|
|
92
|
+
error = e;
|
|
93
|
+
expect(error.code).toStrictEqual("400");
|
|
94
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
95
|
+
}
|
|
90
96
|
});
|
|
91
97
|
|
|
92
98
|
it("registerCustomerCard errorCatch", async () => {
|
|
@@ -94,12 +100,19 @@ describe("registerCustomerCard", () => {
|
|
|
94
100
|
|
|
95
101
|
fetchSpy.mockRejectedValue("error");
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
let error: ErrorResponse;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const response = (await liteCheckout.registerCustomerCard(
|
|
107
|
+
"1234", { ...new RegisterCustomerCardRequestClass() }
|
|
108
|
+
)) as IErrorResponse;
|
|
109
|
+
} catch (e: any) {
|
|
110
|
+
error = e;
|
|
111
|
+
expect(error.message).toStrictEqual("error");
|
|
112
|
+
expect(error.name).toStrictEqual("catch");
|
|
113
|
+
}
|
|
114
|
+
|
|
100
115
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
101
|
-
expect(response.message).toStrictEqual("error");
|
|
102
|
-
expect(response.name).toStrictEqual("catch");
|
|
103
116
|
expect(liteCheckoutSpy).rejects.toThrow();
|
|
104
117
|
});
|
|
105
118
|
});
|
|
@@ -84,11 +84,17 @@ describe("startCheckoutRouter", () => {
|
|
|
84
84
|
})
|
|
85
85
|
);
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
let error: ErrorResponse;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const response = (await liteCheckout.startCheckoutRouter({
|
|
91
|
+
...new StartCheckoutRequestClass(),
|
|
92
|
+
})) as IErrorResponse;
|
|
93
|
+
} catch (e: any) {
|
|
94
|
+
error = e;
|
|
95
|
+
expect(error.code).toStrictEqual("400");
|
|
96
|
+
expect(error).toBeInstanceOf(ErrorResponse);
|
|
97
|
+
}
|
|
92
98
|
});
|
|
93
99
|
|
|
94
100
|
it("startCheckoutRouter errorCatch", async () => {
|
|
@@ -96,12 +102,19 @@ describe("startCheckoutRouter", () => {
|
|
|
96
102
|
|
|
97
103
|
fetchSpy.mockRejectedValue("error");
|
|
98
104
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
let error: ErrorResponse;
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const response = (await liteCheckout.startCheckoutRouter({
|
|
109
|
+
...new StartCheckoutRequestClass(),
|
|
110
|
+
})) as IErrorResponse;
|
|
111
|
+
} catch (e: any) {
|
|
112
|
+
error = e;
|
|
113
|
+
expect(error.message).toStrictEqual("error");
|
|
114
|
+
expect(error.name).toStrictEqual("catch");
|
|
115
|
+
}
|
|
116
|
+
|
|
102
117
|
expect(liteCheckoutSpy).toHaveBeenCalled();
|
|
103
|
-
expect(response.message).toStrictEqual("error");
|
|
104
|
-
expect(response.name).toStrictEqual("catch");
|
|
105
118
|
expect(liteCheckoutSpy).rejects.toThrow();
|
|
106
119
|
});
|
|
107
120
|
});
|