1
1
/* eslint-disable jest/no-disabled-tests */
2
2
/* eslint-disable jest/valid-title */
3
3
import { Category } from '@commercetools-test-data/category' ;
4
- import { LocalizedString , Reference } from '@commercetools-test-data/commons' ;
4
+ import { LocalizedString } from '@commercetools-test-data/commons' ;
5
5
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils' ;
6
6
import { ProductVariant } from '@commercetools-test-data/product' ;
7
7
import { ProductType } from '@commercetools-test-data/product-type' ;
8
- import {
9
- TProductProjection ,
10
- TProductProjectionGraphql ,
11
- TProductProjectionRest ,
12
- } from './types' ;
8
+ import { State } from '@commercetools-test-data/state' ;
9
+ import { TaxCategory } from '@commercetools-test-data/tax-category' ;
10
+ import { TProductProjectionGraphql , TProductProjectionRest } from './types' ;
13
11
import * as ProductProjection from './index' ;
14
12
15
13
describe ( 'builder' , ( ) => {
@@ -27,99 +25,9 @@ describe('builder', () => {
27
25
] ) ;
28
26
29
27
it (
30
- ...createBuilderSpec < TProductProjection , TProductProjection > (
31
- 'default' ,
32
- ProductProjection . random ( ) ,
33
- expect . objectContaining ( {
34
- id : expect . any ( String ) ,
35
- version : expect . any ( Number ) ,
36
- key : expect . any ( String ) ,
37
- productType : expect . objectContaining ( {
38
- id : expect . any ( String ) ,
39
- key : expect . any ( String ) ,
40
- version : expect . any ( Number ) ,
41
- createdAt : expect . any ( String ) ,
42
- createdBy : expect . objectContaining ( {
43
- customer : expect . objectContaining ( { typeId : 'customer' } ) ,
44
- } ) ,
45
- lastModifiedAt : expect . any ( String ) ,
46
- lastModifiedBy : expect . objectContaining ( {
47
- customer : expect . objectContaining ( { typeId : 'customer' } ) ,
48
- } ) ,
49
- name : expect . any ( String ) ,
50
- description : expect . any ( String ) ,
51
- attributes : expect . arrayContaining ( [
52
- expect . objectContaining ( {
53
- type : expect . objectContaining ( { name : expect . any ( String ) } ) ,
54
- name : expect . any ( String ) ,
55
- label : expect . objectContaining ( {
56
- de : expect . any ( String ) ,
57
- en : expect . any ( String ) ,
58
- fr : expect . any ( String ) ,
59
- } ) ,
60
- isRequired : expect . any ( Boolean ) ,
61
- attributeConstraint : expect . any ( String ) ,
62
- inputTip : expect . objectContaining ( {
63
- de : expect . any ( String ) ,
64
- en : expect . any ( String ) ,
65
- fr : expect . any ( String ) ,
66
- } ) ,
67
- inputHint : expect . any ( String ) ,
68
- isSearchable : expect . any ( Boolean ) ,
69
- } ) ,
70
- ] ) ,
71
- } ) ,
72
- name : expectedGeneralLocalizedString ,
73
- description : expectedGeneralLocalizedString ,
74
- slug : expectedGeneralLocalizedString ,
75
- categories : [ ] ,
76
- categoryOrderHints : null ,
77
- metaTitle : null ,
78
- metaDescription : null ,
79
- metaKeywords : null ,
80
- searchKeywords : [ ] ,
81
- hasStagedChanges : expect . any ( Boolean ) ,
82
- published : expect . any ( Boolean ) ,
83
- masterVariant : expect . objectContaining ( {
84
- key : expect . any ( String ) ,
85
- sku : expect . any ( String ) ,
86
- prices : expect . arrayContaining ( [
87
- expect . objectContaining ( {
88
- value : expect . any ( Object ) ,
89
- } ) ,
90
- ] ) ,
91
- price : null ,
92
- images : expect . arrayContaining ( [
93
- expect . objectContaining ( {
94
- url : expect . any ( String ) ,
95
- } ) ,
96
- ] ) ,
97
- attributes : expect . arrayContaining ( [
98
- expect . objectContaining ( {
99
- name : expect . any ( String ) ,
100
- } ) ,
101
- ] ) ,
102
- assets : expect . arrayContaining ( [ ] ) ,
103
- availability : null ,
104
- isMatchingVariant : expect . any ( Boolean ) ,
105
- scopedPrice : null ,
106
- scopedPriceDiscounted : null ,
107
- } ) ,
108
- variants : [ ] ,
109
- taxCategory : null ,
110
- state : null ,
111
- createdAt : expect . any ( String ) ,
112
- lastModifiedAt : expect . any ( String ) ,
113
- reviewRatingStatistics : null ,
114
- priceMode : null ,
115
- } )
116
- )
117
- ) ;
118
-
119
- it (
120
- ...createBuilderSpec < TProductProjection , TProductProjectionRest > (
28
+ ...createBuilderSpec < TProductProjectionRest , TProductProjectionRest > (
121
29
'rest' ,
122
- ProductProjection . random ( ) ,
30
+ ProductProjection . ProductProjectionRest . random ( ) ,
123
31
expect . objectContaining ( {
124
32
id : expect . any ( String ) ,
125
33
version : expect . any ( Number ) ,
@@ -199,9 +107,9 @@ describe('builder', () => {
199
107
) ;
200
108
201
109
it (
202
- ...createBuilderSpec < TProductProjection , TProductProjectionGraphql > (
110
+ ...createBuilderSpec < TProductProjectionGraphql , TProductProjectionGraphql > (
203
111
'graphql' ,
204
- ProductProjection . random ( ) ,
112
+ ProductProjection . ProductProjectionGraphql . random ( ) ,
205
113
expect . objectContaining ( {
206
114
id : expect . any ( String ) ,
207
115
version : expect . any ( Number ) ,
@@ -225,8 +133,11 @@ describe('builder', () => {
225
133
categories : [ ] ,
226
134
categoryOrderHints : [ ] ,
227
135
metaTitle : null ,
136
+ metaTitleAllLocales : null ,
228
137
metaDescription : null ,
138
+ metaDescriptionAllLocales : null ,
229
139
metaKeywords : null ,
140
+ metaKeywordsAllLocales : null ,
230
141
searchKeywords : [ ] ,
231
142
hasStagedChanges : expect . any ( Boolean ) ,
232
143
published : expect . any ( Boolean ) ,
@@ -236,47 +147,55 @@ describe('builder', () => {
236
147
sku : expect . any ( String ) ,
237
148
} ) ,
238
149
variants : [ ] ,
239
- taxCategory : undefined ,
240
- state : undefined ,
150
+ taxCategory : null ,
151
+ state : null ,
241
152
createdAt : expect . any ( String ) ,
242
153
lastModifiedAt : expect . any ( String ) ,
243
- reviewRatingStatistics : undefined ,
244
- priceMode : null ,
154
+ reviewRatingStatistics : null ,
245
155
} )
246
156
)
247
157
) ;
248
158
249
159
it ( 'should allow customization' , ( ) => {
250
- const productProjectionMock = ProductProjection . presets
251
- . happyCowMilkProductProjection ( )
252
- . categories ( [
253
- Category . random ( )
254
- . id ( 'category-id' )
255
- . name ( LocalizedString . presets . empty ( ) . en ( 'category-name' ) ) ,
256
- ] )
257
- . categoryOrderHints ( {
258
- 'category-1' : '0.4' ,
259
- } )
260
- . id ( 'happy-cow-milk-id' )
261
- . key ( 'happy-cow-milk-key' )
262
- . metaKeywords ( LocalizedString . presets . empty ( ) . en ( 'happy' ) )
263
- . priceMode ( 'Embedded' )
264
- . productType ( ProductType . presets . milk ( ) . id ( 'product-type-id' ) )
265
- . reviewRatingStatistics ( {
266
- averageRating : 3.12345 ,
267
- highestRating : 4.9 ,
268
- lowestRating : 2.1 ,
269
- count : 25 ,
270
- ratingsDistribution : { } ,
271
- } )
272
- . searchKeywords ( {
273
- en : [ { text : 'product search keyword' } ] ,
274
- } )
275
- . state ( Reference . presets . stateReference ( ) )
276
- . taxCategory ( Reference . presets . taxCategoryReference ( ) )
277
- . variants ( [ ProductVariant . random ( ) . key ( 'alternative-variant-key' ) ] )
278
- . version ( 222 )
279
- . buildGraphql < TProductProjectionGraphql > ( ) ;
160
+ const productProjectionMock =
161
+ ProductProjection . ProductProjectionGraphql . presets
162
+ . happyCowMilk ( )
163
+ . categories ( [
164
+ Category . random ( )
165
+ . id ( 'category-id' )
166
+ . name ( LocalizedString . presets . empty ( ) . en ( 'category-name' ) ) ,
167
+ ] )
168
+ . categoryOrderHints ( [
169
+ {
170
+ __typename : 'CategoryOrderHintProductSearch' ,
171
+ categoryId : 'category-1' ,
172
+ orderHint : '0.4' ,
173
+ } ,
174
+ ] )
175
+ . id ( 'happy-cow-milk-id' )
176
+ . key ( 'happy-cow-milk-key' )
177
+ . metaKeywordsAllLocales ( LocalizedString . presets . empty ( ) . en ( 'happy' ) )
178
+ . productType ( ProductType . presets . milk ( ) . id ( 'product-type-id' ) )
179
+ . reviewRatingStatistics ( {
180
+ averageRating : 3.12345 ,
181
+ highestRating : 4.9 ,
182
+ lowestRating : 2.1 ,
183
+ count : 25 ,
184
+ ratingsDistribution : { } ,
185
+ __typename : 'ReviewRatingStatistics' ,
186
+ } )
187
+ . searchKeywords ( [
188
+ {
189
+ __typename : 'SearchKeywordsProductSearch' ,
190
+ locale : 'en' ,
191
+ searchKeywords : [ { text : 'product search keyword' } ] ,
192
+ } ,
193
+ ] )
194
+ . state ( State . random ( ) . id ( 'state-id' ) )
195
+ . taxCategory ( TaxCategory . random ( ) . id ( 'tax-category-id' ) )
196
+ . variants ( [ ProductVariant . random ( ) . key ( 'alternative-variant-key' ) ] )
197
+ . version ( 222 )
198
+ . buildGraphql < TProductProjectionGraphql > ( ) ;
280
199
281
200
const expectedLocalizedName = expect . arrayContaining ( [
282
201
expect . objectContaining ( {
@@ -312,7 +231,7 @@ describe('builder', () => {
312
231
{
313
232
categoryId : 'category-1' ,
314
233
orderHint : '0.4' ,
315
- __typename : 'CategoryOrderHint ' ,
234
+ __typename : 'CategoryOrderHintProductSearch ' ,
316
235
} ,
317
236
] ) ,
318
237
categoriesRef : expect . arrayContaining ( [
@@ -339,13 +258,13 @@ describe('builder', () => {
339
258
expect . objectContaining ( {
340
259
locale : 'en' ,
341
260
value : 'happy' ,
261
+ __typename : 'LocalizedString' ,
342
262
} ) ,
343
263
] ) ,
344
264
metaTitle : 'Happy Cow Milk' ,
345
265
metaTitleAllLocales : expectedLocalizedName ,
346
266
name : 'Happy Cow Milk' ,
347
267
nameAllLocales : expectedLocalizedName ,
348
- priceMode : 'Embedded' ,
349
268
productType : expect . objectContaining ( {
350
269
__typename : 'ProductTypeDefinition' ,
351
270
name : 'Milk Product Type' ,
@@ -384,18 +303,20 @@ describe('builder', () => {
384
303
} ) ,
385
304
] ) ,
386
305
state : expect . objectContaining ( {
387
- id : 'product-type -id' ,
306
+ id : 'state -id' ,
388
307
__typename : 'State' ,
389
308
} ) ,
390
309
stateRef : expect . objectContaining ( {
310
+ id : 'state-id' ,
391
311
typeId : 'state' ,
392
312
__typename : 'Reference' ,
393
313
} ) ,
394
314
taxCategory : expect . objectContaining ( {
395
- id : 'product-type -id' ,
315
+ id : 'tax-category -id' ,
396
316
__typename : 'TaxCategory' ,
397
317
} ) ,
398
318
taxCategoryRef : expect . objectContaining ( {
319
+ id : 'tax-category-id' ,
399
320
typeId : 'tax-category' ,
400
321
__typename : 'Reference' ,
401
322
} ) ,
0 commit comments