|
|
@@ -9,6 +9,8 @@ import { shouldGenerateUpdate } from './update-activity-logic';
|
|
|
|
|
|
describe('shouldGenerateUpdate()', () => {
|
|
|
let mongoServer: MongoMemoryServer;
|
|
|
+ const ONE_HOUR = 60 * 60 * 1000;
|
|
|
+ const date = new Date();
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
mongoServer = await MongoMemoryServer.create();
|
|
|
@@ -57,4 +59,53 @@ describe('shouldGenerateUpdate()', () => {
|
|
|
|
|
|
expect(result).toBe(true);
|
|
|
});
|
|
|
+
|
|
|
+ it('should not generate update activity if it is the first update activity by the creator', async () => {
|
|
|
+ const currentUserId = new mongoose.Types.ObjectId().toString();
|
|
|
+ const targetPageId = new mongoose.Types.ObjectId().toString();
|
|
|
+ const currentActivityId = new mongoose.Types.ObjectId().toString();
|
|
|
+ const olderActivityId = new mongoose.Types.ObjectId().toString();
|
|
|
+
|
|
|
+ await Activity.insertMany([
|
|
|
+ {
|
|
|
+ user: currentUserId,
|
|
|
+ action: SupportedAction.ACTION_PAGE_CREATE,
|
|
|
+ createdAt: new Date(date.getTime() - ONE_HOUR),
|
|
|
+ target: targetPageId,
|
|
|
+ _id: olderActivityId,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ user: currentUserId,
|
|
|
+ action: SupportedAction.ACTION_PAGE_UPDATE,
|
|
|
+ createdAt: new Date(),
|
|
|
+ target: targetPageId,
|
|
|
+ _id: currentActivityId,
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ await Revision.insertMany([
|
|
|
+ {
|
|
|
+ _id: new mongoose.Types.ObjectId(),
|
|
|
+ pageId: targetPageId,
|
|
|
+ body: 'Old content',
|
|
|
+ format: 'markdown',
|
|
|
+ author: currentUserId,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ _id: new mongoose.Types.ObjectId(),
|
|
|
+ pageId: targetPageId,
|
|
|
+ body: 'Newer content',
|
|
|
+ format: 'markdown',
|
|
|
+ author: currentUserId,
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ const result = await shouldGenerateUpdate({
|
|
|
+ targetPageId,
|
|
|
+ currentUserId,
|
|
|
+ currentActivityId,
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result).toBe(false);
|
|
|
+ });
|
|
|
});
|