@unchainedshop/core-orders 3.1.1 → 3.1.2
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 +4 -5
- package/src/module/buildFindSelector.test.ts +43 -32
- package/jest.config.js +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-orders",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"main": "lib/orders-index.js",
|
|
5
5
|
"types": "lib/orders-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"build": "tsc -b",
|
|
10
10
|
"prepublishOnly": "npm run clean && npm run build",
|
|
11
11
|
"watch": "tsc -w",
|
|
12
|
-
"test": "
|
|
13
|
-
"test:watch": "
|
|
12
|
+
"test": "tsx --test",
|
|
13
|
+
"test:watch": "tsx --test --watch"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^22.13.4",
|
|
41
|
-
"
|
|
42
|
-
"ts-jest": "^29.2.5",
|
|
41
|
+
"tsx": "^4.19.2",
|
|
43
42
|
"typescript": "^5.7.3"
|
|
44
43
|
}
|
|
45
44
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
1
3
|
import { OrderStatus } from '../db/OrdersCollection.js';
|
|
2
4
|
import { buildFindByIdSelector as buildFindByIdSelectorForDelivery } from './configureOrderDeliveriesModule.js';
|
|
3
5
|
import { buildFindOrderDiscountByIdSelector } from './configureOrderDiscountsModule.js';
|
|
@@ -11,50 +13,54 @@ import buildFindSelectorForOrder from './buildFindSelector.js';
|
|
|
11
13
|
describe('OrderPosition', () => {
|
|
12
14
|
describe('buildFindSelector', () => {
|
|
13
15
|
it('Return filter object when passed no argument', () => {
|
|
14
|
-
|
|
16
|
+
assert.deepStrictEqual(buildFindSelectorForOrder({}), { status: { $ne: null } });
|
|
15
17
|
});
|
|
16
18
|
|
|
17
|
-
it('Return filter object when passed
|
|
18
|
-
|
|
19
|
+
it('Return filter object when passed includeCarts, queryString, status, userId and (status should take precedence over includeCarts)', () => {
|
|
20
|
+
assert.deepStrictEqual(
|
|
19
21
|
buildFindSelectorForOrder({
|
|
20
22
|
includeCarts: false,
|
|
21
23
|
queryString: 'hello world',
|
|
22
24
|
status: [OrderStatus.CONFIRMED],
|
|
23
25
|
userId: 'admin-id',
|
|
24
26
|
}),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
{
|
|
28
|
+
userId: 'admin-id',
|
|
29
|
+
status: {
|
|
30
|
+
$in: ['CONFIRMED'],
|
|
31
|
+
},
|
|
32
|
+
$text: { $search: 'hello world' },
|
|
29
33
|
},
|
|
30
|
-
|
|
31
|
-
});
|
|
34
|
+
);
|
|
32
35
|
});
|
|
33
36
|
|
|
34
|
-
it('Return filter object when passed
|
|
35
|
-
|
|
37
|
+
it('Return filter object when passed includeCarts, queryString, userId', () => {
|
|
38
|
+
assert.deepStrictEqual(
|
|
36
39
|
buildFindSelectorForOrder({
|
|
37
40
|
includeCarts: true,
|
|
38
41
|
queryString: 'hello world',
|
|
39
42
|
userId: 'admin-id',
|
|
40
43
|
}),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
{
|
|
45
|
+
userId: 'admin-id',
|
|
46
|
+
$text: { $search: 'hello world' },
|
|
47
|
+
},
|
|
48
|
+
);
|
|
46
49
|
});
|
|
47
50
|
|
|
48
|
-
it('Return filter object when passed
|
|
49
|
-
|
|
50
|
-
userId: 'admin-id',
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
it('Return filter object when passed queryString, userId', () => {
|
|
52
|
+
assert.deepStrictEqual(
|
|
53
|
+
buildFindSelectorForOrder({ queryString: 'hello world', userId: 'admin-id' }),
|
|
54
|
+
{
|
|
55
|
+
userId: 'admin-id',
|
|
56
|
+
$text: { $search: 'hello world' },
|
|
57
|
+
status: { $ne: null },
|
|
58
|
+
},
|
|
59
|
+
);
|
|
54
60
|
});
|
|
55
61
|
|
|
56
|
-
it('Return filter object when passed
|
|
57
|
-
|
|
62
|
+
it('Return filter object when passed queryString', () => {
|
|
63
|
+
assert.deepStrictEqual(buildFindSelectorForOrder({ queryString: 'hello world' }), {
|
|
58
64
|
$text: { $search: 'hello world' },
|
|
59
65
|
status: { $ne: null },
|
|
60
66
|
});
|
|
@@ -65,7 +71,7 @@ describe('OrderPosition', () => {
|
|
|
65
71
|
describe('OrderDelivery', () => {
|
|
66
72
|
describe('buildFindByIdSelector', () => {
|
|
67
73
|
it('Return correct db _id selector', () => {
|
|
68
|
-
|
|
74
|
+
assert.deepStrictEqual(buildFindByIdSelectorForDelivery('order-delivery-id'), {
|
|
69
75
|
_id: 'order-delivery-id',
|
|
70
76
|
});
|
|
71
77
|
});
|
|
@@ -75,7 +81,7 @@ describe('OrderDelivery', () => {
|
|
|
75
81
|
describe('OrderDiscount', () => {
|
|
76
82
|
describe('buildFindByIdSelector', () => {
|
|
77
83
|
it('Return correct db _id selector', () => {
|
|
78
|
-
|
|
84
|
+
assert.deepStrictEqual(buildFindOrderDiscountByIdSelector('order-discount-id'), {
|
|
79
85
|
_id: 'order-discount-id',
|
|
80
86
|
});
|
|
81
87
|
});
|
|
@@ -85,16 +91,21 @@ describe('OrderDiscount', () => {
|
|
|
85
91
|
describe('OrderPayment', () => {
|
|
86
92
|
describe('buildFindByIdSelector', () => {
|
|
87
93
|
it('Return correct db _id selector', () => {
|
|
88
|
-
|
|
94
|
+
assert.deepStrictEqual(buildFindOrderPaymentByIdSelector('order-payment-id'), {
|
|
95
|
+
_id: 'order-payment-id',
|
|
96
|
+
});
|
|
89
97
|
});
|
|
90
98
|
});
|
|
91
99
|
|
|
92
100
|
describe('buildFindByContextDataSelector', () => {
|
|
93
101
|
it('Return correct db context field selector object', () => {
|
|
94
|
-
|
|
95
|
-
'
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
assert.deepStrictEqual(
|
|
103
|
+
buildFindByContextDataSelector({ first: 'first value', second: 'second value' }),
|
|
104
|
+
{
|
|
105
|
+
'context.first': 'first value',
|
|
106
|
+
'context.second': 'second value',
|
|
107
|
+
},
|
|
108
|
+
);
|
|
98
109
|
});
|
|
99
110
|
});
|
|
100
111
|
});
|
|
@@ -102,7 +113,7 @@ describe('OrderPayment', () => {
|
|
|
102
113
|
describe('OrderPosition', () => {
|
|
103
114
|
describe('buildFindByIdSelector', () => {
|
|
104
115
|
it('Return correct db _id selector', () => {
|
|
105
|
-
|
|
116
|
+
assert.deepStrictEqual(buildFindOrderPositionByIdSelector('order-position-id'), {
|
|
106
117
|
_id: 'order-position-id',
|
|
107
118
|
});
|
|
108
119
|
});
|
package/jest.config.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
2
|
-
export default {
|
|
3
|
-
preset: 'ts-jest/presets/default-esm', // or other ESM presets
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
extensionsToTreatAsEsm: ['.ts'],
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.tsx?$': [
|
|
8
|
-
'ts-jest',
|
|
9
|
-
{
|
|
10
|
-
useESM: true,
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
},
|
|
14
|
-
moduleNameMapper: {
|
|
15
|
-
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
16
|
-
},
|
|
17
|
-
};
|