1
+ component extends = " tests.resources.ModuleIntegrationSpec" {
2
+
3
+ property name = " cache" inject = " cachebox:default" ;
4
+
5
+ function beforeAll () {
6
+ super .beforeAll ();
7
+ }
8
+
9
+ function run () {
10
+ describe ( " Constraints" , function () {
11
+ it ( " can skip strategies based on constraints" , function () {
12
+ var unleash = prepareMock ( getInstance ( " UnleashSDK@unleashsdk" ) );
13
+ unleash .$( " getContext" , {
14
+ " appName" : " unleashsdk-tests" ,
15
+ " environment" : " testing" ,
16
+ " userId" : " 1" ,
17
+ " sessionId" : " 1" ,
18
+ " remoteAddress" : CGI .REMOTE_ADDR
19
+ } );
20
+ unleash .$( " getFeature" , {
21
+ " stale" : false ,
22
+ " variants" : " " ,
23
+ " enabled" : true ,
24
+ " type" : " release" ,
25
+ " name" : " feature-1" ,
26
+ " strategies" : [
27
+ {
28
+ " name" : " default" ,
29
+ " parameters" : {},
30
+ " constraints" : [
31
+ {
32
+ " contextName" : " environment" ,
33
+ " operator" : " IN" ,
34
+ " values" : [ " dev" , " testing" ]
35
+ },
36
+ {
37
+ " contextName" : " appName" ,
38
+ " operator" : " NOT_IN" ,
39
+ " values" : [ " unleashsdk-tests" ]
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ " name" : " userWithId" ,
45
+ " parameters" : {
46
+ " userIds" : " 2,3,4"
47
+ }
48
+ }
49
+ ]
50
+ } );
51
+ expect ( unleash .isEnabled ( " feature-1" ) ).toBeFalse ();
52
+ // unleash.$( "getContext", {
53
+ // "appName": "unleashsdk-not-tests",
54
+ // "environment": "testing",
55
+ // "userId": "1",
56
+ // "sessionId": "1",
57
+ // "remoteAddress": CGI.REMOTE_ADDR
58
+ // } );
59
+ // expect( unleash.isEnabled( "feature-1" ) ).toBeTrue();
60
+ } );
61
+
62
+ it ( " all strategies that pass constraints must be enabled for the feature to be enabled" , function () {
63
+ var unleash = prepareMock ( getInstance ( " UnleashSDK@unleashsdk" ) );
64
+ unleash .$( " getContext" , {
65
+ " appName" : " unleashsdk-not-tests" ,
66
+ " environment" : " testing" ,
67
+ " userId" : " 1" ,
68
+ " sessionId" : " 1" ,
69
+ " remoteAddress" : CGI .REMOTE_ADDR
70
+ } );
71
+ unleash .$( " getFeature" , {
72
+ " stale" : false ,
73
+ " variants" : " " ,
74
+ " enabled" : true ,
75
+ " type" : " release" ,
76
+ " name" : " feature-1" ,
77
+ " strategies" : [
78
+ {
79
+ " name" : " default" ,
80
+ " parameters" : {},
81
+ " constraints" : [
82
+ {
83
+ " contextName" : " environment" ,
84
+ " operator" : " IN" ,
85
+ " values" : [ " dev" , " testing" ]
86
+ },
87
+ {
88
+ " contextName" : " appName" ,
89
+ " operator" : " NOT_IN" ,
90
+ " values" : [ " unleashsdk-tests" ]
91
+ }
92
+ ]
93
+ },
94
+ {
95
+ " name" : " userWithId" ,
96
+ " parameters" : {
97
+ " userIds" : " 1,2,3,4"
98
+ }
99
+ }
100
+ ]
101
+ } );
102
+ expect ( unleash .isEnabled ( " feature-1" ) ).toBeTrue ();
103
+ } );
104
+ } );
105
+ }
106
+
107
+ }
0 commit comments