1
1
import { FeaturesConfigEntity } from 'src/modules/feature/entities/features-config.entity' ;
2
2
import {
3
3
FeatureConfig ,
4
- FeatureConfigFilter ,
4
+ FeatureConfigFilter , FeatureConfigFilterAnd , FeatureConfigFilterOr ,
5
5
FeaturesConfig ,
6
6
FeaturesConfigData ,
7
7
} from 'src/modules/feature/model/features-config' ;
8
8
import { classToClass } from 'src/utils' ;
9
+ import { Feature } from 'src/modules/feature/model/feature' ;
10
+ import { FeatureEntity } from 'src/modules/feature/entities/feature.entity' ;
11
+ import { mockAppSettings } from 'src/__mocks__/app-settings' ;
12
+ import config from 'src/utils/config' ;
13
+ import * as defaultConfig from '../../config/features-config.json' ;
9
14
10
15
export const mockFeaturesConfigId = '1' ;
11
- export const mockFeaturesConfigVersion = 1 .111;
16
+ export const mockFeaturesConfigVersion = defaultConfig . version + 0 .111;
12
17
export const mockControlNumber = 7.68 ;
18
+ export const mockControlGroup = '7' ;
13
19
14
20
export const mockFeaturesConfigJson = {
15
21
version : mockFeaturesConfigVersion ,
16
22
features : {
17
23
liveRecommendations : {
18
- perc : [ [ 0 , 10 ] ] ,
24
+ perc : [ [ 1.25 , 8.45 ] ] ,
19
25
flag : true ,
20
26
filters : [
21
27
{
@@ -28,6 +34,49 @@ export const mockFeaturesConfigJson = {
28
34
} ,
29
35
} ;
30
36
37
+ export const mockFeaturesConfigJsonComplex = {
38
+ ...mockFeaturesConfigJson ,
39
+ features : {
40
+ liveRecommendations : {
41
+ ...mockFeaturesConfigJson . features . liveRecommendations ,
42
+ filters : [
43
+ {
44
+ or : [
45
+ {
46
+ name : 'env.FORCE_ENABLE_LIVE_RECOMMENDATIONS' ,
47
+ value : 'true' ,
48
+ type : 'eq' ,
49
+ } ,
50
+ {
51
+ and : [
52
+ {
53
+ name : 'agreements.analytics' ,
54
+ value : true ,
55
+ cond : 'eq' ,
56
+ } ,
57
+ {
58
+ or : [
59
+ {
60
+ name : 'settings.scanThreshold' ,
61
+ value : mockAppSettings . scanThreshold ,
62
+ cond : 'eq' ,
63
+ } ,
64
+ {
65
+ name : 'settings.batchSize' ,
66
+ value : mockAppSettings . batchSize ,
67
+ cond : 'eq' ,
68
+ } ,
69
+ ] ,
70
+ } ,
71
+ ] ,
72
+ } ,
73
+ ] ,
74
+ } ,
75
+ ] ,
76
+ } ,
77
+ } ,
78
+ } ;
79
+
31
80
export const mockFeaturesConfigData = Object . assign ( new FeaturesConfigData ( ) , {
32
81
...mockFeaturesConfigJson ,
33
82
features : new Map ( Object . entries ( {
@@ -40,21 +89,96 @@ export const mockFeaturesConfigData = Object.assign(new FeaturesConfigData(), {
40
89
} ) ) ,
41
90
} ) ;
42
91
92
+ export const mockFeaturesConfigDataComplex = Object . assign ( new FeaturesConfigData ( ) , {
93
+ ...mockFeaturesConfigJson ,
94
+ features : new Map ( Object . entries ( {
95
+ liveRecommendations : Object . assign ( new FeatureConfig ( ) , {
96
+ ...mockFeaturesConfigJson . features . liveRecommendations ,
97
+ filters : [
98
+ Object . assign ( new FeatureConfigFilterOr ( ) , {
99
+ or : [
100
+ Object . assign ( new FeatureConfigFilter ( ) , {
101
+ name : 'env.FORCE_ENABLE_LIVE_RECOMMENDATIONS' ,
102
+ value : 'true' ,
103
+ type : 'eq' ,
104
+ } ) ,
105
+ Object . assign ( new FeatureConfigFilterAnd ( ) , {
106
+ and : [
107
+ Object . assign ( new FeatureConfigFilter ( ) , {
108
+ name : 'agreements.analytics' ,
109
+ value : true ,
110
+ cond : 'eq' ,
111
+ } ) ,
112
+ Object . assign ( new FeatureConfigFilterOr ( ) , {
113
+ or : [
114
+ Object . assign ( new FeatureConfigFilter ( ) , {
115
+ name : 'settings.scanThreshold' ,
116
+ value : mockAppSettings . scanThreshold ,
117
+ cond : 'eq' ,
118
+ } ) ,
119
+ Object . assign ( new FeatureConfigFilter ( ) , {
120
+ name : 'settings.batchSize' ,
121
+ value : mockAppSettings . batchSize ,
122
+ cond : 'eq' ,
123
+ } ) ,
124
+ ] ,
125
+ } ) ,
126
+ ] ,
127
+ } ) ,
128
+ ] ,
129
+ } ) ,
130
+ ] ,
131
+ } ) ,
132
+ } ) ) ,
133
+ } ) ;
134
+
43
135
export const mockFeaturesConfig = Object . assign ( new FeaturesConfig ( ) , {
44
136
controlNumber : mockControlNumber ,
45
137
data : mockFeaturesConfigData ,
46
138
} ) ;
47
139
140
+ export const mockFeaturesConfigComplex = Object . assign ( new FeaturesConfig ( ) , {
141
+ controlNumber : mockControlNumber ,
142
+ data : mockFeaturesConfigDataComplex ,
143
+ } ) ;
144
+
48
145
export const mockFeaturesConfigEntity = Object . assign ( new FeaturesConfigEntity ( ) , {
49
146
...classToClass ( FeaturesConfigEntity , mockFeaturesConfig ) ,
50
147
id : mockFeaturesConfigId ,
51
148
} ) ;
52
149
150
+ export const mockFeaturesConfigEntityComplex = Object . assign ( new FeaturesConfigEntity ( ) , {
151
+ ...classToClass ( FeaturesConfigEntity , mockFeaturesConfigComplex ) ,
152
+ id : mockFeaturesConfigId ,
153
+ } ) ;
154
+
155
+ export const mockFeature = Object . assign ( new Feature ( ) , {
156
+ name : 'liveRecommendations' ,
157
+ flag : true ,
158
+ } ) ;
159
+
160
+ export const mockFeatureEntity = Object . assign ( new FeatureEntity ( ) , {
161
+ id : 'lr-1' ,
162
+ name : 'liveRecommendations' ,
163
+ flag : true ,
164
+ } ) ;
165
+
166
+ export const mockServerState = {
167
+ settings : mockAppSettings ,
168
+ agreements : mockAppSettings . agreements ,
169
+ config : config . get ( ) ,
170
+ env : process . env ,
171
+ } ;
172
+
53
173
export const mockFeaturesConfigRepository = jest . fn ( ( ) => ( {
54
174
getOrCreate : jest . fn ( ) . mockResolvedValue ( mockFeaturesConfig ) ,
55
175
update : jest . fn ( ) . mockResolvedValue ( mockFeaturesConfig ) ,
56
176
} ) ) ;
57
177
58
178
export const mockFeaturesConfigService = ( ) => ( {
59
179
sync : jest . fn ( ) ,
180
+ getControlInfo : jest . fn ( ) . mockResolvedValue ( {
181
+ controlNumber : mockControlNumber ,
182
+ controlGroup : mockControlGroup ,
183
+ } ) ,
60
184
} ) ;
0 commit comments