@stacksjs/commerce 0.70.55 → 0.70.56
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/package.json +10 -7
- package/src/carts/destroy.ts +0 -54
- package/src/carts/fetch.ts +0 -20
- package/src/carts/index.ts +0 -13
- package/src/carts/store.ts +0 -75
- package/src/carts/update.ts +0 -78
- package/src/coupons/destroy.ts +0 -49
- package/src/coupons/fetch.ts +0 -510
- package/src/coupons/index.ts +0 -30
- package/src/coupons/store.ts +0 -46
- package/src/coupons/update.ts +0 -147
- package/src/customers/destroy.ts +0 -62
- package/src/customers/fetch.ts +0 -20
- package/src/customers/index.ts +0 -17
- package/src/customers/store.ts +0 -45
- package/src/customers/update.ts +0 -44
- package/src/devices/destroy.ts +0 -54
- package/src/devices/export.ts +0 -98
- package/src/devices/fetch.ts +0 -125
- package/src/devices/index.ts +0 -31
- package/src/devices/store.ts +0 -82
- package/src/devices/update.ts +0 -125
- package/src/errors/destroy.ts +0 -54
- package/src/errors/fetch.ts +0 -197
- package/src/errors/index.ts +0 -28
- package/src/errors/update.ts +0 -116
- package/src/gift-cards/destroy.ts +0 -87
- package/src/gift-cards/fetch.ts +0 -431
- package/src/gift-cards/index.ts +0 -26
- package/src/gift-cards/store.ts +0 -56
- package/src/gift-cards/update.ts +0 -102
- package/src/index.ts +0 -78
- package/src/orders/destroy.ts +0 -111
- package/src/orders/events.ts +0 -121
- package/src/orders/export.ts +0 -158
- package/src/orders/fetch.ts +0 -379
- package/src/orders/guards.ts +0 -261
- package/src/orders/index.ts +0 -91
- package/src/orders/place-order.ts +0 -274
- package/src/orders/store.ts +0 -51
- package/src/orders/totals.ts +0 -190
- package/src/orders/update.ts +0 -164
- package/src/orders/webhook.ts +0 -312
- package/src/payments/destroy.ts +0 -56
- package/src/payments/fetch.ts +0 -288
- package/src/payments/index.ts +0 -16
- package/src/payments/store.ts +0 -63
- package/src/payments/update.ts +0 -52
- package/src/product.ts +0 -0
- package/src/products/categories/destroy.ts +0 -103
- package/src/products/categories/fetch.ts +0 -285
- package/src/products/categories/index.ts +0 -36
- package/src/products/categories/store.ts +0 -87
- package/src/products/categories/update.ts +0 -251
- package/src/products/index.ts +0 -35
- package/src/products/items/destroy.ts +0 -54
- package/src/products/items/fetch.ts +0 -282
- package/src/products/items/index.ts +0 -26
- package/src/products/items/store.ts +0 -84
- package/src/products/items/update.ts +0 -324
- package/src/products/manufacturers/destroy.ts +0 -56
- package/src/products/manufacturers/fetch.ts +0 -117
- package/src/products/manufacturers/index.ts +0 -24
- package/src/products/manufacturers/store.ts +0 -82
- package/src/products/manufacturers/update.ts +0 -113
- package/src/products/reviews/destroy.ts +0 -56
- package/src/products/reviews/fetch.ts +0 -63
- package/src/products/reviews/index.ts +0 -25
- package/src/products/reviews/store.ts +0 -46
- package/src/products/reviews/update.ts +0 -82
- package/src/products/units/destroy.ts +0 -56
- package/src/products/units/fetch.ts +0 -20
- package/src/products/units/index.ts +0 -13
- package/src/products/units/store.ts +0 -162
- package/src/products/units/update.ts +0 -159
- package/src/products/variants/destroy.ts +0 -56
- package/src/products/variants/fetch.ts +0 -20
- package/src/products/variants/index.ts +0 -21
- package/src/products/variants/store.ts +0 -136
- package/src/products/variants/update.ts +0 -104
- package/src/receipts/destroy.ts +0 -54
- package/src/receipts/export.ts +0 -0
- package/src/receipts/fetch.ts +0 -222
- package/src/receipts/index.ts +0 -24
- package/src/receipts/printer.ts +0 -69
- package/src/receipts/store.ts +0 -69
- package/src/receipts/update.ts +0 -124
- package/src/shippings/delivery-routes/destroy.ts +0 -54
- package/src/shippings/delivery-routes/fetch.ts +0 -42
- package/src/shippings/delivery-routes/index.ts +0 -26
- package/src/shippings/delivery-routes/store.ts +0 -69
- package/src/shippings/delivery-routes/update.ts +0 -120
- package/src/shippings/digital-deliveries/destroy.ts +0 -111
- package/src/shippings/digital-deliveries/fetch.ts +0 -20
- package/src/shippings/digital-deliveries/index.ts +0 -26
- package/src/shippings/digital-deliveries/store.ts +0 -76
- package/src/shippings/digital-deliveries/update.ts +0 -129
- package/src/shippings/drivers/destroy.ts +0 -78
- package/src/shippings/drivers/fetch.ts +0 -20
- package/src/shippings/drivers/index.ts +0 -24
- package/src/shippings/drivers/store.ts +0 -69
- package/src/shippings/drivers/update.ts +0 -117
- package/src/shippings/index.ts +0 -39
- package/src/shippings/license-keys/destroy.ts +0 -111
- package/src/shippings/license-keys/fetch.ts +0 -20
- package/src/shippings/license-keys/index.ts +0 -26
- package/src/shippings/license-keys/store.ts +0 -77
- package/src/shippings/license-keys/update.ts +0 -117
- package/src/shippings/shipping-methods/destroy.ts +0 -111
- package/src/shippings/shipping-methods/fetch.ts +0 -62
- package/src/shippings/shipping-methods/index.ts +0 -28
- package/src/shippings/shipping-methods/store.ts +0 -123
- package/src/shippings/shipping-methods/update.ts +0 -120
- package/src/shippings/shipping-rates/destroy.ts +0 -102
- package/src/shippings/shipping-rates/fetch.ts +0 -320
- package/src/shippings/shipping-rates/index.ts +0 -36
- package/src/shippings/shipping-rates/store.ts +0 -102
- package/src/shippings/shipping-rates/update.ts +0 -139
- package/src/shippings/shipping-zones/destroy.ts +0 -111
- package/src/shippings/shipping-zones/fetch.ts +0 -96
- package/src/shippings/shipping-zones/index.ts +0 -26
- package/src/shippings/shipping-zones/store.ts +0 -74
- package/src/shippings/shipping-zones/update.ts +0 -156
- package/src/tax/destroy.ts +0 -54
- package/src/tax/fetch.ts +0 -20
- package/src/tax/index.ts +0 -24
- package/src/tax/store.ts +0 -69
- package/src/tax/update.ts +0 -119
- package/src/tests/coupons.test.ts +0 -90
- package/src/tests/customers.test.ts +0 -39
- package/src/tests/device.test.ts +0 -111
- package/src/tests/digitals.test.ts +0 -31
- package/src/tests/drivers.test.ts +0 -25
- package/src/tests/gift-cards.test.ts +0 -36
- package/src/tests/license.test.ts +0 -31
- package/src/tests/manufacturers.test.ts +0 -80
- package/src/tests/orders.test.ts +0 -25
- package/src/tests/payments.test.ts +0 -75
- package/src/tests/rates.test.ts +0 -367
- package/src/tests/receipts.test.ts +0 -287
- package/src/tests/restaurant.test.ts +0 -522
- package/src/tests/reviews.test.ts +0 -165
- package/src/tests/routes.test.ts +0 -51
- package/src/tests/setup.ts +0 -149
- package/src/tests/shipping.test.ts +0 -88
- package/src/tests/tax.test.ts +0 -25
- package/src/tests/units.test.ts +0 -110
- package/src/tests/variants.test.ts +0 -133
- package/src/tests/waitlist.test.ts +0 -303
- package/src/tests/zones.test.ts +0 -86
- package/src/types.ts +0 -312
- package/src/utils/typed-stats.ts +0 -67
- package/src/waitlists/index.ts +0 -19
- package/src/waitlists/products/destroy.ts +0 -65
- package/src/waitlists/products/export.ts +0 -113
- package/src/waitlists/products/fetch.ts +0 -362
- package/src/waitlists/products/index.ts +0 -33
- package/src/waitlists/products/store.ts +0 -112
- package/src/waitlists/products/update.ts +0 -125
- package/src/waitlists/restaurant/destroy.ts +0 -65
- package/src/waitlists/restaurant/export.ts +0 -107
- package/src/waitlists/restaurant/fetch.ts +0 -538
- package/src/waitlists/restaurant/index.ts +0 -43
- package/src/waitlists/restaurant/store.ts +0 -109
- package/src/waitlists/restaurant/update.ts +0 -198
- /package/dist/{src/coupons → coupons}/destroy.d.ts +0 -0
- /package/dist/{src/coupons → coupons}/fetch.d.ts +0 -0
- /package/dist/{src/coupons → coupons}/index.d.ts +0 -0
- /package/dist/{src/coupons → coupons}/store.d.ts +0 -0
- /package/dist/{src/coupons → coupons}/update.d.ts +0 -0
- /package/dist/{src/customers → customers}/destroy.d.ts +0 -0
- /package/dist/{src/customers → customers}/fetch.d.ts +0 -0
- /package/dist/{src/customers → customers}/index.d.ts +0 -0
- /package/dist/{src/customers → customers}/store.d.ts +0 -0
- /package/dist/{src/customers → customers}/update.d.ts +0 -0
- /package/dist/{src/devices → devices}/destroy.d.ts +0 -0
- /package/dist/{src/devices → devices}/export.d.ts +0 -0
- /package/dist/{src/devices → devices}/fetch.d.ts +0 -0
- /package/dist/{src/devices → devices}/index.d.ts +0 -0
- /package/dist/{src/devices → devices}/store.d.ts +0 -0
- /package/dist/{src/devices → devices}/update.d.ts +0 -0
- /package/dist/{src/errors → errors}/destroy.d.ts +0 -0
- /package/dist/{src/errors → errors}/fetch.d.ts +0 -0
- /package/dist/{src/errors → errors}/index.d.ts +0 -0
- /package/dist/{src/errors → errors}/update.d.ts +0 -0
- /package/dist/{src/gift-cards → gift-cards}/destroy.d.ts +0 -0
- /package/dist/{src/gift-cards → gift-cards}/fetch.d.ts +0 -0
- /package/dist/{src/gift-cards → gift-cards}/index.d.ts +0 -0
- /package/dist/{src/gift-cards → gift-cards}/store.d.ts +0 -0
- /package/dist/{src/gift-cards → gift-cards}/update.d.ts +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/orders → orders}/destroy.d.ts +0 -0
- /package/dist/{src/orders → orders}/events.d.ts +0 -0
- /package/dist/{src/orders → orders}/export.d.ts +0 -0
- /package/dist/{src/orders → orders}/fetch.d.ts +0 -0
- /package/dist/{src/orders → orders}/guards.d.ts +0 -0
- /package/dist/{src/orders → orders}/index.d.ts +0 -0
- /package/dist/{src/orders → orders}/place-order.d.ts +0 -0
- /package/dist/{src/orders → orders}/store.d.ts +0 -0
- /package/dist/{src/orders → orders}/totals.d.ts +0 -0
- /package/dist/{src/orders → orders}/update.d.ts +0 -0
- /package/dist/{src/orders → orders}/webhook.d.ts +0 -0
- /package/dist/{src/payments → payments}/destroy.d.ts +0 -0
- /package/dist/{src/payments → payments}/fetch.d.ts +0 -0
- /package/dist/{src/payments → payments}/index.d.ts +0 -0
- /package/dist/{src/payments → payments}/store.d.ts +0 -0
- /package/dist/{src/payments → payments}/update.d.ts +0 -0
- /package/dist/{src/products → products}/categories/destroy.d.ts +0 -0
- /package/dist/{src/products → products}/categories/fetch.d.ts +0 -0
- /package/dist/{src/products → products}/categories/index.d.ts +0 -0
- /package/dist/{src/products → products}/categories/store.d.ts +0 -0
- /package/dist/{src/products → products}/categories/update.d.ts +0 -0
- /package/dist/{src/products → products}/index.d.ts +0 -0
- /package/dist/{src/products → products}/items/destroy.d.ts +0 -0
- /package/dist/{src/products → products}/items/fetch.d.ts +0 -0
- /package/dist/{src/products → products}/items/index.d.ts +0 -0
- /package/dist/{src/products → products}/items/store.d.ts +0 -0
- /package/dist/{src/products → products}/items/update.d.ts +0 -0
- /package/dist/{src/products → products}/manufacturers/destroy.d.ts +0 -0
- /package/dist/{src/products → products}/manufacturers/fetch.d.ts +0 -0
- /package/dist/{src/products → products}/manufacturers/index.d.ts +0 -0
- /package/dist/{src/products → products}/manufacturers/store.d.ts +0 -0
- /package/dist/{src/products → products}/manufacturers/update.d.ts +0 -0
- /package/dist/{src/products → products}/reviews/destroy.d.ts +0 -0
- /package/dist/{src/products → products}/reviews/fetch.d.ts +0 -0
- /package/dist/{src/products → products}/reviews/index.d.ts +0 -0
- /package/dist/{src/products → products}/reviews/store.d.ts +0 -0
- /package/dist/{src/products → products}/reviews/update.d.ts +0 -0
- /package/dist/{src/products → products}/units/destroy.d.ts +0 -0
- /package/dist/{src/products → products}/units/fetch.d.ts +0 -0
- /package/dist/{src/products → products}/units/index.d.ts +0 -0
- /package/dist/{src/products → products}/units/store.d.ts +0 -0
- /package/dist/{src/products → products}/units/update.d.ts +0 -0
- /package/dist/{src/products → products}/variants/destroy.d.ts +0 -0
- /package/dist/{src/products → products}/variants/fetch.d.ts +0 -0
- /package/dist/{src/products → products}/variants/index.d.ts +0 -0
- /package/dist/{src/products → products}/variants/store.d.ts +0 -0
- /package/dist/{src/products → products}/variants/update.d.ts +0 -0
- /package/dist/{src/receipts → receipts}/destroy.d.ts +0 -0
- /package/dist/{src/receipts → receipts}/fetch.d.ts +0 -0
- /package/dist/{src/receipts → receipts}/index.d.ts +0 -0
- /package/dist/{src/receipts → receipts}/store.d.ts +0 -0
- /package/dist/{src/receipts → receipts}/update.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/delivery-routes/destroy.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/delivery-routes/fetch.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/delivery-routes/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/delivery-routes/store.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/delivery-routes/update.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/digital-deliveries/destroy.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/digital-deliveries/fetch.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/digital-deliveries/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/digital-deliveries/store.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/digital-deliveries/update.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/drivers/destroy.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/drivers/fetch.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/drivers/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/drivers/store.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/drivers/update.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/license-keys/destroy.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/license-keys/fetch.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/license-keys/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/license-keys/store.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/license-keys/update.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-methods/destroy.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-methods/fetch.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-methods/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-methods/store.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-methods/update.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-rates/destroy.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-rates/fetch.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-rates/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-rates/store.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-rates/update.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-zones/destroy.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-zones/fetch.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-zones/index.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-zones/store.d.ts +0 -0
- /package/dist/{src/shippings → shippings}/shipping-zones/update.d.ts +0 -0
- /package/dist/{src/tax → tax}/destroy.d.ts +0 -0
- /package/dist/{src/tax → tax}/fetch.d.ts +0 -0
- /package/dist/{src/tax → tax}/index.d.ts +0 -0
- /package/dist/{src/tax → tax}/store.d.ts +0 -0
- /package/dist/{src/tax → tax}/update.d.ts +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{src/utils → utils}/typed-stats.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/index.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/products/destroy.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/products/fetch.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/products/index.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/products/store.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/products/update.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/restaurant/destroy.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/restaurant/fetch.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/restaurant/index.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/restaurant/store.d.ts +0 -0
- /package/dist/{src/waitlists → waitlists}/restaurant/update.d.ts +0 -0
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
type ReceiptJsonResponse = ModelRow<typeof Receipt>
|
|
2
|
-
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
3
|
-
import { refreshDatabase } from './setup'
|
|
4
|
-
import { bulkDestroy } from '../receipts/destroy'
|
|
5
|
-
import { fetchAll, fetchPrintsPerHour } from '../receipts/fetch'
|
|
6
|
-
import { bulkStore } from '../receipts/store'
|
|
7
|
-
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
await refreshDatabase()
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
describe('Print Log Module', () => {
|
|
13
|
-
describe('store', () => {
|
|
14
|
-
it('should return 0 when trying to bulk store an empty array', async () => {
|
|
15
|
-
const count = await bulkStore([])
|
|
16
|
-
expect(count).toBe(0)
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
describe('destroy', () => {
|
|
21
|
-
it('should return 0 when trying to delete an empty array of print logs', async () => {
|
|
22
|
-
// Try to delete with an empty array
|
|
23
|
-
const deletedCount = await bulkDestroy([])
|
|
24
|
-
expect(deletedCount).toBe(0)
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('fetch', () => {
|
|
29
|
-
it('should fetch all print logs', async () => {
|
|
30
|
-
// Create test print logs
|
|
31
|
-
const requests = [
|
|
32
|
-
{
|
|
33
|
-
printer: 'HP LaserJet',
|
|
34
|
-
document: 'invoice.pdf',
|
|
35
|
-
timestamp: Date.now(),
|
|
36
|
-
status: 'success',
|
|
37
|
-
size: 1024,
|
|
38
|
-
pages: 5,
|
|
39
|
-
duration: 30,
|
|
40
|
-
uuid: '1234567890',
|
|
41
|
-
print_device_id: 1,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
printer: 'Epson Printer',
|
|
45
|
-
document: 'report.pdf',
|
|
46
|
-
timestamp: Date.now(),
|
|
47
|
-
status: 'warning',
|
|
48
|
-
size: 2048,
|
|
49
|
-
pages: 10,
|
|
50
|
-
duration: 45,
|
|
51
|
-
uuid: '1234567890',
|
|
52
|
-
print_device_id: 1,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
printer: 'Canon Printer',
|
|
56
|
-
document: 'document.pdf',
|
|
57
|
-
timestamp: Date.now(),
|
|
58
|
-
status: 'failed',
|
|
59
|
-
size: 512,
|
|
60
|
-
pages: 2,
|
|
61
|
-
duration: 15,
|
|
62
|
-
uuid: '1234567890',
|
|
63
|
-
print_device_id: 1,
|
|
64
|
-
},
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
// Create the print logs
|
|
68
|
-
await bulkStore(requests)
|
|
69
|
-
|
|
70
|
-
// Fetch all print logs
|
|
71
|
-
const allReceipts = await fetchAll()
|
|
72
|
-
expect(allReceipts).toBeDefined()
|
|
73
|
-
expect(allReceipts.length).toBe(3)
|
|
74
|
-
expect(allReceipts.map((p: ReceiptJsonResponse) => p.printer)).toContain('HP LaserJet')
|
|
75
|
-
expect(allReceipts.map((p: ReceiptJsonResponse) => p.printer)).toContain('Epson Printer')
|
|
76
|
-
expect(allReceipts.map((p: ReceiptJsonResponse) => p.printer)).toContain('Canon Printer')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should calculate prints per hour statistics within a date range', async () => {
|
|
80
|
-
// Use a fixed timestamp for today at midnight
|
|
81
|
-
const today = new Date()
|
|
82
|
-
today.setHours(0, 0, 0, 0)
|
|
83
|
-
const startDate = today.getTime()
|
|
84
|
-
const endDate = startDate + 86399999 // End of today
|
|
85
|
-
|
|
86
|
-
// Create test receipts with different timestamps
|
|
87
|
-
const requests = [
|
|
88
|
-
{
|
|
89
|
-
printer: 'HP LaserJet',
|
|
90
|
-
document: 'invoice.pdf',
|
|
91
|
-
timestamp: startDate + (2 * 3600000), // 2 AM
|
|
92
|
-
status: 'success',
|
|
93
|
-
size: 1024,
|
|
94
|
-
pages: 5,
|
|
95
|
-
duration: 30,
|
|
96
|
-
uuid: '1234567890',
|
|
97
|
-
print_device_id: 1,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
printer: 'Epson Printer',
|
|
101
|
-
document: 'report.pdf',
|
|
102
|
-
timestamp: startDate + (2 * 3600000), // 2 AM
|
|
103
|
-
status: 'success',
|
|
104
|
-
size: 2048,
|
|
105
|
-
pages: 10,
|
|
106
|
-
duration: 45,
|
|
107
|
-
uuid: '1234567890',
|
|
108
|
-
print_device_id: 1,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
printer: 'Canon Printer',
|
|
112
|
-
document: 'document.pdf',
|
|
113
|
-
timestamp: startDate + (14 * 3600000), // 2 PM
|
|
114
|
-
status: 'warning',
|
|
115
|
-
size: 512,
|
|
116
|
-
pages: 2,
|
|
117
|
-
duration: 15,
|
|
118
|
-
uuid: '1234567890',
|
|
119
|
-
print_device_id: 1,
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
printer: 'Brother Printer',
|
|
123
|
-
document: 'error.pdf',
|
|
124
|
-
timestamp: startDate + (14 * 3600000), // 2 PM
|
|
125
|
-
status: 'failed',
|
|
126
|
-
size: 256,
|
|
127
|
-
pages: 1,
|
|
128
|
-
duration: 5,
|
|
129
|
-
uuid: '1234567890',
|
|
130
|
-
print_device_id: 1,
|
|
131
|
-
},
|
|
132
|
-
]
|
|
133
|
-
|
|
134
|
-
await bulkStore(requests)
|
|
135
|
-
|
|
136
|
-
// Fetch prints per hour statistics
|
|
137
|
-
const stats = await fetchPrintsPerHour(startDate, endDate)
|
|
138
|
-
|
|
139
|
-
// Verify the statistics
|
|
140
|
-
expect(stats).toBeDefined()
|
|
141
|
-
expect(stats.totalPrints).toBe(4)
|
|
142
|
-
expect(stats.totalHours).toBe(24)
|
|
143
|
-
|
|
144
|
-
// Verify hourly breakdown
|
|
145
|
-
expect(stats.hourlyBreakdown).toHaveLength(24)
|
|
146
|
-
expect(stats.hourlyBreakdown[2].count).toBe(2) // 2 prints at 2 AM
|
|
147
|
-
expect(stats.hourlyBreakdown[14].count).toBe(2) // 2 prints at 2 PM
|
|
148
|
-
// All other hours should have 0 prints
|
|
149
|
-
stats.hourlyBreakdown.forEach((hour: { hour: number, count: number }, index: number) => {
|
|
150
|
-
if (index !== 2 && index !== 14) {
|
|
151
|
-
expect(hour.count).toBe(0)
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('should return zero statistics when no receipts exist in date range', async () => {
|
|
157
|
-
const now = Date.now()
|
|
158
|
-
const startDate = now - (now % 86400000) // Start of today
|
|
159
|
-
const endDate = startDate + 86399999 // End of today
|
|
160
|
-
|
|
161
|
-
const stats = await fetchPrintsPerHour(startDate, endDate)
|
|
162
|
-
|
|
163
|
-
expect(stats).toBeDefined()
|
|
164
|
-
expect(stats.totalPrints).toBe(0)
|
|
165
|
-
expect(stats.totalHours).toBe(24)
|
|
166
|
-
expect(stats.printsPerHour).toBe(0)
|
|
167
|
-
expect(stats.hourlyBreakdown).toHaveLength(24)
|
|
168
|
-
stats.hourlyBreakdown.forEach((hour: { hour: number, count: number }) => {
|
|
169
|
-
expect(hour.count).toBe(0)
|
|
170
|
-
})
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
it('should calculate correct statistics for a single hour', async () => {
|
|
174
|
-
const now = Date.now()
|
|
175
|
-
const startDate = now - (now % 86400000) // Start of today
|
|
176
|
-
const endDate = startDate + 3600000 // One hour later
|
|
177
|
-
|
|
178
|
-
// Create test receipts all in the same hour
|
|
179
|
-
const requests = [
|
|
180
|
-
{
|
|
181
|
-
printer: 'HP LaserJet',
|
|
182
|
-
document: 'invoice1.pdf',
|
|
183
|
-
timestamp: startDate,
|
|
184
|
-
status: 'success',
|
|
185
|
-
size: 1024,
|
|
186
|
-
pages: 1,
|
|
187
|
-
uuid: '1234567890',
|
|
188
|
-
print_device_id: 1,
|
|
189
|
-
duration: 30,
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
printer: 'Epson Printer',
|
|
193
|
-
document: 'invoice2.pdf',
|
|
194
|
-
timestamp: startDate + 1800000, // 30 minutes later
|
|
195
|
-
status: 'success',
|
|
196
|
-
size: 2048,
|
|
197
|
-
pages: 1,
|
|
198
|
-
duration: 45,
|
|
199
|
-
uuid: '1234567890',
|
|
200
|
-
print_device_id: 1,
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
printer: 'Canon Printer',
|
|
204
|
-
document: 'invoice3.pdf',
|
|
205
|
-
timestamp: startDate + 3000000, // 50 minutes later
|
|
206
|
-
status: 'success',
|
|
207
|
-
size: 512,
|
|
208
|
-
pages: 1,
|
|
209
|
-
duration: 15,
|
|
210
|
-
uuid: '1234567890',
|
|
211
|
-
print_device_id: 1,
|
|
212
|
-
},
|
|
213
|
-
]
|
|
214
|
-
|
|
215
|
-
await bulkStore(requests)
|
|
216
|
-
|
|
217
|
-
const stats = await fetchPrintsPerHour(startDate, endDate)
|
|
218
|
-
|
|
219
|
-
expect(stats).toBeDefined()
|
|
220
|
-
expect(stats.totalPrints).toBe(3)
|
|
221
|
-
expect(stats.totalHours).toBe(1)
|
|
222
|
-
expect(stats.printsPerHour).toBe(3) // 3 prints / 1 hour
|
|
223
|
-
expect(stats.hourlyBreakdown).toHaveLength(24)
|
|
224
|
-
// Only the first hour should have prints
|
|
225
|
-
stats.hourlyBreakdown.forEach((hour: { hour: number, count: number }, index: number) => {
|
|
226
|
-
expect(hour.count).toBe(index === 0 ? 3 : 0)
|
|
227
|
-
})
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('should only count receipts within the specified date range for hourly statistics', async () => {
|
|
231
|
-
const now = Date.now()
|
|
232
|
-
const startDate = now - (now % 86400000) // Start of today
|
|
233
|
-
const endDate = startDate + 86399999 // End of today
|
|
234
|
-
|
|
235
|
-
// Create receipts with different dates
|
|
236
|
-
const requests = [
|
|
237
|
-
{
|
|
238
|
-
printer: 'HP LaserJet',
|
|
239
|
-
document: 'invoice.pdf',
|
|
240
|
-
timestamp: startDate,
|
|
241
|
-
status: 'success',
|
|
242
|
-
size: 1024,
|
|
243
|
-
pages: 5,
|
|
244
|
-
duration: 30,
|
|
245
|
-
uuid: '1234567890',
|
|
246
|
-
print_device_id: 1,
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
printer: 'Epson Printer',
|
|
250
|
-
document: 'report.pdf',
|
|
251
|
-
timestamp: startDate - 86400000, // Yesterday
|
|
252
|
-
status: 'success',
|
|
253
|
-
size: 2048,
|
|
254
|
-
pages: 10,
|
|
255
|
-
duration: 45,
|
|
256
|
-
uuid: '1234567890',
|
|
257
|
-
print_device_id: 1,
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
printer: 'Canon Printer',
|
|
261
|
-
document: 'document.pdf',
|
|
262
|
-
timestamp: endDate + 1, // Tomorrow
|
|
263
|
-
status: 'warning',
|
|
264
|
-
size: 512,
|
|
265
|
-
pages: 2,
|
|
266
|
-
duration: 15,
|
|
267
|
-
uuid: '1234567890',
|
|
268
|
-
print_device_id: 1,
|
|
269
|
-
},
|
|
270
|
-
]
|
|
271
|
-
|
|
272
|
-
await bulkStore(requests)
|
|
273
|
-
|
|
274
|
-
const stats = await fetchPrintsPerHour(startDate, endDate)
|
|
275
|
-
|
|
276
|
-
// Verify only today's receipt is counted
|
|
277
|
-
expect(stats).toBeDefined()
|
|
278
|
-
expect(stats.totalPrints).toBe(1)
|
|
279
|
-
expect(stats.totalHours).toBe(24)
|
|
280
|
-
expect(stats.hourlyBreakdown).toHaveLength(24)
|
|
281
|
-
// Only the first hour should have prints
|
|
282
|
-
stats.hourlyBreakdown.forEach((hour: { hour: number, count: number }, index: number) => {
|
|
283
|
-
expect(hour.count).toBe(index === 0 ? 1 : 0)
|
|
284
|
-
})
|
|
285
|
-
})
|
|
286
|
-
})
|
|
287
|
-
})
|