@@ -151,23 +151,36 @@ describe("Data Access Layer", function () {
151
151
} ) ;
152
152
153
153
describe ( "privilegedAccess" , function ( ) {
154
- const data = {
155
-
156
- phone : "1234567890" ,
157
- chaincode : "abc7896" ,
158
- } ;
159
- it ( "should set only email for INTERNAL access" , function ( ) {
154
+ it ( "should return default user fields if email does not exist in userdata and INTERNAL access requested" , function ( ) {
155
+ const data = { } ;
156
+ const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . INTERNAL ) ;
157
+ expect ( result . email ) . to . equal ( undefined ) ;
158
+ } ) ;
159
+
160
+ it ( "should set only email for INTERNAL access if email exists" , function ( ) {
161
+ const data = {
162
+
163
+ } ;
160
164
const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . INTERNAL ) ;
161
165
expect ( result ) . to . have . property ( "email" ) ;
162
166
} ) ;
163
167
164
- it ( "should set email and phone for PRIVATE access" , function ( ) {
168
+ it ( "should set email and phone for PRIVATE access if email and phone exists" , function ( ) {
169
+ const data = {
170
+
171
+ phone : "1234567890" ,
172
+ } ;
165
173
const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . PRIVATE ) ;
166
174
expect ( result ) . to . have . property ( "email" ) ;
167
175
expect ( result ) . to . have . property ( "phone" ) ;
168
176
} ) ;
169
177
170
- it ( "should set email, phone, and chaincode for CONFIDENTIAL access" , function ( ) {
178
+ it ( "should set email, phone, and chaincode for CONFIDENTIAL access if email,phone and chaincode exists" , function ( ) {
179
+ const data = {
180
+
181
+ phone : "1234567890" ,
182
+ chaincode : "abc7896" ,
183
+ } ;
171
184
const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . CONFIDENTIAL ) ;
172
185
expect ( result ) . to . have . property ( "email" ) ;
173
186
expect ( result ) . to . have . property ( "phone" ) ;
@@ -189,13 +202,31 @@ describe("Data Access Layer", function () {
189
202
expect ( result ) . to . equal ( "unauthorized" ) ;
190
203
} ) ;
191
204
205
+ it ( "should call privilegedAccess for INTERNAL level and super_user role" , function ( ) {
206
+ userData [ 11 ] . email = "[email protected] " ;
207
+ const role = { super_user : true } ;
208
+ const result = levelSpecificAccess ( userData [ 11 ] , ACCESS_LEVEL . INTERNAL , role ) ;
209
+ expect ( result ) . to . have . property ( "email" ) ;
210
+ } ) ;
211
+
192
212
it ( "should call privilegedAccess for PRIVATE level and super_user role" , function ( ) {
193
- userData . email = "[email protected] " ;
194
- userData . phone = "8976509889" ;
213
+ userData [ 11 ] . email = "[email protected] " ;
214
+ userData [ 11 ] . phone = "8976509889" ;
195
215
const role = { super_user : true } ;
196
216
const user = levelSpecificAccess ( userData [ 11 ] , ACCESS_LEVEL . PRIVATE , role ) ;
197
217
expect ( user ) . to . have . property ( "email" ) ;
198
218
expect ( user ) . to . have . property ( "phone" ) ;
199
219
} ) ;
220
+
221
+ it ( "should call privilegedAccess for CONFIDENTIAL level and super_user role" , function ( ) {
222
+ userData [ 11 ] . email = "[email protected] " ;
223
+ userData [ 11 ] . phone = "8976509889" ;
224
+ userData [ 11 ] . chaincode = "1234567" ;
225
+ const role = { super_user : true } ;
226
+ const user = levelSpecificAccess ( userData [ 11 ] , ACCESS_LEVEL . CONFIDENTIAL , role ) ;
227
+ expect ( user ) . to . have . property ( "email" ) ;
228
+ expect ( user ) . to . have . property ( "phone" ) ;
229
+ expect ( user ) . to . have . property ( "chaincode" ) ;
230
+ } ) ;
200
231
} ) ;
201
232
} ) ;
0 commit comments