Răsfoiți Sursa

add forceUpdateParents test for 3 groups

kaori 3 ani în urmă
părinte
comite
8b84b2f7ce
1 a modificat fișierele cu 49 adăugiri și 9 ștergeri
  1. 49 9
      packages/app/test/integration/service/user-groups.test.ts

+ 49 - 9
packages/app/test/integration/service/user-groups.test.ts

@@ -5,7 +5,6 @@ import { getInstance } from '../setup-crowi';
 
 describe('UserGroupService', () => {
   let crowi;
-  let User;
   let UserGroup;
   let UserGroupRelation;
 
@@ -14,20 +13,17 @@ describe('UserGroupService', () => {
   const groupId3 = new mongoose.Types.ObjectId();
   const groupId4 = new mongoose.Types.ObjectId();
   const groupId5 = new mongoose.Types.ObjectId();
+  const groupId6 = new mongoose.Types.ObjectId();
+  const groupId7 = new mongoose.Types.ObjectId();
+  const groupId8 = new mongoose.Types.ObjectId();
 
   const userId1 = new mongoose.Types.ObjectId();
 
   beforeAll(async() => {
     crowi = await getInstance();
-    User = mongoose.model('User');
     UserGroup = mongoose.model('UserGroup');
     UserGroupRelation = mongoose.model('UserGroupRelation');
 
-    // Create Users
-    await User.insertMany([
-      { name: 'user1', username: 'user1', email: 'user-group-test1@example.com' },
-    ]);
-
 
     // Create Groups
     await UserGroup.insertMany([
@@ -61,6 +57,24 @@ describe('UserGroupService', () => {
         name: 'v5_group5',
         description: 'description5',
       },
+      // No parent
+      {
+        _id: groupId6,
+        name: 'v5_group6',
+        description: 'description5',
+      },
+      // No parent
+      {
+        _id: groupId7,
+        name: 'v5_group7',
+        description: 'description5',
+      },
+      // No parent
+      {
+        _id: groupId8,
+        name: 'v5_group8',
+        description: 'description5',
+      },
     ]);
 
     // Create UserGroupRelations
@@ -69,6 +83,14 @@ describe('UserGroupService', () => {
         relatedGroup: groupId4,
         relatedUser: userId1,
       },
+      {
+        relatedGroup: groupId6,
+        relatedUser: userId1,
+      },
+      {
+        relatedGroup: groupId8,
+        relatedUser: userId1,
+      },
     ]);
 
   });
@@ -117,8 +139,10 @@ describe('UserGroupService', () => {
     await expect(result).rejects.toThrow('The parent group does not contain the users in this group.');
   });
 
-  // In case that forceUpdateParents is true
-  test('User should be included to parent group in case that force update is true', async() => {
+  /*
+  * forceUpdateParents true
+  */
+  test('User should be included to parent group (2 groups ver)', async() => {
     const userGroup4 = await UserGroup.findOne({ _id: groupId4 });
     const userGroup4Relation = await UserGroupRelation.findOne({ relatedGroup:  userGroup4, relatedUser: userId1 });
     const userGroup5 = await UserGroup.findOne({ _id: groupId5 });
@@ -134,4 +158,20 @@ describe('UserGroupService', () => {
     expect(relatedGroup).toBeTruthy();
   });
 
+  test('User should be included to parent group (3 groups ver)', async() => {
+    const userGroup8 = await UserGroup.findOne({ _id: groupId8 });
+    const forceUpdateParents = true;
+
+    await crowi.userGroupService.updateGroup(
+      userGroup8._id, userGroup8.name, userGroup8.description, groupId7, forceUpdateParents,
+    );
+    const relatedGroup6 = await UserGroupRelation.findOne({ relatedGroup: groupId6, relatedUser: userId1 });
+    const relatedGroup7 = await UserGroupRelation.findOne({ relatedGroup: groupId7, relatedUser: userId1 });
+    const relatedGroup8 = await UserGroupRelation.findOne({ relatedGroup: groupId8, relatedUser: userId1 });
+
+    expect(relatedGroup6).toBeTruthy();
+    expect(relatedGroup7).toBeTruthy();
+    expect(relatedGroup8).toBeTruthy();
+  });
+
 });