Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap committed Jan 31, 2025
1 parent 89ebfe1 commit 3b399d2
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions apps/server/src/modules/group/domain/group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ describe(Group.name, () => {
describe('removeUser', () => {
describe('when the user is in the group', () => {
const setup = () => {
const user: UserDO = userDoFactory.buildWithId();
const userId = new ObjectId().toHexString();
const user: UserDO = userDoFactory.buildWithId(undefined, userId);
const groupUser1 = new GroupUser({
userId: user.id as string,
roleId: new ObjectId().toHexString(),
Expand All @@ -24,6 +25,7 @@ describe(Group.name, () => {
});

return {
userId,
user,
groupUser1,
groupUser2,
Expand All @@ -32,25 +34,26 @@ describe(Group.name, () => {
};

it('should remove the user', () => {
const { user, group, groupUser1 } = setup();
const { group, groupUser1, userId } = setup();

group.removeUser(user);
group.removeUser(userId);

expect(group.users).not.toContain(groupUser1);
});

it('should keep all other users', () => {
const { user, group, groupUser2 } = setup();
const { group, groupUser2, userId } = setup();

group.removeUser(user);
group.removeUser(userId);

expect(group.users).toContain(groupUser2);
});
});

describe('when the user is not in the group', () => {
const setup = () => {
const user: UserDO = userDoFactory.buildWithId();
const userId = new ObjectId().toHexString();
const user: UserDO = userDoFactory.buildWithId(undefined, userId);
const groupUser2 = new GroupUser({
userId: new ObjectId().toHexString(),
roleId: new ObjectId().toHexString(),
Expand All @@ -60,36 +63,39 @@ describe(Group.name, () => {
});

return {
userId,
user,
groupUser2,
group,
};
};

it('should do nothing', () => {
const { user, group, groupUser2 } = setup();
const { group, groupUser2, userId } = setup();

group.removeUser(user);
group.removeUser(userId);

expect(group.users).toEqual([groupUser2]);
});
});

describe('when the group is empty', () => {
const setup = () => {
const user: UserDO = userDoFactory.buildWithId();
const userId = new ObjectId().toHexString();
const user: UserDO = userDoFactory.buildWithId(undefined, userId);
const group: Group = groupFactory.build({ users: [] });

return {
userId,
user,
group,
};
};

it('should stay empty', () => {
const { user, group } = setup();
const { userId, group } = setup();

group.removeUser(user);
group.removeUser(userId);

expect(group.users).toEqual([]);
});
Expand Down

0 comments on commit 3b399d2

Please sign in to comment.