@labdigital/commercetools-mock 1.5.0 → 1.6.1

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.
Files changed (129) hide show
  1. package/README.md +5 -4
  2. package/dist/index.cjs +117 -17
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +30 -7
  5. package/dist/index.d.ts +30 -7
  6. package/dist/index.js +117 -17
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -3
  9. package/src/constants.ts +2 -2
  10. package/src/ctMock.ts +176 -176
  11. package/src/exceptions.ts +10 -10
  12. package/src/helpers.ts +26 -26
  13. package/src/index.test.ts +173 -173
  14. package/src/index.ts +3 -3
  15. package/src/lib/expandParser.ts +19 -19
  16. package/src/lib/haversine.test.ts +13 -13
  17. package/src/lib/haversine.ts +14 -14
  18. package/src/lib/masking.ts +15 -15
  19. package/src/lib/parser.ts +2 -2
  20. package/src/lib/predicateParser.test.ts +204 -204
  21. package/src/lib/predicateParser.ts +398 -398
  22. package/src/lib/projectionSearchFilter.test.ts +168 -168
  23. package/src/lib/projectionSearchFilter.ts +272 -269
  24. package/src/lib/proxy.ts +8 -8
  25. package/src/oauth/errors.ts +4 -4
  26. package/src/oauth/helpers.ts +6 -6
  27. package/src/oauth/server.ts +103 -101
  28. package/src/oauth/store.ts +27 -27
  29. package/src/priceSelector.test.ts +68 -68
  30. package/src/priceSelector.ts +70 -70
  31. package/src/product-projection-search.ts +296 -296
  32. package/src/projectAPI.test.ts +3 -3
  33. package/src/projectAPI.ts +46 -46
  34. package/src/repositories/abstract.ts +190 -190
  35. package/src/repositories/associate-role.ts +10 -7
  36. package/src/repositories/attribute-group.ts +63 -8
  37. package/src/repositories/business-unit.ts +10 -7
  38. package/src/repositories/cart-discount.ts +134 -134
  39. package/src/repositories/cart.ts +517 -514
  40. package/src/repositories/category.ts +170 -167
  41. package/src/repositories/channel.ts +114 -111
  42. package/src/repositories/custom-object.ts +66 -63
  43. package/src/repositories/customer-group.ts +72 -69
  44. package/src/repositories/customer.ts +90 -90
  45. package/src/repositories/discount-code.ts +171 -168
  46. package/src/repositories/errors.ts +15 -15
  47. package/src/repositories/extension.ts +79 -76
  48. package/src/repositories/helpers.ts +180 -180
  49. package/src/repositories/index.ts +39 -39
  50. package/src/repositories/inventory-entry.ts +98 -95
  51. package/src/repositories/my-order.ts +11 -11
  52. package/src/repositories/order-edit.ts +29 -29
  53. package/src/repositories/order.test.ts +191 -191
  54. package/src/repositories/order.ts +393 -393
  55. package/src/repositories/payment.ts +155 -155
  56. package/src/repositories/product-discount.ts +149 -149
  57. package/src/repositories/product-projection.ts +135 -50
  58. package/src/repositories/product-selection.ts +31 -31
  59. package/src/repositories/product-type.ts +156 -156
  60. package/src/repositories/product.ts +600 -597
  61. package/src/repositories/project.ts +136 -135
  62. package/src/repositories/quote-request.ts +19 -19
  63. package/src/repositories/quote.ts +19 -19
  64. package/src/repositories/review.ts +24 -24
  65. package/src/repositories/shipping-method.ts +217 -217
  66. package/src/repositories/shopping-list.ts +49 -49
  67. package/src/repositories/staged-quote.ts +20 -20
  68. package/src/repositories/standalone-price.ts +72 -61
  69. package/src/repositories/state.ts +84 -84
  70. package/src/repositories/store.ts +114 -114
  71. package/src/repositories/subscription.ts +40 -40
  72. package/src/repositories/tax-category.ts +98 -98
  73. package/src/repositories/type.ts +157 -157
  74. package/src/repositories/zone.ts +71 -71
  75. package/src/server.ts +2 -2
  76. package/src/services/abstract.ts +173 -173
  77. package/src/services/attribute-group.ts +16 -0
  78. package/src/services/cart-discount.ts +8 -8
  79. package/src/services/cart.test.ts +409 -409
  80. package/src/services/cart.ts +50 -50
  81. package/src/services/category.test.ts +25 -25
  82. package/src/services/category.ts +8 -8
  83. package/src/services/channel.ts +8 -8
  84. package/src/services/custom-object.test.ts +184 -184
  85. package/src/services/custom-object.ts +48 -48
  86. package/src/services/customer-group.ts +8 -8
  87. package/src/services/customer.test.ts +151 -151
  88. package/src/services/customer.ts +27 -27
  89. package/src/services/discount-code.ts +8 -8
  90. package/src/services/extension.ts +8 -8
  91. package/src/services/index.ts +52 -44
  92. package/src/services/inventory-entry.test.ts +162 -162
  93. package/src/services/inventory-entry.ts +8 -8
  94. package/src/services/my-cart.test.ts +78 -78
  95. package/src/services/my-cart.ts +28 -28
  96. package/src/services/my-customer.test.ts +44 -44
  97. package/src/services/my-customer.ts +53 -53
  98. package/src/services/my-order.ts +20 -20
  99. package/src/services/my-payment.test.ts +65 -65
  100. package/src/services/my-payment.ts +8 -8
  101. package/src/services/order.test.ts +527 -527
  102. package/src/services/order.ts +31 -31
  103. package/src/services/payment.test.ts +65 -65
  104. package/src/services/payment.ts +8 -8
  105. package/src/services/product-discount.ts +8 -8
  106. package/src/services/product-projection.test.ts +502 -428
  107. package/src/services/product-projection.ts +32 -18
  108. package/src/services/product-type.test.ts +56 -56
  109. package/src/services/product-type.ts +8 -8
  110. package/src/services/product.test.ts +510 -510
  111. package/src/services/product.ts +8 -8
  112. package/src/services/project.ts +34 -34
  113. package/src/services/shipping-method.test.ts +81 -81
  114. package/src/services/shipping-method.ts +12 -12
  115. package/src/services/shopping-list.ts +8 -8
  116. package/src/services/standalone-price.test.ts +256 -256
  117. package/src/services/standalone-price.ts +8 -8
  118. package/src/services/state.test.ts +42 -42
  119. package/src/services/state.ts +8 -8
  120. package/src/services/store.test.ts +57 -57
  121. package/src/services/store.ts +8 -8
  122. package/src/services/subscription.ts +8 -8
  123. package/src/services/tax-category.test.ts +61 -61
  124. package/src/services/tax-category.ts +8 -8
  125. package/src/services/type.ts +8 -8
  126. package/src/services/zone.ts +8 -8
  127. package/src/storage/abstract.ts +58 -58
  128. package/src/storage/in-memory.ts +419 -419
  129. package/src/types.ts +82 -82
