Skip to content

Commit 3e69291

Browse files
authored
Merge pull request #2632 from RedisInsight/be/feature/RI-4988-filter-cloud-plans
#RI-4988 add feature config for plan filters
2 parents 1b399c5 + 6fe519c commit 3e69291

File tree

3 files changed

+82
-6
lines changed

3 files changed

+82
-6
lines changed

redisinsight/api/config/features-config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 2.34,
2+
"version": 2.3401,
33
"features": {
44
"insightsRecommendations": {
55
"flag": true,
@@ -28,6 +28,11 @@
2828
}
2929
],
3030
"data": {
31+
"filterFreePlan": [{
32+
"field": "name",
33+
"expression": "^(No HA?.)|(Cache?.)",
34+
"options": "i"
35+
}],
3136
"selectPlan": {
3237
"components": {
3338
"triggersAndFunctions": [

redisinsight/api/src/modules/cloud/subscription/cloud-subscription.api.service.spec.ts

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import {
55
mockCloudSubscriptionApiProvider,
66
mockCloudSubscriptionCapiService,
77
mockCloudSubscriptionRegions,
8+
mockFeatureService,
89
mockSessionMetadata,
910
mockSubscriptionPlanResponse,
1011
MockType,
1112
} from 'src/__mocks__';
1213
import { CloudApiUnauthorizedException } from 'src/modules/cloud/common/exceptions';
1314
import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.service';
15+
import { FeatureService } from 'src/modules/feature/feature.service';
1416
import { CloudSubscriptionApiService } from './cloud-subscription.api.service';
15-
import { CloudUserApiService } from '../user/cloud-user.api.service';
1617
import { CloudSessionService } from '../session/cloud-session.service';
1718
import { CloudSubscriptionCapiService } from './cloud-subscription.capi.service';
1819
import { CloudSubscriptionApiProvider } from './providers/cloud-subscription.api.provider';
1920

2021
describe('CloudSubscriptionApiService', () => {
2122
let service: CloudSubscriptionApiService;
2223
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>;
2626

2727
beforeEach(async () => {
2828
const module: TestingModule = await Test.createTestingModule({
@@ -44,11 +44,17 @@ describe('CloudSubscriptionApiService', () => {
4444
provide: CloudCapiKeyService,
4545
useFactory: mockCloudCapiKeyService,
4646
},
47+
{
48+
provide: FeatureService,
49+
useFactory: mockFeatureService,
50+
},
4751
],
4852
}).compile();
4953

5054
service = module.get(CloudSubscriptionApiService);
5155
api = module.get(CloudSubscriptionApiProvider);
56+
capi = module.get(CloudSubscriptionCapiService);
57+
featureService = module.get(FeatureService);
5258
});
5359

5460
describe('getSubscriptionPlans', () => {
@@ -61,6 +67,55 @@ describe('CloudSubscriptionApiService', () => {
6167
CloudApiUnauthorizedException,
6268
);
6369
});
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+
});
64119
});
65120

66121
describe('getCloudRegions', () => {

redisinsight/api/src/modules/cloud/subscription/cloud-subscription.api.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { SessionMetadata } from 'src/common/models';
44
import { wrapHttpError } from 'src/common/utils';
55
import { CloudRequestUtm, ICloudApiCredentials } from 'src/modules/cloud/common/models';
66
import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.service';
7+
import { FeatureService } from 'src/modules/feature/feature.service';
8+
import { KnownFeatures } from 'src/modules/feature/constants';
79
import { CloudSubscriptionCapiService } from './cloud-subscription.capi.service';
810
import { CloudSubscriptionRegion, CloudSubscriptionType } from './models';
911
import { CloudSessionService } from '../session/cloud-session.service';
@@ -20,6 +22,7 @@ export class CloudSubscriptionApiService {
2022
private readonly sessionService: CloudSessionService,
2123
private readonly cloudCapiKeyService: CloudCapiKeyService,
2224
private readonly cloudSubscriptionCapiService: CloudSubscriptionCapiService,
25+
private readonly featureService: FeatureService,
2326
) {}
2427

2528
/**
@@ -42,9 +45,22 @@ export class CloudSubscriptionApiService {
4245
),
4346
]);
4447

48+
const cloudSsoFeature = await this.featureService.getByName(KnownFeatures.CloudSso);
49+
4550
const freePlans = filter(
4651
fixedPlans,
47-
({ price, name }) => price === 0 && name.startsWith('Cache'),
52+
(plan) => {
53+
if (plan.price !== 0) {
54+
return false;
55+
}
56+
57+
if (!cloudSsoFeature?.data?.filterFreePlan?.length) {
58+
return true;
59+
}
60+
61+
return !!((cloudSsoFeature?.data?.filterFreePlan).find((f) => f.expression
62+
&& (new RegExp(f.expression, f.options)).test(plan[f?.field])));
63+
},
4864
);
4965

5066
return freePlans.map((plan) => ({

0 commit comments

Comments
 (0)