washday-sdk 0.0.8 → 0.0.9

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.
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ presets: [
3
+ ['@babel/preset-env', {targets: {node: 'current'}}],
4
+ '@babel/preset-typescript',
5
+ ],
6
+ };
7
+
8
+
@@ -15,9 +15,9 @@ const getProductTaxesPercentage = (productObj, store) => {
15
15
  // If store tax configured and taxExempt is false, return store tax
16
16
  return tax.value;
17
17
  };
18
- const tax1 = getTaxValue(store.taxOne, !productObj.taxExemptOne);
19
- const tax2 = getTaxValue(store.taxTwo, !productObj.taxExemptTwo);
20
- const tax3 = getTaxValue(store.taxThree, !productObj.taxExemptThree);
18
+ const tax1 = getTaxValue(store.taxOne, productObj.taxExemptOne);
19
+ const tax2 = getTaxValue(store.taxTwo, productObj.taxExemptTwo);
20
+ const tax3 = getTaxValue(store.taxThree, productObj.taxExemptThree);
21
21
  return tax1 + tax2 + tax3;
22
22
  };
23
23
  exports.getProductTaxesPercentage = getProductTaxesPercentage;
package/jest.config.js ADDED
File without changes
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "test": "test",
7
+ "test": "jest",
8
8
  "build": "tsc",
9
9
  "publish": "npm run build && npm publish --access public"
10
10
  },
@@ -14,6 +14,11 @@
14
14
  "author": "Washday",
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
+ "@babel/core": "^7.24.4",
18
+ "@babel/preset-env": "^7.24.4",
19
+ "@babel/preset-typescript": "^7.24.1",
20
+ "babel-jest": "^29.7.0",
21
+ "jest": "^29.7.0",
17
22
  "typescript": "^5.4.4"
18
23
  },
