Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Modify the user invite process to avoid using fetchUser #1127

Merged
merged 5 commits into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions static_src/actions/user_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ const userActions = {

receivedInviteStatus(invite, email) {
const verified = invite.verified;
const userGuid = invite.userGuid;

AppDispatcher.handleViewAction({
type: userActionTypes.USER_INVITE_STATUS_UPDATED,
email,
verified
});

return cfApi.fetchUser(invite.userGuid)
.then(user => userActions.createUserAndAssociate(user))
return userActions.createUserAndAssociate(userGuid)
.then(() => userActions.createInviteNotification(verified, email))
.catch(err => userActions.userInviteCreateError(err, `There was a problem
inviting ${email}`));
Expand Down Expand Up @@ -231,19 +232,27 @@ const userActions = {
return Promise.resolve(err);
},

createUserAndAssociate(user) {
createUserAndAssociate(userGuid) {
const orgGuid = OrgStore.currentOrgGuid;
const userGuid = user.guid;
AppDispatcher.handleViewAction({
type: userActionTypes.USER_ORG_ASSOCIATE,
userGuid,
orgGuid
});
return cfApi.putAssociateUserToOrganization(userGuid, orgGuid)
.then(userActions.createdUserAndAssociated(userGuid, orgGuid, user));
.then(() => cfApi.fetchOrgUsers(orgGuid))
.then(orgUsers => userActions.createdUserAndAssociated(userGuid, orgGuid, orgUsers));
},

createdUserAndAssociated(userGuid, orgGuid, user) {
createdUserAndAssociated(userGuid, orgGuid, orgUsers) {
const user = orgUsers.filter((orgUser) => orgUser.guid === userGuid);

if (!user[0]) {
const err = new Error('user was not associated to org');
const message = `The user ${userGuid} was not associated in the org ${orgGuid}.`;
return Promise.resolve(userActions.userInviteCreateError(err, message));
}

AppDispatcher.handleViewAction({
type: userActionTypes.USER_ORG_ASSOCIATED,
userGuid,
Expand Down
18 changes: 11 additions & 7 deletions static_src/test/unit/actions/user_actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ describe('userActions', function() {

describe('receivedInviteStatus()', function() {
it('should', function() {
var invite = { userGuid: "user-guid" };
var user = { userGuid: "user-guid" };
var userGuid = "user-guid";
var invite = { userGuid };
var email = 'this@there.com';
var verified = true;
var expected = { email, verified };

sandbox.spy(userActions, 'receivedInviteStatus');
sandbox.stub(userActions, 'createUserAndAssociate').returns(Promise.resolve(invite));
sandbox.stub(userActions, 'createInviteNotification');
sandbox.stub(uaaApi, 'inviteUaaUser').returns(Promise.resolve(invite));
let spy = setupViewSpy(sandbox)

Expand Down Expand Up @@ -285,26 +287,28 @@ describe('userActions', function() {
let orgGuid;
let expectedParams;
let spy;
let user;

beforeEach(function (done) {
userGuid = "fake-udid";
orgGuid = "fake-org-udid";
const user = {
user = {
guid: userGuid,
username: 'asdf'
};
orgUsers = [user, {userGuid: 'wrong-udid'}, {userGuid: 'wrong-udid-2'}];
expectedParams = {
userGuid,
orgGuid,
user
user: orgUsers[0]
};
spy = setupViewSpy(sandbox)
userActions.createdUserAndAssociated(userGuid, orgGuid, user)
spy = setupViewSpy(sandbox);
userActions.createdUserAndAssociated(userGuid, orgGuid, orgUsers)
.then(done, done.fail);
});

it('should dispatch USER_ORG_ASSOCIATED notice with user and org', function() {
assertAction(spy, userActionTypes.USER_ORG_ASSOCIATED, expectedParams);
assertAction(spy, userActionTypes.USER_ORG_ASSOCIATED);
});
});

Expand Down
9 changes: 5 additions & 4 deletions static_src/test/unit/stores/user_store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,16 @@ describe('UserStore', function () {
describe('on org user associated', function() {
const userGuid = 'user-543';
const orgGuid = 'org-abc';

let orgUsers
beforeEach(function() {
UserStore._data = Immutable.List();
sandbox.spy(UserStore, 'emitChange');
const user = {
guid: userGuid,
username: 'person@person.com'
};
userActions.createdUserAndAssociated(userGuid, orgGuid, user);
orgUsers = [user, {userGuid: 'wrong-udid'}, {userGuid: 'wrong-udid-2'}];
userActions.createdUserAndAssociated(userGuid, orgGuid, orgUsers);
});

it('should emit a change', function() {
Expand All @@ -256,14 +257,14 @@ describe('UserStore', function () {
const userGuid = "fake-user-guid";
const orgGuid = "fake-org-guid";
const orgUsers = [
{userGuid: "fake-user-guid-1"},
{userGuid: userGuid},
{userGuid: "fake-user-guid-2"},
{userGuid: "fake-user-guid-3"}
];

userActions.createdUserAndAssociated(userGuid, orgGuid, orgUsers);

expect(spy).toHaveBeenCalledTwice();
expect(spy).toHaveBeenCalledOnce();
});

it('should merge and update org with new users', function() {
Expand Down