@@ -22,32 +22,35 @@ define([
22
22
'use strict' ;
23
23
24
24
var injector = new Squire ( ) ,
25
- customerData ,
26
- productResolver ,
27
- productResolverIds ,
28
- storage ,
29
- mocks ,
30
25
obj ,
26
+ customerDataIds ,
31
27
localStorageIds ,
28
+ timestamp ,
32
29
namespace = 'namespace' ,
33
- windowCheckoutData ,
34
- timestamp ;
35
-
36
- beforeEach ( function ( done ) {
37
- customerData = { } ;
38
- productResolverIds = [ ] ;
30
+ windowCheckoutData = window . checkout ,
31
+ customerDataGet = function ( ) {
32
+ return {
33
+ items : customerDataIds
34
+ } ;
35
+ } ,
36
+ customerData = {
37
+ get : jasmine . createSpy ( ) . and . returnValue ( customerDataGet )
38
+ } ,
39
+ productResolverIds = [ ] ,
39
40
productResolver = jasmine . createSpy ( ) . and . callFake ( function ( ) {
40
41
return productResolverIds ;
41
- } ) ;
42
+ } ) ,
42
43
storage = {
43
44
onStorageInit : jasmine . createSpy ( ) ,
44
45
createStorage : jasmine . createSpy ( )
45
- } ;
46
+ } ,
46
47
mocks = {
47
48
'Magento_Customer/js/customer-data' : customerData ,
48
49
'Magento_Catalog/js/product/view/product-ids-resolver' : productResolver ,
49
50
'Magento_Catalog/js/product/storage/storage-service' : storage
50
51
} ;
52
+
53
+ beforeEach ( function ( done ) {
51
54
injector . mock ( mocks ) ;
52
55
injector . require ( [ 'Magento_Catalog/js/product/provider' ] , function ( UiClass ) {
53
56
timestamp = new Date ( ) . getTime ( ) / 1000 ;
@@ -75,14 +78,20 @@ define([
75
78
scope_id : 1
76
79
} ,
77
80
'website-1-3' : {
78
- added_at : timestamp - 120 ,
81
+ added_at : timestamp - 180 ,
79
82
product_id : 3 ,
80
83
scope_id : 1
81
84
}
82
85
} ;
86
+ customerDataIds = {
87
+ 4 : {
88
+ added_at : timestamp - 360 ,
89
+ product_id : 4 ,
90
+ scope_id : 1
91
+ }
92
+ } ;
83
93
done ( ) ;
84
94
} ) ;
85
- windowCheckoutData = window . checkout ;
86
95
} ) ;
87
96
88
97
afterEach ( function ( ) {
@@ -116,20 +125,8 @@ define([
116
125
expect ( obj . idsMerger ) . not . toHaveBeenCalled ( ) ;
117
126
} ) ;
118
127
it ( 'check that initial ids, localstorage ids and ids from customer data are processed' , function ( ) {
119
- var initialIds ,
120
- customerDataIds ,
121
- customerDataGet ;
122
-
123
- initialIds = obj . ids ( ) ;
124
- customerDataIds = {
125
- 4 : { } ,
126
- 6 : { }
127
- } ;
128
- customerDataGet = function ( ) {
129
- return {
130
- items : customerDataIds
131
- } ;
132
- } ;
128
+ var initialIds = obj . ids ( ) ;
129
+
133
130
window . checkout = {
134
131
baseUrl : 'http://localhost/' ,
135
132
websiteId : 1
@@ -179,11 +176,11 @@ define([
179
176
} ) ;
180
177
181
178
it ( 'argument is an object and has "items" property' , function ( ) {
182
- expect ( obj . prepareDataFromCustomerData ( { items : { 1 : { } , 2 : { } } } ) ) . toEqual ( { 1 : { } , 2 : { } } ) ;
179
+ expect ( obj . prepareDataFromCustomerData ( { items : customerDataIds } ) ) . toEqual ( customerDataIds ) ;
183
180
} ) ;
184
181
185
182
it ( 'argument is an object and does not have "items" property' , function ( ) {
186
- expect ( obj . prepareDataFromCustomerData ( { 1 : { } , 2 : { } } ) ) . toEqual ( { 1 : { } , 2 : { } } ) ;
183
+ expect ( obj . prepareDataFromCustomerData ( customerDataIds ) ) . toEqual ( customerDataIds ) ;
187
184
} ) ;
188
185
} ) ;
189
186
@@ -203,7 +200,7 @@ define([
203
200
} ) ;
204
201
205
202
it ( 'filters out expired ids' , function ( ) {
206
- obj . idsStorage . lifetime = 70 ;
203
+ obj . idsStorage . lifetime = 100 ;
207
204
expect ( obj . filterIds ( localStorageIds ) ) . toEqual ( { 2 : localStorageIds [ 'website-1-2' ] } ) ;
208
205
} ) ;
209
206
0 commit comments