Skip to content

Commit 4f13cad

Browse files
committed
test fix
1 parent cdc110c commit 4f13cad

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

services/dataAccessLayer.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ const removeSensitiveInfo = function (obj) {
9292
};
9393

9494
const privilegedAccess = (user, data, level) => {
95-
user.email = data.email;
95+
if ("email" in data) {
96+
user.email = data.email;
97+
}
9698
if (level === ACCESS_LEVEL.PRIVATE || level === ACCESS_LEVEL.CONFIDENTIAL) {
97-
user.phone = data.phone;
99+
if ("phone" in data) {
100+
user.phone = data.phone;
101+
}
98102
}
99103
if (level === ACCESS_LEVEL.CONFIDENTIAL) {
100-
user.chaincode = data.chaincode;
104+
if ("chaincode" in data) {
105+
user.chaincode = data.chaincode;
106+
}
101107
}
102108
return user;
103109
};
@@ -111,6 +117,7 @@ const levelSpecificAccess = (user, level = ACCESS_LEVEL.PUBLIC, role = null) =>
111117
if (role === null || !role.super_user) {
112118
return "unauthorized";
113119
}
120+
114121
return privilegedAccess(user, unFilteredData, level);
115122
};
116123

test/unit/services/dataAccessLayer.test.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,36 @@ describe("Data Access Layer", function () {
151151
});
152152

153153
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+
};
160164
const result = privilegedAccess(userData[11], data, ACCESS_LEVEL.INTERNAL);
161165
expect(result).to.have.property("email");
162166
});
163167

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+
};
165173
const result = privilegedAccess(userData[11], data, ACCESS_LEVEL.PRIVATE);
166174
expect(result).to.have.property("email");
167175
expect(result).to.have.property("phone");
168176
});
169177

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+
};
171184
const result = privilegedAccess(userData[11], data, ACCESS_LEVEL.CONFIDENTIAL);
172185
expect(result).to.have.property("email");
173186
expect(result).to.have.property("phone");
@@ -189,13 +202,31 @@ describe("Data Access Layer", function () {
189202
expect(result).to.equal("unauthorized");
190203
});
191204

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+
192212
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";
195215
const role = { super_user: true };
196216
const user = levelSpecificAccess(userData[11], ACCESS_LEVEL.PRIVATE, role);
197217
expect(user).to.have.property("email");
198218
expect(user).to.have.property("phone");
199219
});
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+
});
200231
});
201232
});

0 commit comments

Comments
 (0)