@@ -5,172 +5,172 @@ import { applyPriceSelector } from '../priceSelector.js'
5
5
  import { parseFilterExpression } from './projectionSearchFilter.js'
6
6
 
7
7
  describe('Search filter', () => {
8
- const exampleProduct: ProductProjection = {
9
- id: '7401d82f-1378-47ba-996a-85beeb87ac87',
10
- version: 2,
11
- createdAt: '2022-07-22T10:02:40.851Z',
12
- lastModifiedAt: '2022-07-22T10:02:44.427Z',
13
- key: 'test-product',
14
- productType: {
15
- typeId: 'product-type',
16
- id: 'b9b4b426-938b-4ccb-9f36-c6f933e8446e',
17
- },
18
- name: {
19
- 'nl-NL': 'test',
20
- },
21
- slug: {
22
- 'nl-NL': 'test',
23
- },
24
- variants: [],
25
- searchKeywords: {},
26
- categories: [],
27
- masterVariant: {
28
- id: 1,
29
- sku: 'MYSKU',
30
- attributes: [
31
- {
32
- name: 'Country',
33
- value: {
34
- key: 'NL',
35
- label: {
36
- de: 'niederlande',
37
- en: 'netherlands',
38
- nl: 'nederland',
39
- },
40
- },
41
- },
42
- {
43
- name: 'number',
44
- value: 4,
45
- },
46
- ],
47
- prices: [
48
- {
49
- id: 'dummy-uuid',
50
- value: {
51
- type: 'centPrecision',
52
- currencyCode: 'EUR',
53
- centAmount: 1789,
54
- fractionDigits: 2,
55
- },
56
- },
57
- ],
58
- },
59
- }
60
-
61
- const match = (pattern: string, product?: ProductProjection) => {
62
- const matchFunc = parseFilterExpression(pattern)
63
- const clone = cloneObject(product ?? exampleProduct)
64
- return {
65
- isMatch: matchFunc(clone, false),
66
- product: clone,
67
- }
68
- }
69
-
70
- test('by product key', async () => {
71
- expect(match(`key:exists`).isMatch).toBeTruthy()
72
- expect(match(`key:missing`).isMatch).toBeFalsy()
73
- expect(match(`key:"test-product"`).isMatch).toBeTruthy()
74
- })
75
-
76
- test('by product type id', async () => {
77
- expect(
78
- match(`productType.id:"b9b4b426-938b-4ccb-9f36-c6f933e8446e"`).isMatch
79
- ).toBeTruthy()
80
- })
81
-
82
- test('by SKU', async () => {
83
- expect(match(`variants.sku:exists`).isMatch).toBeTruthy()
84
- expect(match(`variants.sku:missing`).isMatch).toBeFalsy()
85
- expect(match(`variants.sku:"MYSKU"`).isMatch).toBeTruthy()
86
- })
87
-
88
- test('by attribute value', async () => {
89
- expect(match(`variants.attributes.number:4`).isMatch).toBeTruthy()
90
- expect(match(`variants.attributes.number:3,4`).isMatch).toBeTruthy()
91
- expect(match(`variants.attributes.number:3,4,5`).isMatch).toBeTruthy()
92
- expect(match(`variants.attributes.number:1,2,3,5`).isMatch).toBeFalsy()
93
- })
94
-
95
- test('by attribute range', async () => {
96
- expect(
97
- match(`variants.attributes.number:range (0 TO 5)`).isMatch
98
- ).toBeTruthy()
99
-
100
- expect(
101
- match(`variants.attributes.number:range (* TO 5)`).isMatch
102
- ).toBeTruthy()
103
-
104
- expect(
105
- match(`variants.attributes.number:range (* TO *)`).isMatch
106
- ).toBeTruthy()
107
- })
108
-
109
- test('by attribute enum key', async () => {
110
- expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy()
111
- expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy()
112
- })
113
-
114
- test('by attribute enum key', async () => {
115
- expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy()
116
- expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy()
117
- })
118
-
119
- test('by price range', async () => {
120
- expect(
121
- match(`variants.price.centAmount:range (1500 TO 2000)`).isMatch
122
- ).toBeTruthy()
123
- })
124
-
125
- test('by price range - or', async () => {
126
- expect(
127
- match(
128
- `variants.price.centAmount:range (2 TO 1500 ), (1500 TO 3000), (3000 TO 6000)`
129
- ).isMatch
130
- ).toBeTruthy()
131
- })
132
-
133
- test('by scopedPrice range', async () => {
134
- let result
135
- let products: ProductProjection[]
136
-
137
- // No currency given
138
- result = match(`variants.scopedPrice.value.centAmount:range (1500 TO 2000)`)
139
- expect(result.isMatch).toBeFalsy()
140
-
141
- // Currency match
142
- products = [cloneObject(exampleProduct)]
143
- applyPriceSelector(products, { currency: 'EUR' })
144
-
145
- result = match(
146
- `variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
147
- products[0]
148
- )
149
- expect(result.isMatch).toBeTruthy()
150
- expect(result.product).toMatchObject({
151
- masterVariant: {
152
- sku: 'MYSKU',
153
- scopedPrice: { value: { centAmount: 1789 } },
154
- },
155
- })
156
-
157
- // Currency mismatch
158
- products = [cloneObject(exampleProduct)]
159
- applyPriceSelector(products, { currency: 'USD' })
160
-
161
- result = match(
162
- `variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
163
- products[0]
164
- )
165
- expect(result.isMatch).toBeFalsy()
166
-
167
- // Price has no country so mismatch
168
- products = [cloneObject(exampleProduct)]
169
- applyPriceSelector(products, { currency: 'EUR', country: 'NL' })
170
- result = match(
171
- `variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
172
- products[0]
173
- )
174
- expect(result.isMatch).toBeFalsy()
175
- })
8
+ const exampleProduct: ProductProjection = {
9
+ id: '7401d82f-1378-47ba-996a-85beeb87ac87',
10
+ version: 2,
11
+ createdAt: '2022-07-22T10:02:40.851Z',
12
+ lastModifiedAt: '2022-07-22T10:02:44.427Z',
13
+ key: 'test-product',
14
+ productType: {
15
+ typeId: 'product-type',
16
+ id: 'b9b4b426-938b-4ccb-9f36-c6f933e8446e',
17
+ },
18
+ name: {
19
+ 'nl-NL': 'test',
20
+ },
21
+ slug: {
22
+ 'nl-NL': 'test',
23
+ },
24
+ variants: [],
25
+ searchKeywords: {},
26
+ categories: [],
27
+ masterVariant: {
28
+ id: 1,
29
+ sku: 'MYSKU',
30
+ attributes: [
31
+ {
32
+ name: 'Country',
33
+ value: {
34
+ key: 'NL',
35
+ label: {
36
+ de: 'niederlande',
37
+ en: 'netherlands',
38
+ nl: 'nederland',
39
+ },
40
+ },
41
+ },
42
+ {
43
+ name: 'number',
44
+ value: 4,
45
+ },
46
+ ],
47
+ prices: [
48
+ {
49
+ id: 'dummy-uuid',
50
+ value: {
51
+ type: 'centPrecision',
52
+ currencyCode: 'EUR',
53
+ centAmount: 1789,
54
+ fractionDigits: 2,
55
+ },
56
+ },
57
+ ],
58
+ },
59
+ }
60
+
61
+ const match = (pattern: string, product?: ProductProjection) => {
62
+ const matchFunc = parseFilterExpression(pattern)
63
+ const clone = cloneObject(product ?? exampleProduct)
64
+ return {
65
+ isMatch: matchFunc(clone, false),
66
+ product: clone,
67
+ }
68
+ }
69
+
70
+ test('by product key', async () => {
71
+ expect(match(`key:exists`).isMatch).toBeTruthy()
72
+ expect(match(`key:missing`).isMatch).toBeFalsy()
73
+ expect(match(`key:"test-product"`).isMatch).toBeTruthy()
74
+ })
75
+
76
+ test('by product type id', async () => {
77
+ expect(
78
+ match(`productType.id:"b9b4b426-938b-4ccb-9f36-c6f933e8446e"`).isMatch
79
+ ).toBeTruthy()
80
+ })
81
+
82
+ test('by SKU', async () => {
83
+ expect(match(`variants.sku:exists`).isMatch).toBeTruthy()
84
+ expect(match(`variants.sku:missing`).isMatch).toBeFalsy()
85
+ expect(match(`variants.sku:"MYSKU"`).isMatch).toBeTruthy()
86
+ })
87
+
88
+ test('by attribute value', async () => {
89
+ expect(match(`variants.attributes.number:4`).isMatch).toBeTruthy()
90
+ expect(match(`variants.attributes.number:3,4`).isMatch).toBeTruthy()
91
+ expect(match(`variants.attributes.number:3,4,5`).isMatch).toBeTruthy()
92
+ expect(match(`variants.attributes.number:1,2,3,5`).isMatch).toBeFalsy()
93
+ })
94
+
95
+ test('by attribute range', async () => {
96
+ expect(
97
+ match(`variants.attributes.number:range (0 TO 5)`).isMatch
98
+ ).toBeTruthy()
99
+
100
+ expect(
101
+ match(`variants.attributes.number:range (* TO 5)`).isMatch
102
+ ).toBeTruthy()
103
+
104
+ expect(
105
+ match(`variants.attributes.number:range (* TO *)`).isMatch
106
+ ).toBeTruthy()
107
+ })
108
+
109
+ test('by attribute enum key', async () => {
110
+ expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy()
111
+ expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy()
112
+ })
113
+
114
+ test('by attribute enum key', async () => {
115
+ expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy()
116
+ expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy()
117
+ })
118
+
119
+ test('by price range', async () => {
120
+ expect(
121
+ match(`variants.price.centAmount:range (1500 TO 2000)`).isMatch
122
+ ).toBeTruthy()
123
+ })
124
+
125
+ test('by price range - or', async () => {
126
+ expect(
127
+ match(
128
+ `variants.price.centAmount:range (2 TO 1500 ), (1500 TO 3000), (3000 TO 6000)`
129
+ ).isMatch
130
+ ).toBeTruthy()
131
+ })
132
+
133
+ test('by scopedPrice range', async () => {
134
+ let result
135
+ let products: ProductProjection[]
136
+
137
+ // No currency given
138
+ result = match(`variants.scopedPrice.value.centAmount:range (1500 TO 2000)`)
139
+ expect(result.isMatch).toBeFalsy()
140
+
141
+ // Currency match
142
+ products = [cloneObject(exampleProduct)]
143
+ applyPriceSelector(products, { currency: 'EUR' })
144
+
145
+ result = match(
146
+ `variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
147
+ products[0]
148
+ )
149
+ expect(result.isMatch).toBeTruthy()
150
+ expect(result.product).toMatchObject({
151
+ masterVariant: {
152
+ sku: 'MYSKU',
153
+ scopedPrice: { value: { centAmount: 1789 } },
154
+ },
155
+ })
156
+
157
+ // Currency mismatch
158
+ products = [cloneObject(exampleProduct)]
159
+ applyPriceSelector(products, { currency: 'USD' })
160
+
161
+ result = match(
162
+ `variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
163
+ products[0]
164
+ )
165
+ expect(result.isMatch).toBeFalsy()
166
+
167
+ // Price has no country so mismatch
168
+ products = [cloneObject(exampleProduct)]
169
+ applyPriceSelector(products, { currency: 'EUR', country: 'NL' })
170
+ result = match(
171
+ `variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
172
+ products[0]
173
+ )
174
+ expect(result.isMatch).toBeFalsy()
175
+ })
176
176
  })