@@ -5,24 +5,24 @@ import {
5
5
mockCloudSubscriptionApiProvider ,
6
6
mockCloudSubscriptionCapiService ,
7
7
mockCloudSubscriptionRegions ,
8
+ mockFeatureService ,
8
9
mockSessionMetadata ,
9
10
mockSubscriptionPlanResponse ,
10
11
MockType ,
11
12
} from 'src/__mocks__' ;
12
13
import { CloudApiUnauthorizedException } from 'src/modules/cloud/common/exceptions' ;
13
14
import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.service' ;
15
+ import { FeatureService } from 'src/modules/feature/feature.service' ;
14
16
import { CloudSubscriptionApiService } from './cloud-subscription.api.service' ;
15
- import { CloudUserApiService } from '../user/cloud-user.api.service' ;
16
17
import { CloudSessionService } from '../session/cloud-session.service' ;
17
18
import { CloudSubscriptionCapiService } from './cloud-subscription.capi.service' ;
18
19
import { CloudSubscriptionApiProvider } from './providers/cloud-subscription.api.provider' ;
19
20
20
21
describe ( 'CloudSubscriptionApiService' , ( ) => {
21
22
let service : CloudSubscriptionApiService ;
22
23
let api : MockType < CloudSubscriptionApiProvider > ;
23
- let sessionService : MockType < CloudSessionService > ;
24
- let cloudUserApiService : MockType < CloudUserApiService > ;
25
- let cloudSubscriptionCapiService : MockType < CloudSubscriptionCapiService > ;
24
+ let capi : MockType < CloudSubscriptionCapiService > ;
25
+ let featureService : MockType < FeatureService > ;
26
26
27
27
beforeEach ( async ( ) => {
28
28
const module : TestingModule = await Test . createTestingModule ( {
@@ -44,11 +44,17 @@ describe('CloudSubscriptionApiService', () => {
44
44
provide : CloudCapiKeyService ,
45
45
useFactory : mockCloudCapiKeyService ,
46
46
} ,
47
+ {
48
+ provide : FeatureService ,
49
+ useFactory : mockFeatureService ,
50
+ } ,
47
51
] ,
48
52
} ) . compile ( ) ;
49
53
50
54
service = module . get ( CloudSubscriptionApiService ) ;
51
55
api = module . get ( CloudSubscriptionApiProvider ) ;
56
+ capi = module . get ( CloudSubscriptionCapiService ) ;
57
+ featureService = module . get ( FeatureService ) ;
52
58
} ) ;
53
59
54
60
describe ( 'getSubscriptionPlans' , ( ) => {
@@ -61,6 +67,55 @@ describe('CloudSubscriptionApiService', () => {
61
67
CloudApiUnauthorizedException ,
62
68
) ;
63
69
} ) ;
70
+
71
+ describe ( 'filter' , ( ) => {
72
+ beforeEach ( ( ) => {
73
+ featureService . getByName . mockResolvedValueOnce ( {
74
+ flag : true ,
75
+ data : {
76
+ filterFreePlan : [ {
77
+ field : 'name' ,
78
+ expression : '^(No HA?.)|(Cache?.)' ,
79
+ options : 'i' ,
80
+ } ] ,
81
+ } ,
82
+ } ) ;
83
+ } ) ;
84
+
85
+ it ( 'get empty list due to filter' , async ( ) => {
86
+ capi . getSubscriptionsPlans . mockResolvedValueOnce ( [
87
+ { name : 'some name' , price : 0 } ,
88
+ ] ) ;
89
+ expect ( await service . getSubscriptionPlans ( mockSessionMetadata ) ) . toEqual ( [ ] ) ;
90
+ } ) ;
91
+
92
+ it ( 'filter only "no ha" and "cache" plans' , async ( ) => {
93
+ capi . getSubscriptionsPlans . mockResolvedValueOnce ( [
94
+ { name : 'some name' , price : 0 } ,
95
+ { name : 'no thing' , price : 0 } ,
96
+ { name : 'No HA' , price : 0 } ,
97
+ { name : 'No HA 30MB price:0' , price : 0 } ,
98
+ { name : 'No HA 30MB price:1' , price : 1 } ,
99
+ { name : 'no ha 30MB' , price : 0 } ,
100
+ { name : 'no ha' , price : 0 } ,
101
+ { name : 'Cache' , price : 0 } ,
102
+ { name : 'Cache 30MB' , price : 0 } ,
103
+ { name : 'cache' , price : 0 } ,
104
+ { name : 'cache 30MB' , price : 0 } ,
105
+ { name : '' , price : 0 } ,
106
+ ] ) ;
107
+ expect ( await service . getSubscriptionPlans ( mockSessionMetadata ) ) . toEqual ( [
108
+ { name : 'No HA' , price : 0 } ,
109
+ { name : 'No HA 30MB price:0' , price : 0 } ,
110
+ { name : 'no ha 30MB' , price : 0 } ,
111
+ { name : 'no ha' , price : 0 } ,
112
+ { name : 'Cache' , price : 0 } ,
113
+ { name : 'Cache 30MB' , price : 0 } ,
114
+ { name : 'cache' , price : 0 } ,
115
+ { name : 'cache 30MB' , price : 0 } ,
116
+ ] ) ;
117
+ } ) ;
118
+ } ) ;
64
119
} ) ;
65
120
66
121
describe ( 'getCloudRegions' , ( ) => {
0 commit comments