Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmithun4 committed Jun 14, 2022
1 parent 421298f commit b9fa229
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions server/src/services/users.service.ts
Expand Up @@ -155,10 +155,11 @@ export class UsersService {
// removing keys with undefined values
cleanObject(updatableParams);

await this.updateUser(userId, updatableParams);
const user = await this.findOne(userId);
let user: User;

const performUpdateInTransaction = async (manager) => {
await manager.update(User, userId, updatableParams);
user = await manager.findOne(User, { where: { id: userId } });
await this.removeUserGroupPermissionsIfExists(manager, user, removeGroups, organizationId);
await this.addUserGroupPermissions(manager, user, addGroups, organizationId);
};
Expand Down
27 changes: 25 additions & 2 deletions server/test/controllers/organization_users.e2e-spec.ts
Expand Up @@ -188,7 +188,7 @@ describe('organization users controller', () => {
expect(viewerUserData.user.password).not.toBe('old-password');
});

it('should allow unarchive if user is already archived', async () => {
it('should not allow unarchive if user status is not archived', async () => {
const adminUserData = await createUser(app, {
email: 'admin@tooljet.io',
status: 'active',
Expand All @@ -205,11 +205,34 @@ describe('organization users controller', () => {
await request(app.getHttpServer())
.post(`/api/organization_users/${developerUserData.orgUser.id}/unarchive/`)
.set('Authorization', authHeaderForUser(adminUserData.user))
.expect(201);
.expect(400);

await developerUserData.orgUser.reload();
expect(developerUserData.orgUser.status).toBe('active');
});

it('should not allow unarchive if user status is not archived', async () => {
const adminUserData = await createUser(app, {
email: 'admin@tooljet.io',
status: 'active',
groups: ['admin', 'all_users'],
});
const organization = adminUserData.organization;
const developerUserData = await createUser(app, {
email: 'developer@tooljet.io',
status: 'invited',
groups: ['developer', 'all_users'],
organization,
});

await request(app.getHttpServer())
.post(`/api/organization_users/${developerUserData.orgUser.id}/unarchive/`)
.set('Authorization', authHeaderForUser(adminUserData.user))
.expect(400);

await developerUserData.orgUser.reload();
expect(developerUserData.orgUser.status).toBe('invited');
});
});

afterAll(async () => {
Expand Down

0 comments on commit b9fa229

Please sign in to comment.