From 48b1f4edbf72067e5a5cc0a9203abc1210ee14dc Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 7 Dec 2016 22:54:51 +1300 Subject: [PATCH] remove VCA from list of those you can upload too --- lib/components/UserDropdown.js | 2 +- lib/redux/reducers/users.js | 12 ++++---- test/browser/redux/reducers/users.test.js | 36 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/lib/components/UserDropdown.js b/lib/components/UserDropdown.js index ba535cf888..5e820e07b0 100644 --- a/lib/components/UserDropdown.js +++ b/lib/components/UserDropdown.js @@ -45,7 +45,7 @@ var UserDropdown = React.createClass({ var selectorOpts = _.map(sorted, function(targetId) { return { - value: targetId, + value: targetId, label: personUtils.patientFullName(allUsers[targetId]) }; }); diff --git a/lib/redux/reducers/users.js b/lib/redux/reducers/users.js index 931aecef59..a2c5679aa3 100644 --- a/lib/redux/reducers/users.js +++ b/lib/redux/reducers/users.js @@ -123,6 +123,10 @@ function isPwd(membership) { return !_.isEmpty(_.get(membership, ['profile', 'patient'], {})); } +function isVCA(membership) { + return personUtils.userHasRole(membership, 'clinic'); +} + export function targetDevices(state = {}, action) { switch (action.type) { case actionTypes.ADD_TARGET_DEVICE: { @@ -257,11 +261,10 @@ export function targetUsersForUpload(state = [], action) { let newState = []; _.each(memberships, (membership) => { if (membership.userid === user.userid) { - if (!_.isEmpty(profile.patient)) { + if (!isVCA(user) && !_.isEmpty(profile.patient)){ newState.push(membership.userid); } - } - else { + } else { newState.push(membership.userid); } }); @@ -281,14 +284,13 @@ export function uploadTargetUser(state = null, action) { case actionTypes.LOGIN_SUCCESS: case actionTypes.SET_USER_INFO_FROM_TOKEN: const { user, profile, memberships } = action.payload; - const isClinicAccount = personUtils.userHasRole(user, 'clinic'); const uploadMemberships = _.filter(memberships, (mship) => { return !_.isEmpty(_.get(mship, ['profile', 'patient'])); }); if (!_.isEmpty(profile.patient)) { return user.userid; } - else if (uploadMemberships.length === 1 && !isClinicAccount) { + else if (uploadMemberships.length === 1 && !isVCA(user)) { return uploadMemberships[0].userid; } else { diff --git a/test/browser/redux/reducers/users.test.js b/test/browser/redux/reducers/users.test.js index 39e3c1b08b..c265dec1b1 100644 --- a/test/browser/redux/reducers/users.test.js +++ b/test/browser/redux/reducers/users.test.js @@ -562,6 +562,42 @@ describe('users', () => { })).to.deep.equal(['d4e5f6']); }); + describe('SET_ALL_USERS', () => { + it('should handle when logged in is VCA', () => { + const profile = {patient: {b: 2}}; + const user = {userid: 'x1y2z3', profile: {fullName: 'VCA Foo'}, roles: ['clinic']}; + const memberships = [ + {userid: 'a1b2c3', profile: {fullName: 'Annie Foo'}}, + {userid: 'd4e5f6', profile: {patient: {b: 2}}}, + user + ]; + expect(users.targetUsersForUpload(undefined, { + type: actionTypes.SET_ALL_USERS, + payload: { user, profile, memberships } + })).to.deep.equal(['a1b2c3','d4e5f6']); + }); + it('should handle non VCA roles', () => { + const profile = {patient: {b: 2}}; + const user = {userid: '888', profile: { patient: {c: 1}}, roles: ['other']}; + const memberships = [ + {userid: 'd4e5f6', profile: {patient: {b: 2}}}, + {userid: 'x1y2z3', profile: {patient: {a: 1}}}, + user + ]; + expect(users.targetUsersForUpload(undefined, { + type: actionTypes.SET_ALL_USERS, + payload: { user, profile, memberships } + })).to.deep.equal(['d4e5f6', 'x1y2z3', '888']); + }); + it('should handle normal accounts', () => { + const profile = {a: 1}; + expect(users.targetUsersForUpload(undefined, { + type: actionTypes.SET_ALL_USERS, + payload: { user, profile, memberships } + })).to.deep.equal(['d4e5f6']); + }); + }); + it('should handle CREATE_CUSTODIAL_ACCOUNT_SUCCESS', () => { const action = { type: actionTypes.CREATE_CUSTODIAL_ACCOUNT_SUCCESS,