|
@@ -4,13 +4,9 @@ import mongoose from 'mongoose';
|
|
|
import { getInstance } from '../setup-crowi';
|
|
import { getInstance } from '../setup-crowi';
|
|
|
|
|
|
|
|
describe('UserGroupService', () => {
|
|
describe('UserGroupService', () => {
|
|
|
- // let dummyUser1;
|
|
|
|
|
- // let dummyUser2;
|
|
|
|
|
-
|
|
|
|
|
let crowi;
|
|
let crowi;
|
|
|
let UserGroup;
|
|
let UserGroup;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
const groupId1 = new mongoose.Types.ObjectId();
|
|
const groupId1 = new mongoose.Types.ObjectId();
|
|
|
const groupId2 = new mongoose.Types.ObjectId();
|
|
const groupId2 = new mongoose.Types.ObjectId();
|
|
|
const groupId3 = new mongoose.Types.ObjectId();
|
|
const groupId3 = new mongoose.Types.ObjectId();
|
|
@@ -22,25 +18,16 @@ describe('UserGroupService', () => {
|
|
|
|
|
|
|
|
UserGroup = mongoose.model('UserGroup');
|
|
UserGroup = mongoose.model('UserGroup');
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- * Common
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
- // dummyUser1 = await UserGroup.findOne({ username: 'v5DummyUser1' });
|
|
|
|
|
- // dummyUser2 = await UserGroup.findOne({ username: 'v5DummyUser2' });
|
|
|
|
|
-
|
|
|
|
|
- // xssSpy = jest.spyOn(crowi.xss, 'process').mockImplementation(path => path);
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
// Create Groups
|
|
// Create Groups
|
|
|
await UserGroup.insertMany([
|
|
await UserGroup.insertMany([
|
|
|
- // no parent
|
|
|
|
|
|
|
+ // No parent
|
|
|
{
|
|
{
|
|
|
_id: groupId1,
|
|
_id: groupId1,
|
|
|
name: 'v5_group1',
|
|
name: 'v5_group1',
|
|
|
description: 'description1',
|
|
description: 'description1',
|
|
|
},
|
|
},
|
|
|
- // no parent
|
|
|
|
|
|
|
+ // No parent
|
|
|
{
|
|
{
|
|
|
_id: groupId2,
|
|
_id: groupId2,
|
|
|
name: 'v5_group2',
|
|
name: 'v5_group2',
|
|
@@ -72,7 +59,7 @@ describe('UserGroupService', () => {
|
|
|
expect(updatedUserGroup.parent).toStrictEqual(newParentId);
|
|
expect(updatedUserGroup.parent).toStrictEqual(newParentId);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- test('Cannot update to existing group name', async() => {
|
|
|
|
|
|
|
+ test('Should throw an error when trying to set existing group name', async() => {
|
|
|
const userGroup = await UserGroup.findOne({ _id: groupId1 });
|
|
const userGroup = await UserGroup.findOne({ _id: groupId1 });
|
|
|
await expect(crowi.userGroupService.updateGroup(userGroup._id, 'v5_group2')).rejects.toThrow('The group name is already taken');
|
|
await expect(crowi.userGroupService.updateGroup(userGroup._id, 'v5_group2')).rejects.toThrow('The group name is already taken');
|
|
|
});
|
|
});
|