19
24
  "dependencies": {
@@ -0,0 +1,399 @@
1
+ // myModule.test.js
2
+ import { calculateOrderTotal } from "./index";
3
+
4
+ describe("sum function", () => {
5
+ const ORDER_DEMO = {
6
+ orderDto: {
7
+ deliveryDateFormatted: "lunes 08 abr.",
8
+ pickupInfo: null,
9
+ deliveryInfo: {
10
+ date: "2024-04-09T05:00:00.000Z",
11
+ fromTime: "2024-04-08T21:00:00.000Z",
12
+ },
13
+ express: false,
14
+ products: [
15
+ {
16
+ extraAmount: 0,
17
+ type: "weight",
18
+ showInApp: true,
19
+ order: 0,
20
+ invoice_description: "",
21
+ invoice_product_key: "",
22
+ invoice_product_unit_key: "",
23
+ invoice_product_unit_name: "",
24
+ productType: "storeProduct",
25
+ _id: "62d186387ec9330016319594",
26
+ name: "Lavado por kilo",
27
+ price: 17,
28
+ expressPrice: 20,
29
+ pieces: "1",
30
+ sku: "lavxkilo",
31
+ overlayText: "Lavado por kilo",
32
+ image: "6184782c3927a40018e36dea",
33
+ taxExemptOne: false,
34
+ taxExemptTwo: false,
35
+ taxExemptThree: false,
36
+ isActive: true,
37
+ store: "629c267812db5b001692adae",
38
+ owner: "629c267812db5b001692ada4",
39
+ productSupplies: [
40
+ {
41
+ usageAmount: 25,
42
+ _id: "62d6151fac2fc200166d0304",
43
+ supplyId: "62d35942c642440016cfcda8",
44
+ },
45
+ ],
46
+ __v: 1,
47
+ discountAmount: 0,
48
+ quantity: 3.7,
49
+ productId: "62d186387ec9330016319594",
50
+ qty: 3.7,
51
+ },
52
+ ],
53
+ taxesType: "included",
54
+ total: 62.9,
55
+ customer: "66147eecae83bb001540dd96",
56
+ store: "629c267812db5b001692adae",
57
+ paymentMethod: "delivery",
58
+ notifyBy: "none",
59
+ pickup: false,
60
+ delivery: false,
61
+ phone: "",
62
+ email: "",
63
+ address: "",
64
+ notes: "",
65
+ privateNotes: "",
66
+ creditApplied: 0,
67
+ amountPaid: 0,
68
+ customerInfo: {
69
+ password: "",
70
+ google: false,
71
+ facebook: false,
72
+ apple: false,
73
+ useStoreApp: false,
74
+ discount: 0,
75
+ credit: 0,
76
+ isActive: true,
77
+ createdDate: "2024-04-08T23:34:04.586Z",
78
+ stripeCustomerId: "",
79
+ invoiceInfo: {
80
+ _id: "66147eecae83bb001540dd95",
81
+ legal_name: "",
82
+ tax_system: "",
83
+ zipCode: "",
84
+ },
85
+ _id: "66147eecae83bb001540dd96",
86
+ name: "Carlos Piña 🍍",
87
+ phone: "",
88
+ address: "",
89
+ notes: "",
90
+ privateNotes: "",
91
+ rfc: "",
92
+ createdBy: "62d194d77ec933001631e831",
93
+ createdIn: "629c267812db5b001692adae",
94
+ company: "629c267712db5b001692ad9e",
95
+ addresses: [],
96
+ paymentMethods: [],
97
+ __v: 0,
98
+ title: "Carlos Piña 🍍",
99
+ id: "66147eecae83bb001540dd96",
100
+ },
101
+ customerName: "Carlos Piña 🍍",
102
+ pickingUpDateTime: null,
103
+ cleanedDateTime: null,
104
+ readyDateTime: null,
105
+ deliveringDateTime: null,
106
+ collectedDateTime: null,
107
+ cancelledDateTime: null,
108
+ paidDateTime: null,
109
+ status: "cleaning",
110
+ prepaidAmount: 0,
111
+ prepaidPaymentMethod: "",
112
+ customerDiscount: 0,
113
+ productTotal: 54.22,
114
+ taxesTotal: 8.68,
115
+ productTotalWithoutDiscount: 54.22,
116
+ totalDiscountAmount: 0,
117
+ shippingServiceTotal: 0,
118
+ discountsToApply: [],
119
+ usePrepaid: false,
120
+ cashierBox: "629c267812db5b001692adb3",
121
+ discountCode: "",
122
+ buyAndGetProducts: [],
123
+ deliveryRoute: null,
124
+ pickupRoute: null,
125
+ createdDate: "2024-04-08T23:34:48.950Z",
126
+ },
127
+ customer: {
128
+ customer: {
129
+ password: "",
130
+ google: false,
131
+ facebook: false,
132
+ apple: false,
133
+ useStoreApp: false,
134
+ discount: 0,
135
+ credit: 0,
136
+ isActive: true,
137
+ createdDate: "2024-04-08T23:34:04.586Z",
138
+ stripeCustomerId: "",
139
+ invoiceInfo: {
140
+ _id: "66147eecae83bb001540dd95",
141
+ legal_name: "",
142
+ tax_system: "",
143
+ zipCode: "",
144
+ },
145
+ _id: "66147eecae83bb001540dd96",
146
+ name: "Carlos Piña 🍍",
147
+ phone: "",
148
+ address: "",
149
+ notes: "",
150
+ privateNotes: "",
151
+ rfc: "",
152
+ createdBy: "62d194d77ec933001631e831",
153
+ createdIn: "629c267812db5b001692adae",
154
+ company: "629c267712db5b001692ad9e",
155
+ addresses: [],
156
+ paymentMethods: [],
157
+ __v: 0,
158
+ },
159
+ },
160
+ store: {
161
+ taxesType: "included",
162
+ notificationConfig: {
163
+ notifyOrderCreated: false,
164
+ notifyPickedUp: false,
165
+ notifyCleaned: true,
166
+ notifyCollected: false,
167
+ notifyDelivered: false,
168
+ notifyOwnerOnOrderCreated: false,
169
+ notifyEmail: "",
170
+ _id: "62a2d05fd0a7c800160869bc",
171
+ },
172
+ paymentConfig: {
173
+ defaultPaymentMethod: "delivery",
174
+ _id: "63650e8dcfa0e30016729776",
175
+ },
176
+ orderPageConfig: {
177
+ defaultDeliveryDate: "0",
178
+ defaultDeliveryTime: "18:00",
179
+ defaultNotifyMethod: "none",
180
+ printTicketAfterOrder: true,
181
+ shippingServiceCost: 0,
182
+ showProductSearchBarWeb: true,
183
+ _id: "6407b53301a1aa00141b217e",
184
+ },
185
+ _id: "629c267812db5b001692adae",
186
+ name: "Clean & Go",
187
+ phone: "9983524573",
188
+ inventory: [],
189
+ discountCodes: [
190
+ {
191
+ type: "percentage",
192
+ value: 14,
193
+ products: [
194
+ "62d1893f7ec933001631ab24",
195
+ "62d189697ec933001631acab",
196
+ "62d19a287ec933001632156f",
197
+ "62d199117ec9330016320ec0",
198
+ "62d198e07ec9330016320cc7",
199
+ "62d191d67ec933001631cd76",
200
+ "62d191747ec933001631c9cc",
201
+ "62d191ad7ec933001631cbef",
202
+ ],
203
+ applyToAllProducts: false,
204
+ applyOnceOnOrder: false,
205
+ hasUseLimit: false,
206
+ useLimitQty: 0,
207
+ usedCounter: 0,
208
+ onePerCustomer: true,
209
+ isActive: true,
210
+ buyAndGetConditions: [],
211
+ _id: "62d1ae1b7ec9330016328166",
212
+ name: "Anfitriones Airbnb",
213
+ code: "AIRBNBANF",
214
+ fromDate: "2022-07-01T05:00:00.000Z",
215
+ toDate: "2022-08-01T04:59:59.999Z",
216
+ fromTime: "00:00",
217
+ toTime: "23:59",
218
+ createdBy: "629c267812db5b001692ada4",
219
+ createdAt: "2022-07-15T18:12:43.506Z",
220
+ updatedAt: "2022-07-15T18:12:43.506Z",
221
+ },
222
+ {
223
+ type: "percentage",
224
+ value: 20,
225
+ products: [],
226
+ applyToAllProducts: true,
227
+ applyOnceOnOrder: false,
228
+ hasUseLimit: false,
229
+ useLimitQty: 0,
230
+ usedCounter: 0,
231
+ onePerCustomer: true,
232
+ isActive: true,
233
+ buyAndGetConditions: [],
234
+ _id: "635821305b689d0016c97f8c",
235
+ name: "Descuento por comentarios",
236
+ code: "20DESC01",
237
+ fromDate: "2022-01-01T05:00:00.000Z",
238
+ toDate: "2023-01-01T04:59:59.999Z",
239
+ fromTime: "00:00",
240
+ toTime: "23:59",
241
+ createdBy: "629c267812db5b001692ada4",
242
+ createdAt: "2022-10-25T17:47:28.314Z",
243
+ updatedAt: "2022-10-25T17:47:28.314Z",
244
+ },
245
+ {
246
+ type: "percentage",
247
+ value: 20,
248
+ products: [],
249
+ applyToAllProducts: true,
250
+ applyOnceOnOrder: false,
251
+ hasUseLimit: false,
252
+ useLimitQty: 0,
253
+ usedCounter: 0,
254
+ onePerCustomer: true,
255
+ isActive: true,
256
+ buyAndGetConditions: [],
257
+ _id: "6359c5d21332cf00168c5008",
258
+ name: "Descuento por comentario",
259
+ code: "20DESC02",
260
+ fromDate: "2022-01-01T05:00:00.000Z",
261
+ toDate: "2023-01-01T04:59:59.999Z",
262
+ fromTime: "00:00",
263
+ toTime: "23:59",
264
+ createdBy: "62d194d77ec933001631e831",
265
+ createdAt: "2022-10-26T23:42:10.732Z",
266
+ updatedAt: "2022-10-26T23:42:10.732Z",
267
+ },
268
+ {
269
+ type: "percentage",
270
+ value: 19,
271
+ products: [],
272
+ applyToAllProducts: true,
273
+ applyOnceOnOrder: false,
274
+ hasUseLimit: false,
275
+ useLimitQty: 0,
276
+ usedCounter: 0,
277
+ onePerCustomer: true,
278
+ isActive: true,
279
+ buyAndGetConditions: [],
280
+ _id: "6359c5ef1332cf00168c516d",
281
+ name: "Descuento por comentario",
282
+ code: "20DESC03",
283
+ fromDate: "2022-01-01T05:00:00.000Z",
284
+ toDate: "2023-01-01T04:59:59.999Z",
285
+ fromTime: "00:00",
286
+ toTime: "23:59",
287
+ createdBy: "62d194d77ec933001631e831",
288
+ createdAt: "2022-10-26T23:42:39.555Z",
289
+ updatedAt: "2022-10-26T23:42:39.555Z",
290
+ },
291
+ {
292
+ type: "percentage",
293
+ value: 20,
294
+ products: [],
295
+ applyToAllProducts: true,
296
+ applyOnceOnOrder: false,
297
+ hasUseLimit: false,
298
+ useLimitQty: 0,
299
+ usedCounter: 0,
300
+ onePerCustomer: true,
301
+ isActive: true,
302
+ buyAndGetConditions: [],
303
+ _id: "6359c60c1332cf00168c52c6",
304
+ name: "Descuento por comentario",
305
+ code: "20DESC04",
306
+ fromDate: "2022-01-01T05:00:00.000Z",
307
+ toDate: "2023-01-01T04:59:59.999Z",
308
+ fromTime: "00:00",
309
+ toTime: "23:59",
310
+ createdBy: "62d194d77ec933001631e831",
311
+ createdAt: "2022-10-26T23:43:08.577Z",
312
+ updatedAt: "2022-10-26T23:43:08.577Z",
313
+ },
314
+ {
315
+ type: "percentage",
316
+ value: 20,
317
+ products: [],
318
+ applyToAllProducts: true,
319
+ applyOnceOnOrder: false,
320
+ hasUseLimit: false,
321
+ useLimitQty: 0,
322
+ usedCounter: 0,
323
+ onePerCustomer: true,
324
+ isActive: true,
325
+ buyAndGetConditions: [],
326
+ _id: "6359c6261332cf00168c5468",
327
+ name: "Descuento por comentario",
328
+ code: "20DESC05",
329
+ fromDate: "2022-01-01T05:00:00.000Z",
330
+ toDate: "2023-01-01T04:59:59.999Z",
331
+ fromTime: "00:00",
332
+ toTime: "23:59",
333
+ createdBy: "62d194d77ec933001631e831",
334
+ createdAt: "2022-10-26T23:43:34.663Z",
335
+ updatedAt: "2022-10-26T23:43:34.663Z",
336
+ },
337
+ ],
338
+ taxOne: {
339
+ _id: "658bb2f376aa7b001482888c",
340
+ value: 16,
341
+ name: "IVA",
342
+ },
343
+ taxThree: null,
344
+ taxTwo: null,
345
+ },
346
+ hasShippingCost: false,
347
+ storeDiscounts: [],
348
+ discountCodeObj: null,
349
+ };
350
+ beforeEach(() => {
351
+ // Run this setup function before each test case
352
+ });
353
+ it("test calculateOrderTotal taxes included", () => {
354
+ // Test case
355
+ const {
356
+ orderDto,
357
+ customer,
358
+ store,
359
+ hasShippingCost,
360
+ storeDiscounts,
361
+ discountCodeObj,
362
+ } = ORDER_DEMO;
363
+
364
+ const { ...informationNewPackage } = calculateOrderTotal(
365
+ orderDto,
366
+ { customer },
367
+ store,
368
+ orderDto.delivery || orderDto.pickup,
369
+ // storeDiscounts.data?.discounts || [],
370
+ storeDiscounts,
371
+ discountCodeObj
372
+ );
373
+
374
+ const res = {
375
+ totalDiscountAmount: informationNewPackage.totalDiscountAmount,
376
+ totalQuantity: informationNewPackage.totalQuantity,
377
+ totalImportWithDiscount: informationNewPackage.productTotal,
378
+ totalImportWithoutDiscount:
379
+ informationNewPackage.productTotalWithoutDiscount,
380
+ totalImporTaxes: informationNewPackage.taxesTotal,
381
+ shippingCost: informationNewPackage.shippingServiceTotal,
382
+ };
383
+ expect(res).toEqual({
384
+ totalDiscountAmount: 0,
385
+ totalQuantity: 3.7,
386
+ totalImportWithDiscount: 54.22,
387
+ totalImportWithoutDiscount: 54.22,
388
+ totalImporTaxes: 8.68,
389
+ shippingCost: 0,
390
+ });
391
+ });
392
+
393
+ it("should return 0 when adding two zeros", () => {
394
+ // Test case
395
+ expect(sum(0, 0)).toBe(0);
396
+ });
397
+
398
+ // Add more test cases as needed
399
+ });
@@ -19,9 +19,9 @@ export const getProductTaxesPercentage = (productObj: IOrderProduct, store: ISto
19
19
  return tax.value;
20
20
  };
21
21
 
22
- const tax1 = getTaxValue(store.taxOne, !productObj.taxExemptOne);
23
- const tax2 = getTaxValue(store.taxTwo, !productObj.taxExemptTwo);
24
- const tax3 = getTaxValue(store.taxThree, !productObj.taxExemptThree);
22
+ const tax1 = getTaxValue(store.taxOne, productObj.taxExemptOne);
23
+ const tax2 = getTaxValue(store.taxTwo, productObj.taxExemptTwo);
24
+ const tax3 = getTaxValue(store.taxThree, productObj.taxExemptThree);
25
25
 
26
26
  return tax1 + tax2 + tax3;
27
27
  };