-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
N21 1212 remove user from group (#4454)
* remove user from group: * remove emptx groups
- Loading branch information
1 parent
6f7f09c
commit d3a0975
Showing
11 changed files
with
553 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { groupFactory, roleFactory, userDoFactory } from '@shared/testing'; | ||
|
||
import { ObjectId } from 'bson'; | ||
import { RoleReference, UserDO } from '@shared/domain'; | ||
import { Group } from './group'; | ||
import { GroupUser } from './group-user'; | ||
|
||
describe('Group (Domain Object)', () => { | ||
describe('removeUser', () => { | ||
describe('when the user is in the group', () => { | ||
const setup = () => { | ||
const user: UserDO = userDoFactory.buildWithId(); | ||
const groupUser1 = new GroupUser({ | ||
userId: user.id as string, | ||
roleId: new ObjectId().toHexString(), | ||
}); | ||
const groupUser2 = new GroupUser({ | ||
userId: new ObjectId().toHexString(), | ||
roleId: new ObjectId().toHexString(), | ||
}); | ||
const group: Group = groupFactory.build({ | ||
users: [groupUser1, groupUser2], | ||
}); | ||
|
||
return { | ||
user, | ||
groupUser1, | ||
groupUser2, | ||
group, | ||
}; | ||
}; | ||
|
||
it('should remove the user', () => { | ||
const { user, group, groupUser1 } = setup(); | ||
|
||
group.removeUser(user); | ||
|
||
expect(group.users).not.toContain(groupUser1); | ||
}); | ||
|
||
it('should keep all other users', () => { | ||
const { user, group, groupUser2 } = setup(); | ||
|
||
group.removeUser(user); | ||
|
||
expect(group.users).toContain(groupUser2); | ||
}); | ||
}); | ||
|
||
describe('when the user is not in the group', () => { | ||
const setup = () => { | ||
const user: UserDO = userDoFactory.buildWithId(); | ||
const groupUser2 = new GroupUser({ | ||
userId: new ObjectId().toHexString(), | ||
roleId: new ObjectId().toHexString(), | ||
}); | ||
const group: Group = groupFactory.build({ | ||
users: [groupUser2], | ||
}); | ||
|
||
return { | ||
user, | ||
groupUser2, | ||
group, | ||
}; | ||
}; | ||
|
||
it('should do nothing', () => { | ||
const { user, group, groupUser2 } = setup(); | ||
|
||
group.removeUser(user); | ||
|
||
expect(group.users).toEqual([groupUser2]); | ||
}); | ||
}); | ||
|
||
describe('when the group is empty', () => { | ||
const setup = () => { | ||
const user: UserDO = userDoFactory.buildWithId(); | ||
const group: Group = groupFactory.build({ users: [] }); | ||
|
||
return { | ||
user, | ||
group, | ||
}; | ||
}; | ||
|
||
it('should stay empty', () => { | ||
const { user, group } = setup(); | ||
|
||
group.removeUser(user); | ||
|
||
expect(group.users).toEqual([]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('isEmpty', () => { | ||
describe('when no users in group exist', () => { | ||
const setup = () => { | ||
const group: Group = groupFactory.build({ users: [] }); | ||
|
||
return { | ||
group, | ||
}; | ||
}; | ||
|
||
it('should return true', () => { | ||
const { group } = setup(); | ||
|
||
const isEmpty = group.isEmpty(); | ||
|
||
expect(isEmpty).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when users in group exist', () => { | ||
const setup = () => { | ||
const externalUserId = 'externalUserId'; | ||
const role: RoleReference = roleFactory.buildWithId(); | ||
const user: UserDO = userDoFactory.buildWithId({ roles: [role], externalId: externalUserId }); | ||
const group: Group = groupFactory.build({ users: [{ userId: user.id as string, roleId: role.id }] }); | ||
|
||
return { | ||
group, | ||
}; | ||
}; | ||
|
||
it('should return false', () => { | ||
const { group } = setup(); | ||
|
||
const isEmpty = group.isEmpty(); | ||
|
||
expect(isEmpty).toEqual(false); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.