@stacksjs/commerce 0.70.53 → 0.70.55
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 +3 -2
- package/src/carts/destroy.ts +54 -0
- package/src/carts/fetch.ts +20 -0
- package/src/carts/index.ts +13 -0
- package/src/carts/store.ts +75 -0
- package/src/carts/update.ts +78 -0
- package/src/coupons/destroy.ts +49 -0
- package/src/coupons/fetch.ts +510 -0
- package/src/coupons/index.ts +30 -0
- package/src/coupons/store.ts +46 -0
- package/src/coupons/update.ts +147 -0
- package/src/customers/destroy.ts +62 -0
- package/src/customers/fetch.ts +20 -0
- package/src/customers/index.ts +17 -0
- package/src/customers/store.ts +45 -0
- package/src/customers/update.ts +44 -0
- package/src/devices/destroy.ts +54 -0
- package/src/devices/export.ts +98 -0
- package/src/devices/fetch.ts +125 -0
- package/src/devices/index.ts +31 -0
- package/src/devices/store.ts +82 -0
- package/src/devices/update.ts +125 -0
- package/src/errors/destroy.ts +54 -0
- package/src/errors/fetch.ts +197 -0
- package/src/errors/index.ts +28 -0
- package/src/errors/update.ts +116 -0
- package/src/gift-cards/destroy.ts +87 -0
- package/src/gift-cards/fetch.ts +431 -0
- package/src/gift-cards/index.ts +26 -0
- package/src/gift-cards/store.ts +56 -0
- package/src/gift-cards/update.ts +102 -0
- package/src/index.ts +78 -0
- package/src/orders/destroy.ts +111 -0
- package/src/orders/events.ts +121 -0
- package/src/orders/export.ts +158 -0
- package/src/orders/fetch.ts +379 -0
- package/src/orders/guards.ts +261 -0
- package/src/orders/index.ts +91 -0
- package/src/orders/place-order.ts +274 -0
- package/src/orders/store.ts +51 -0
- package/src/orders/totals.ts +190 -0
- package/src/orders/update.ts +164 -0
- package/src/orders/webhook.ts +312 -0
- package/src/payments/destroy.ts +56 -0
- package/src/payments/fetch.ts +288 -0
- package/src/payments/index.ts +16 -0
- package/src/payments/store.ts +63 -0
- package/src/payments/update.ts +52 -0
- package/src/product.ts +0 -0
- package/src/products/categories/destroy.ts +103 -0
- package/src/products/categories/fetch.ts +285 -0
- package/src/products/categories/index.ts +36 -0
- package/src/products/categories/store.ts +87 -0
- package/src/products/categories/update.ts +251 -0
- package/src/products/index.ts +35 -0
- package/src/products/items/destroy.ts +54 -0
- package/src/products/items/fetch.ts +282 -0
- package/src/products/items/index.ts +26 -0
- package/src/products/items/store.ts +84 -0
- package/src/products/items/update.ts +324 -0
- package/src/products/manufacturers/destroy.ts +56 -0
- package/src/products/manufacturers/fetch.ts +117 -0
- package/src/products/manufacturers/index.ts +24 -0
- package/src/products/manufacturers/store.ts +82 -0
- package/src/products/manufacturers/update.ts +113 -0
- package/src/products/reviews/destroy.ts +56 -0
- package/src/products/reviews/fetch.ts +63 -0
- package/src/products/reviews/index.ts +25 -0
- package/src/products/reviews/store.ts +46 -0
- package/src/products/reviews/update.ts +82 -0
- package/src/products/units/destroy.ts +56 -0
- package/src/products/units/fetch.ts +20 -0
- package/src/products/units/index.ts +13 -0
- package/src/products/units/store.ts +162 -0
- package/src/products/units/update.ts +159 -0
- package/src/products/variants/destroy.ts +56 -0
- package/src/products/variants/fetch.ts +20 -0
- package/src/products/variants/index.ts +21 -0
- package/src/products/variants/store.ts +136 -0
- package/src/products/variants/update.ts +104 -0
- package/src/receipts/destroy.ts +54 -0
- package/src/receipts/export.ts +0 -0
- package/src/receipts/fetch.ts +222 -0
- package/src/receipts/index.ts +24 -0
- package/src/receipts/printer.ts +69 -0
- package/src/receipts/store.ts +69 -0
- package/src/receipts/update.ts +124 -0
- package/src/shippings/delivery-routes/destroy.ts +54 -0
- package/src/shippings/delivery-routes/fetch.ts +42 -0
- package/src/shippings/delivery-routes/index.ts +26 -0
- package/src/shippings/delivery-routes/store.ts +69 -0
- package/src/shippings/delivery-routes/update.ts +120 -0
- package/src/shippings/digital-deliveries/destroy.ts +111 -0
- package/src/shippings/digital-deliveries/fetch.ts +20 -0
- package/src/shippings/digital-deliveries/index.ts +26 -0
- package/src/shippings/digital-deliveries/store.ts +76 -0
- package/src/shippings/digital-deliveries/update.ts +129 -0
- package/src/shippings/drivers/destroy.ts +78 -0
- package/src/shippings/drivers/fetch.ts +20 -0
- package/src/shippings/drivers/index.ts +24 -0
- package/src/shippings/drivers/store.ts +69 -0
- package/src/shippings/drivers/update.ts +117 -0
- package/src/shippings/index.ts +39 -0
- package/src/shippings/license-keys/destroy.ts +111 -0
- package/src/shippings/license-keys/fetch.ts +20 -0
- package/src/shippings/license-keys/index.ts +26 -0
- package/src/shippings/license-keys/store.ts +77 -0
- package/src/shippings/license-keys/update.ts +117 -0
- package/src/shippings/shipping-methods/destroy.ts +111 -0
- package/src/shippings/shipping-methods/fetch.ts +62 -0
- package/src/shippings/shipping-methods/index.ts +28 -0
- package/src/shippings/shipping-methods/store.ts +123 -0
- package/src/shippings/shipping-methods/update.ts +120 -0
- package/src/shippings/shipping-rates/destroy.ts +102 -0
- package/src/shippings/shipping-rates/fetch.ts +320 -0
- package/src/shippings/shipping-rates/index.ts +36 -0
- package/src/shippings/shipping-rates/store.ts +102 -0
- package/src/shippings/shipping-rates/update.ts +139 -0
- package/src/shippings/shipping-zones/destroy.ts +111 -0
- package/src/shippings/shipping-zones/fetch.ts +96 -0
- package/src/shippings/shipping-zones/index.ts +26 -0
- package/src/shippings/shipping-zones/store.ts +74 -0
- package/src/shippings/shipping-zones/update.ts +156 -0
- package/src/tax/destroy.ts +54 -0
- package/src/tax/fetch.ts +20 -0
- package/src/tax/index.ts +24 -0
- package/src/tax/store.ts +69 -0
- package/src/tax/update.ts +119 -0
- package/src/tests/coupons.test.ts +90 -0
- package/src/tests/customers.test.ts +39 -0
- package/src/tests/device.test.ts +111 -0
- package/src/tests/digitals.test.ts +31 -0
- package/src/tests/drivers.test.ts +25 -0
- package/src/tests/gift-cards.test.ts +36 -0
- package/src/tests/license.test.ts +31 -0
- package/src/tests/manufacturers.test.ts +80 -0
- package/src/tests/orders.test.ts +25 -0
- package/src/tests/payments.test.ts +75 -0
- package/src/tests/rates.test.ts +367 -0
- package/src/tests/receipts.test.ts +287 -0
- package/src/tests/restaurant.test.ts +522 -0
- package/src/tests/reviews.test.ts +165 -0
- package/src/tests/routes.test.ts +51 -0
- package/src/tests/setup.ts +149 -0
- package/src/tests/shipping.test.ts +88 -0
- package/src/tests/tax.test.ts +25 -0
- package/src/tests/units.test.ts +110 -0
- package/src/tests/variants.test.ts +133 -0
- package/src/tests/waitlist.test.ts +303 -0
- package/src/tests/zones.test.ts +86 -0
- package/src/types.ts +312 -0
- package/src/utils/typed-stats.ts +67 -0
- package/src/waitlists/index.ts +19 -0
- package/src/waitlists/products/destroy.ts +65 -0
- package/src/waitlists/products/export.ts +113 -0
- package/src/waitlists/products/fetch.ts +362 -0
- package/src/waitlists/products/index.ts +33 -0
- package/src/waitlists/products/store.ts +112 -0
- package/src/waitlists/products/update.ts +125 -0
- package/src/waitlists/restaurant/destroy.ts +65 -0
- package/src/waitlists/restaurant/export.ts +107 -0
- package/src/waitlists/restaurant/fetch.ts +538 -0
- package/src/waitlists/restaurant/index.ts +43 -0
- package/src/waitlists/restaurant/store.ts +109 -0
- package/src/waitlists/restaurant/update.ts +198 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { db } from '@stacksjs/database'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Delete a tax rate by ID
|
|
5
|
+
*
|
|
6
|
+
* @param id The ID of the tax rate to delete
|
|
7
|
+
* @returns True if the tax rate was deleted, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
export async function destroy(id: number): Promise<boolean> {
|
|
10
|
+
try {
|
|
11
|
+
const result = await db
|
|
12
|
+
.deleteFrom('tax_rates')
|
|
13
|
+
.where('id', '=', id)
|
|
14
|
+
.executeTakeFirst()
|
|
15
|
+
|
|
16
|
+
return Number(result.numDeletedRows) > 0
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
throw new TypeError(`Failed to delete tax rate: ${error.message}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
throw error
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Delete multiple tax rates by ID
|
|
29
|
+
*
|
|
30
|
+
* @param ids Array of tax rate IDs to delete
|
|
31
|
+
* @returns Number of tax rates deleted
|
|
32
|
+
*/
|
|
33
|
+
export async function bulkDestroy(ids: number[]): Promise<number> {
|
|
34
|
+
if (!ids.length)
|
|
35
|
+
return 0
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Perform the delete operation
|
|
39
|
+
const result = await db
|
|
40
|
+
.deleteFrom('tax_rates')
|
|
41
|
+
.where('id', 'in', ids)
|
|
42
|
+
.executeTakeFirst()
|
|
43
|
+
|
|
44
|
+
// Return the number of deleted rows
|
|
45
|
+
return Number(result.numDeletedRows)
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof Error) {
|
|
49
|
+
throw new TypeError(`Failed to delete tax rates: ${error.message}`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
throw error
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/tax/fetch.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type TaxRateJsonResponse = ModelRow<typeof TaxRate>
|
|
2
|
+
import { db } from '@stacksjs/database'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fetch a tax rate by ID
|
|
6
|
+
*/
|
|
7
|
+
export async function fetchById(id: number): Promise<TaxRateJsonResponse | undefined> {
|
|
8
|
+
return await db
|
|
9
|
+
.selectFrom('tax_rates')
|
|
10
|
+
.where('id', '=', id)
|
|
11
|
+
.selectAll()
|
|
12
|
+
.executeTakeFirst() as TaxRateJsonResponse | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fetch all tax rates
|
|
17
|
+
*/
|
|
18
|
+
export async function fetchAll(): Promise<TaxRateJsonResponse[]> {
|
|
19
|
+
return await db.selectFrom('tax_rates').selectAll().execute() as TaxRateJsonResponse[]
|
|
20
|
+
}
|
package/src/tax/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Functions from destroy.ts
|
|
2
|
+
export {
|
|
3
|
+
bulkDestroy,
|
|
4
|
+
destroy,
|
|
5
|
+
} from './destroy'
|
|
6
|
+
|
|
7
|
+
// Functions from fetch.ts
|
|
8
|
+
export {
|
|
9
|
+
fetchAll,
|
|
10
|
+
fetchById,
|
|
11
|
+
} from './fetch'
|
|
12
|
+
|
|
13
|
+
// Functions from store.ts
|
|
14
|
+
export {
|
|
15
|
+
bulkStore,
|
|
16
|
+
store,
|
|
17
|
+
} from './store'
|
|
18
|
+
|
|
19
|
+
// Functions from update.ts
|
|
20
|
+
export {
|
|
21
|
+
update,
|
|
22
|
+
updateRate,
|
|
23
|
+
updateStatus,
|
|
24
|
+
} from './update'
|
package/src/tax/store.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
type TaxRateJsonResponse = ModelRow<typeof TaxRate>
|
|
2
|
+
type NewTaxRate = NewModelData<typeof TaxRate>
|
|
3
|
+
import { randomUUIDv7 } from 'bun'
|
|
4
|
+
import { db } from '@stacksjs/database'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a new tax rate
|
|
8
|
+
*
|
|
9
|
+
* @param data Tax rate data to store
|
|
10
|
+
* @returns The newly created tax rate record
|
|
11
|
+
*/
|
|
12
|
+
export async function store(data: NewTaxRate): Promise<TaxRateJsonResponse> {
|
|
13
|
+
try {
|
|
14
|
+
const taxData = {
|
|
15
|
+
...data,
|
|
16
|
+
uuid: randomUUIDv7(),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const result = await db
|
|
20
|
+
.insertInto('tax_rates')
|
|
21
|
+
.values(taxData)
|
|
22
|
+
.returningAll()
|
|
23
|
+
.executeTakeFirst()
|
|
24
|
+
|
|
25
|
+
if (!result)
|
|
26
|
+
throw new Error('Failed to create tax rate')
|
|
27
|
+
|
|
28
|
+
return result as TaxRateJsonResponse
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof Error) {
|
|
32
|
+
throw new TypeError(`Failed to create tax rate: ${error.message}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw error
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create multiple tax rates at once
|
|
41
|
+
*
|
|
42
|
+
* @param data Array of tax rate data to store
|
|
43
|
+
* @returns Number of tax rates created
|
|
44
|
+
*/
|
|
45
|
+
export async function bulkStore(data: NewTaxRate[]): Promise<number> {
|
|
46
|
+
if (!data.length)
|
|
47
|
+
return 0
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const taxDataArray = data.map(item => ({
|
|
51
|
+
...item,
|
|
52
|
+
uuid: randomUUIDv7(),
|
|
53
|
+
}))
|
|
54
|
+
|
|
55
|
+
const result = await db
|
|
56
|
+
.insertInto('tax_rates')
|
|
57
|
+
.values(taxDataArray)
|
|
58
|
+
.executeTakeFirst()
|
|
59
|
+
|
|
60
|
+
return Number(result.numInsertedOrUpdatedRows)
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof Error) {
|
|
64
|
+
throw new TypeError(`Failed to create tax rates in bulk: ${error.message}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
throw error
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { db } from '@stacksjs/database'
|
|
2
|
+
import { formatDate } from '@stacksjs/orm'
|
|
3
|
+
type TaxRateJsonResponse = ModelRow<typeof TaxRate>
|
|
4
|
+
type TaxRateUpdate = UpdateModelData<typeof TaxRate>
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Update a tax rate
|
|
8
|
+
*
|
|
9
|
+
* @param id The id of the tax rate to update
|
|
10
|
+
* @param data The tax rate data to update
|
|
11
|
+
* @returns The updated tax rate record
|
|
12
|
+
*/
|
|
13
|
+
export async function update(id: number, data: TaxRateUpdate): Promise<TaxRateJsonResponse> {
|
|
14
|
+
try {
|
|
15
|
+
if (!id)
|
|
16
|
+
throw new Error('Tax rate ID is required for update')
|
|
17
|
+
|
|
18
|
+
const d = data as Record<string, unknown>
|
|
19
|
+
const result = await db
|
|
20
|
+
.updateTable('tax_rates')
|
|
21
|
+
.set({
|
|
22
|
+
name: data.name,
|
|
23
|
+
rate: data.rate,
|
|
24
|
+
type: data.type,
|
|
25
|
+
country: data.country,
|
|
26
|
+
region: data.region,
|
|
27
|
+
status: data.status,
|
|
28
|
+
is_default: d.is_default,
|
|
29
|
+
updated_at: formatDate(new Date()),
|
|
30
|
+
})
|
|
31
|
+
.where('id', '=', id)
|
|
32
|
+
.returningAll()
|
|
33
|
+
.executeTakeFirst()
|
|
34
|
+
|
|
35
|
+
if (!result)
|
|
36
|
+
throw new Error('Failed to update tax rate')
|
|
37
|
+
|
|
38
|
+
return result as TaxRateJsonResponse
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof Error) {
|
|
42
|
+
throw new TypeError(`Failed to update tax rate: ${error.message}`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw error
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Update a tax rate's status
|
|
51
|
+
*
|
|
52
|
+
* @param id The ID of the tax rate
|
|
53
|
+
* @param status The new status
|
|
54
|
+
* @returns The updated tax rate with the new status
|
|
55
|
+
*/
|
|
56
|
+
export async function updateStatus(
|
|
57
|
+
id: number,
|
|
58
|
+
status: 'active' | 'inactive',
|
|
59
|
+
): Promise<TaxRateJsonResponse> {
|
|
60
|
+
try {
|
|
61
|
+
const result = await db
|
|
62
|
+
.updateTable('tax_rates')
|
|
63
|
+
.set({
|
|
64
|
+
status,
|
|
65
|
+
updated_at: formatDate(new Date()),
|
|
66
|
+
})
|
|
67
|
+
.where('id', '=', id)
|
|
68
|
+
.returningAll()
|
|
69
|
+
.executeTakeFirst()
|
|
70
|
+
|
|
71
|
+
if (!result)
|
|
72
|
+
throw new Error('Failed to update tax rate status')
|
|
73
|
+
|
|
74
|
+
return result as TaxRateJsonResponse
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof Error) {
|
|
78
|
+
throw new TypeError(`Failed to update tax rate status: ${error.message}`)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw error
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Update rate information for a tax rate
|
|
87
|
+
*
|
|
88
|
+
* @param id The ID of the tax rate
|
|
89
|
+
* @param rate The updated rate value
|
|
90
|
+
* @returns The updated tax rate
|
|
91
|
+
*/
|
|
92
|
+
export async function updateRate(
|
|
93
|
+
id: number,
|
|
94
|
+
rate: number,
|
|
95
|
+
): Promise<TaxRateJsonResponse> {
|
|
96
|
+
try {
|
|
97
|
+
const result = await db
|
|
98
|
+
.updateTable('tax_rates')
|
|
99
|
+
.set({
|
|
100
|
+
rate,
|
|
101
|
+
updated_at: formatDate(new Date()),
|
|
102
|
+
})
|
|
103
|
+
.where('id', '=', id)
|
|
104
|
+
.returningAll()
|
|
105
|
+
.executeTakeFirst()
|
|
106
|
+
|
|
107
|
+
if (!result)
|
|
108
|
+
throw new Error('Failed to update rate information')
|
|
109
|
+
|
|
110
|
+
return result as TaxRateJsonResponse
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error instanceof Error) {
|
|
114
|
+
throw new TypeError(`Failed to update rate information: ${error.message}`)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
throw error
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { formatDate } from '@stacksjs/orm'
|
|
3
|
+
import { refreshDatabase } from './setup'
|
|
4
|
+
import { fetchActive, fetchAll } from '../coupons/fetch'
|
|
5
|
+
import { store } from '../coupons/store'
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
await refreshDatabase()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
describe('Coupon Module', () => {
|
|
12
|
+
describe('fetchById and fetchByCode', () => {
|
|
13
|
+
it('should fetch all coupons', async () => {
|
|
14
|
+
// Create multiple coupons
|
|
15
|
+
const codes = []
|
|
16
|
+
for (let i = 0; i < 3; i++) {
|
|
17
|
+
const code = `COUPON-ALL-${i}-${Date.now()}`
|
|
18
|
+
codes.push(code)
|
|
19
|
+
|
|
20
|
+
const couponData = {
|
|
21
|
+
code,
|
|
22
|
+
discount_type: 'percentage',
|
|
23
|
+
discount_value: 10 + i,
|
|
24
|
+
product_id: 1,
|
|
25
|
+
start_date: formatDate(new Date('2023-01-01')),
|
|
26
|
+
end_date: formatDate(new Date('2023-12-31')),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await store(couponData)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Fetch all coupons
|
|
33
|
+
const allCoupons = await fetchAll()
|
|
34
|
+
|
|
35
|
+
// Verify all coupons are fetched
|
|
36
|
+
expect(allCoupons.length).toBeGreaterThanOrEqual(3)
|
|
37
|
+
|
|
38
|
+
// Check if our created coupons are in the results
|
|
39
|
+
for (const code of codes) {
|
|
40
|
+
const found = allCoupons.some(coupon => coupon.code === code)
|
|
41
|
+
expect(found).toBe(true)
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should fetch active coupons', async () => {
|
|
46
|
+
// Create an active coupon (current date within range)
|
|
47
|
+
const today = new Date()
|
|
48
|
+
const futureDate = new Date(today)
|
|
49
|
+
futureDate.setMonth(today.getMonth() + 1)
|
|
50
|
+
|
|
51
|
+
const activeCode = `COUPON-ACTIVE-${Date.now()}`
|
|
52
|
+
const activeData = {
|
|
53
|
+
code: activeCode,
|
|
54
|
+
discount_type: 'percentage',
|
|
55
|
+
discount_value: 20,
|
|
56
|
+
product_id: 1,
|
|
57
|
+
start_date: formatDate(today),
|
|
58
|
+
end_date: formatDate(futureDate),
|
|
59
|
+
is_active: true,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await store(activeData)
|
|
63
|
+
|
|
64
|
+
// Create an inactive coupon (same date range but is_active = false)
|
|
65
|
+
const inactiveCode = `COUPON-INACTIVE-${Date.now()}`
|
|
66
|
+
const inactiveData = {
|
|
67
|
+
code: inactiveCode,
|
|
68
|
+
discount_type: 'percentage',
|
|
69
|
+
discount_value: 20,
|
|
70
|
+
product_id: 1,
|
|
71
|
+
start_date: formatDate(today),
|
|
72
|
+
end_date: formatDate(futureDate),
|
|
73
|
+
is_active: false,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await store(inactiveData)
|
|
77
|
+
|
|
78
|
+
// Fetch active coupons
|
|
79
|
+
const activeCoupons = await fetchActive()
|
|
80
|
+
|
|
81
|
+
// Check that active coupon is included
|
|
82
|
+
const hasActiveCoupon = activeCoupons.some(coupon => coupon.code === activeCode)
|
|
83
|
+
expect(hasActiveCoupon).toBe(true)
|
|
84
|
+
|
|
85
|
+
// Check that inactive coupon is not included
|
|
86
|
+
const hasInactiveCoupon = activeCoupons.some(coupon => coupon.code === inactiveCode)
|
|
87
|
+
expect(hasInactiveCoupon).toBe(false)
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { refreshDatabase } from './setup'
|
|
3
|
+
import { destroy } from '../customers/destroy'
|
|
4
|
+
|
|
5
|
+
beforeEach(async () => {
|
|
6
|
+
await refreshDatabase()
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
describe('Customer Module', () => {
|
|
10
|
+
describe('remove', () => {
|
|
11
|
+
it('should throw an error when trying to delete a non-existent customer', async () => {
|
|
12
|
+
// Use a very large ID that is unlikely to exist
|
|
13
|
+
const nonExistentId = 99999999
|
|
14
|
+
|
|
15
|
+
// Attempt to delete and expect an error
|
|
16
|
+
try {
|
|
17
|
+
await destroy(nonExistentId)
|
|
18
|
+
// If we get here, the test should fail as we expect an error
|
|
19
|
+
expect(true).toBe(false) // This line should not be reached
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
expect(error).toBeDefined()
|
|
23
|
+
expect(error instanceof Error).toBe(true)
|
|
24
|
+
expect((error as Error).message).toContain(`Customer with ID ${nonExistentId} not found`)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe('bulkRemove', () => {
|
|
30
|
+
it('should return 0 when trying to delete an empty array of customers', async () => {
|
|
31
|
+
// Import the bulkRemove function
|
|
32
|
+
const { bulkDestroy } = await import('../customers/destroy')
|
|
33
|
+
|
|
34
|
+
// Try to delete with an empty array
|
|
35
|
+
const deletedCount = await bulkDestroy([])
|
|
36
|
+
expect(deletedCount).toBe(0)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { refreshDatabase } from './setup'
|
|
3
|
+
import { bulkDestroy } from '../devices/destroy'
|
|
4
|
+
import { exportPrintDevices } from '../devices/export'
|
|
5
|
+
import { bulkStore, store } from '../devices/store'
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
await refreshDatabase()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
describe('Print Device Module', () => {
|
|
12
|
+
describe('store', () => {
|
|
13
|
+
it('should create multiple print devices with bulk store', async () => {
|
|
14
|
+
const devices = [
|
|
15
|
+
{
|
|
16
|
+
name: 'Printer 1',
|
|
17
|
+
mac_address: '00:11:22:33:44:55',
|
|
18
|
+
location: 'Office 101',
|
|
19
|
+
terminal: 'TERM001',
|
|
20
|
+
status: 'online',
|
|
21
|
+
last_ping: Date.now(),
|
|
22
|
+
print_count: 0,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'Printer 2',
|
|
26
|
+
mac_address: 'AA:BB:CC:DD:EE:FF',
|
|
27
|
+
location: 'Office 102',
|
|
28
|
+
terminal: 'TERM002',
|
|
29
|
+
status: 'online',
|
|
30
|
+
last_ping: Date.now(),
|
|
31
|
+
print_count: 0,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Printer 3',
|
|
35
|
+
mac_address: '11:22:33:44:55:66',
|
|
36
|
+
location: 'Office 103',
|
|
37
|
+
terminal: 'TERM003',
|
|
38
|
+
status: 'online',
|
|
39
|
+
last_ping: Date.now(),
|
|
40
|
+
print_count: 0,
|
|
41
|
+
},
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const count = await bulkStore(devices)
|
|
45
|
+
expect(count).toBe(3)
|
|
46
|
+
|
|
47
|
+
// Verify devices can be fetched
|
|
48
|
+
const { fetchAll } = await import('../devices/fetch')
|
|
49
|
+
const allDevices = await fetchAll()
|
|
50
|
+
expect(allDevices.length).toBeGreaterThanOrEqual(3)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should return 0 when trying to bulk store an empty array', async () => {
|
|
54
|
+
const count = await bulkStore([])
|
|
55
|
+
expect(count).toBe(0)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('destroy', () => {
|
|
60
|
+
it('should return 0 when trying to delete an empty array of devices', async () => {
|
|
61
|
+
// Try to delete with an empty array
|
|
62
|
+
const deletedCount = await bulkDestroy([])
|
|
63
|
+
expect(deletedCount).toBe(0)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('export', () => {
|
|
68
|
+
it('should export print devices to CSV format', async () => {
|
|
69
|
+
// Create a test device
|
|
70
|
+
const deviceData = {
|
|
71
|
+
name: 'Main Printer',
|
|
72
|
+
mac_address: '00:11:22:33:44:55',
|
|
73
|
+
location: 'Office 101',
|
|
74
|
+
terminal: 'TERM001',
|
|
75
|
+
status: 'online',
|
|
76
|
+
last_ping: Date.now(),
|
|
77
|
+
print_count: 100,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await store(deviceData)
|
|
81
|
+
|
|
82
|
+
// Export devices
|
|
83
|
+
const spreadsheet = await exportPrintDevices('csv')
|
|
84
|
+
expect(spreadsheet).toBeDefined()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should export print devices to Excel format', async () => {
|
|
88
|
+
// Create a test device
|
|
89
|
+
const deviceData = {
|
|
90
|
+
name: 'Main Printer',
|
|
91
|
+
mac_address: '00:11:22:33:44:55',
|
|
92
|
+
location: 'Office 101',
|
|
93
|
+
terminal: 'TERM001',
|
|
94
|
+
status: 'online',
|
|
95
|
+
last_ping: Date.now(),
|
|
96
|
+
print_count: 100,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await store(deviceData)
|
|
100
|
+
|
|
101
|
+
// Export devices
|
|
102
|
+
const spreadsheet = await exportPrintDevices('excel')
|
|
103
|
+
expect(spreadsheet).toBeDefined()
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('should handle empty device list during export', async () => {
|
|
107
|
+
const spreadsheet = await exportPrintDevices('csv')
|
|
108
|
+
expect(spreadsheet).toBeDefined()
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { refreshDatabase } from './setup'
|
|
3
|
+
import { bulkDestroy, bulkSoftDelete } from '../shippings/digital-deliveries/destroy'
|
|
4
|
+
import { bulkStore } from '../shippings/digital-deliveries/store'
|
|
5
|
+
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
await refreshDatabase()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
describe('Digital Delivery Module', () => {
|
|
11
|
+
describe('store', () => {
|
|
12
|
+
it('should return 0 when trying to bulk store an empty array', async () => {
|
|
13
|
+
const count = await bulkStore([])
|
|
14
|
+
expect(count).toBe(0)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('destroy', () => {
|
|
19
|
+
it('should return 0 when trying to delete an empty array of deliveries', async () => {
|
|
20
|
+
// Try to delete with an empty array
|
|
21
|
+
const deletedCount = await bulkDestroy([])
|
|
22
|
+
expect(deletedCount).toBe(0)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('should return 0 when trying to soft delete an empty array of deliveries', async () => {
|
|
26
|
+
// Try to soft delete with an empty array
|
|
27
|
+
const deletedCount = await bulkSoftDelete([])
|
|
28
|
+
expect(deletedCount).toBe(0)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { refreshDatabase } from './setup'
|
|
3
|
+
import { bulkDestroy } from '../shippings/drivers/destroy'
|
|
4
|
+
import { bulkStore } from '../shippings/drivers/store'
|
|
5
|
+
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
await refreshDatabase()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
describe('Driver Module', () => {
|
|
11
|
+
describe('store', () => {
|
|
12
|
+
it('should return 0 when trying to bulk store an empty array', async () => {
|
|
13
|
+
const count = await bulkStore([])
|
|
14
|
+
expect(count).toBe(0)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('destroy', () => {
|
|
19
|
+
it('should return 0 when trying to delete an empty array of drivers', async () => {
|
|
20
|
+
// Try to delete with an empty array
|
|
21
|
+
const deletedCount = await bulkDestroy([])
|
|
22
|
+
expect(deletedCount).toBe(0)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { refreshDatabase } from './setup'
|
|
3
|
+
import { bulkDestroy, destroy } from '../gift-cards/destroy'
|
|
4
|
+
|
|
5
|
+
beforeEach(async () => {
|
|
6
|
+
await refreshDatabase()
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
describe('Gift Card Module', () => {
|
|
10
|
+
describe('remove', () => {
|
|
11
|
+
it('should throw an error when trying to delete a non-existent gift card', async () => {
|
|
12
|
+
// Use a very large ID that is unlikely to exist
|
|
13
|
+
const nonExistentId = 99999999
|
|
14
|
+
|
|
15
|
+
// Attempt to delete and expect an error
|
|
16
|
+
try {
|
|
17
|
+
await destroy(nonExistentId)
|
|
18
|
+
// If we get here, the test should fail as we expect an error
|
|
19
|
+
expect(true).toBe(false) // This line should not be reached
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
expect(error).toBeDefined()
|
|
23
|
+
expect(error instanceof Error).toBe(true)
|
|
24
|
+
expect((error as Error).message).toContain(`Gift card with ID ${nonExistentId} not found`)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe('bulkRemove', () => {
|
|
30
|
+
it('should return 0 when trying to delete an empty array of gift cards', async () => {
|
|
31
|
+
// Try to delete with an empty array
|
|
32
|
+
const deletedCount = await bulkDestroy([])
|
|
33
|
+
expect(deletedCount).toBe(0)
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { refreshDatabase } from './setup'
|
|
3
|
+
import { bulkDestroy, bulkSoftDelete } from '../shippings/license-keys/destroy'
|
|
4
|
+
import { bulkStore } from '../shippings/license-keys/store'
|
|
5
|
+
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
await refreshDatabase()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
describe('License Key Module', () => {
|
|
11
|
+
describe('store', () => {
|
|
12
|
+
it('should return 0 when trying to bulk store an empty array', async () => {
|
|
13
|
+
const count = await bulkStore([])
|
|
14
|
+
expect(count).toBe(0)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('destroy', () => {
|
|
19
|
+
it('should return 0 when trying to delete an empty array of licenses', async () => {
|
|
20
|
+
// Try to delete with an empty array
|
|
21
|
+
const deletedCount = await bulkDestroy([])
|
|
22
|
+
expect(deletedCount).toBe(0)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('should return 0 when trying to soft delete an empty array of licenses', async () => {
|
|
26
|
+
// Try to soft delete with an empty array
|
|
27
|
+
const deletedCount = await bulkSoftDelete([])
|
|
28
|
+
expect(deletedCount).toBe(0)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|