diff --git a/src/actions/organization/members/list.js b/src/actions/organization/members/list.js index 4be067e22..654cd22c0 100644 --- a/src/actions/organization/members/list.js +++ b/src/actions/organization/members/list.js @@ -35,7 +35,7 @@ async function organizationMembersList({ params }) { id: organizationId, type: 'organizationMembers', attributes: members.map(member => ({ - id: member.username, + id: member.id, type: 'organizationMember', attributes: member, })), diff --git a/src/actions/organization/members/remove.js b/src/actions/organization/members/remove.js index 8f35b4d32..57b9a409f 100644 --- a/src/actions/organization/members/remove.js +++ b/src/actions/organization/members/remove.js @@ -26,8 +26,9 @@ async function removeMember({ params }) { const { audience } = config.organizations; const userId = await getUserId.call(this, username); - const memberKey = redisKey(userId, USERS_METADATA, audience); - const userInOrganization = await redis.hget(memberKey, organizationId); + const memberKey = redisKey(organizationId, ORGANIZATIONS_MEMBERS, userId); + const memberMetadataKey = redisKey(userId, USERS_METADATA, audience); + const userInOrganization = await redis.hget(memberMetadataKey, organizationId); if (!userInOrganization) { throw ErrorUserNotMember; } @@ -35,7 +36,7 @@ async function removeMember({ params }) { const pipeline = redis.pipeline(); pipeline.del(memberKey); pipeline.zrem(redisKey(organizationId, ORGANIZATIONS_MEMBERS), memberKey); - pipeline.hdel(memberKey, organizationId); + pipeline.hdel(memberMetadataKey, organizationId); return pipeline.exec().then(handlePipeline); } diff --git a/test/suites/organization/members/remove.js b/test/suites/organization/members/remove.js index dadd30d75..5e9bfeb2b 100644 --- a/test/suites/organization/members/remove.js +++ b/test/suites/organization/members/remove.js @@ -28,9 +28,16 @@ describe('#remove member from organization', function registerSuite() { username: this.userNames[0].email, }; - return this.dispatch('users.organization.members.remove', opts) + await this.dispatch('users.organization.members.remove', opts) .reflect() .then(inspectPromise(true)); + + return this.dispatch('users.organization.members.list', { organizationId: this.organization.id }) + .reflect() + .then(inspectPromise(true)) + .then((response) => { + assert.strictEqual(response.data.attributes.find(({ attributes }) => attributes.username === this.userNames[0].email), undefined); + }); }); it('must return organization not found error', async function test() {