Просмотр исходного кода

Test that suppression window is working

arvid-e 3 недель назад
Родитель
Сommit
d1d3dd443e
1 измененных файлов с 36 добавлено и 7 удалено
  1. 36 7
      apps/app/src/server/service/activity/update-activity.spec.ts

+ 36 - 7
apps/app/src/server/service/activity/update-activity.spec.ts

@@ -9,8 +9,10 @@ import { shouldGenerateUpdate } from './update-activity-logic';
 
 
 describe('shouldGenerateUpdate()', () => {
 describe('shouldGenerateUpdate()', () => {
   let mongoServer: MongoMemoryServer;
   let mongoServer: MongoMemoryServer;
-  const ONE_HOUR = 60 * 60 * 1000;
+
   const date = new Date();
   const date = new Date();
+  const ONE_HOUR = 60 * 60 * 1000;
+  const ONE_MINUTE = 1 * 60;
 
 
   const targetPageId = new mongoose.Types.ObjectId().toString();
   const targetPageId = new mongoose.Types.ObjectId().toString();
 
 
@@ -39,14 +41,14 @@ describe('shouldGenerateUpdate()', () => {
       {
       {
         user: currentUserId,
         user: currentUserId,
         action: SupportedAction.ACTION_PAGE_CREATE,
         action: SupportedAction.ACTION_PAGE_CREATE,
-        createdAt: new Date('2025-10-31T23:59:59Z'),
+        createdAt: new Date(),
         target: targetPageId,
         target: targetPageId,
         _id: currentActivityId,
         _id: currentActivityId,
       },
       },
       {
       {
         user: otherUserId,
         user: otherUserId,
-        action: SupportedAction.ACTION_PAGE_CREATE,
-        createdAt: new Date('2025-10-30T23:59:59Z'),
+        action: SupportedAction.ACTION_PAGE_UPDATE,
+        createdAt: new Date(date.getTime() - ONE_HOUR),
         target: targetPageId,
         target: targetPageId,
         _id: olderActivityId,
         _id: olderActivityId,
       },
       },
@@ -105,10 +107,10 @@ describe('shouldGenerateUpdate()', () => {
     expect(result).toBe(false);
     expect(result).toBe(false);
   });
   });
 
 
-  it('should generate update activity if it is the first update activity but user is not the creator', async () => {
+  it('should generate update activity if update is made by the same user and outside the suppression window', async () => {
     await Activity.insertMany([
     await Activity.insertMany([
       {
       {
-        user: otherUserId,
+        user: currentUserId,
         action: SupportedAction.ACTION_PAGE_CREATE,
         action: SupportedAction.ACTION_PAGE_CREATE,
         createdAt: new Date(date.getTime() - ONE_HOUR),
         createdAt: new Date(date.getTime() - ONE_HOUR),
         target: targetPageId,
         target: targetPageId,
@@ -129,7 +131,7 @@ describe('shouldGenerateUpdate()', () => {
         pageId: targetPageId,
         pageId: targetPageId,
         body: 'Old content',
         body: 'Old content',
         format: 'markdown',
         format: 'markdown',
-        author: otherUserId,
+        author: currentUserId,
       },
       },
       {
       {
         _id: new mongoose.Types.ObjectId(),
         _id: new mongoose.Types.ObjectId(),
@@ -148,4 +150,31 @@ describe('shouldGenerateUpdate()', () => {
 
 
     expect(result).toBe(true);
     expect(result).toBe(true);
   });
   });
+
+  it('should not generate update activity if update is made by the same user and within the suppression window', async () => {
+    await Activity.insertMany([
+      {
+        user: currentUserId,
+        action: SupportedAction.ACTION_PAGE_CREATE,
+        createdAt: new Date(date.getTime() - ONE_MINUTE),
+        target: targetPageId,
+        _id: olderActivityId,
+      },
+      {
+        user: currentUserId,
+        action: SupportedAction.ACTION_PAGE_UPDATE,
+        createdAt: new Date(),
+        target: targetPageId,
+        _id: currentActivityId,
+      },
+    ]);
+
+    const result = await shouldGenerateUpdate({
+      targetPageId,
+      currentUserId,
+      currentActivityId,
+    });
+
+    expect(result).toBe(false);
+  });
 });
 });