Skip to content

Commit

Permalink
remove VCA from list of those you can upload too
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-bate committed Dec 7, 2016
1 parent 3d81114 commit 48b1f4e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/components/UserDropdown.js
Expand Up @@ -45,7 +45,7 @@ var UserDropdown = React.createClass({

var selectorOpts = _.map(sorted, function(targetId) {
return {
value: targetId,
value: targetId,
label: personUtils.patientFullName(allUsers[targetId])
};
});
Expand Down
12 changes: 7 additions & 5 deletions lib/redux/reducers/users.js
Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
}
});
Expand All @@ -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 {
Expand Down
36 changes: 36 additions & 0 deletions test/browser/redux/reducers/users.test.js
Expand Up @@ -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,
Expand Down

0 comments on commit 48b1f4e

Please sign in to comment.