Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
feat(activity-log): reimplement activity log
Browse files Browse the repository at this point in the history
close #665
  • Loading branch information
Enkhtuvshin0513 authored and batamar committed Dec 5, 2019
1 parent a6b1254 commit dd68af5
Show file tree
Hide file tree
Showing 74 changed files with 1,152 additions and 937 deletions.
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
collectCoverage: true,
collectCoverageFrom: [
'src/db/models/**',
'!src/db/models/ActivityLogs.ts',
'!src/db/models/Robot.ts',
'!src/db/models/definitions/**',
'src/data/resolvers/**',
Expand All @@ -33,4 +32,4 @@ module.exports = {
tsConfigFile: 'tsconfig.json',
},
},
};
};
104 changes: 104 additions & 0 deletions src/__tests__/activityDb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import * as faker from 'faker';
import { ActivityLogs, Customers, Deals, Segments } from '../db/models';

import { activityLogFactory, customerFactory, dealFactory, segmentFactory } from '../db/factories';
import './setup.ts';

describe('Test activity model', () => {
afterEach(async () => {
// Clearing test data
await ActivityLogs.deleteMany({});
await Deals.deleteMany({});
await Segments.deleteMany({});
await Customers.deleteMany({});
});

test('Activity add activity', async () => {
const contentId = faker.random.uuid();
const contentType = 'customer';
const createdBy = faker.random.uuid();
const action = 'create';

const activity = await ActivityLogs.addActivityLog({
contentId,
contentType,
createdBy,
action,
});

expect(activity).toBeDefined();
expect(activity.contentId).toEqual(contentId);
expect(activity.contentType).toEqual(contentType);
expect(activity.createdBy).toEqual(createdBy);
expect(activity.action).toEqual(action);
});

test('Activity remove activity', async () => {
const activity = await activityLogFactory();

await ActivityLogs.removeActivityLog(activity.contentId);

const count = await ActivityLogs.find({ contentId: activity.contentId }).countDocuments();

expect(count).toBe(0);
});

test('Activity create board item log', async () => {
const deal = await dealFactory({});

const activity = await ActivityLogs.createBoardItemLog({ item: deal, contentType: 'deal' });

expect(activity.contentId).toEqual(deal._id);
});

test('Activity create log from widget', async () => {
const item = await customerFactory({});

const activity1 = await ActivityLogs.createLogFromWidget('create-customer', item);
const activity2 = await ActivityLogs.createLogFromWidget('create-company', item);

expect(activity1.contentId).toEqual(item._id);
expect(activity2.contentId).toEqual(item._id);
});

test('Activity create coc log', async () => {
const item = await customerFactory({ mergedIds: ['1', '2'] });
const item2 = await customerFactory({ integrationId: '123', ownerId: undefined });

const activity1 = await ActivityLogs.createCocLog({ coc: item, contentType: 'customer' });
const activity2 = await ActivityLogs.createCocLog({ coc: item2, contentType: 'customer' });

expect(activity1.contentId).toEqual(item._id);
expect(activity2.contentId).toEqual(item2._id);
});

test('Activity create board item movement log', async () => {
const item = await dealFactory({});

const activity1 = await ActivityLogs.createBoardItemMovementLog(item, 'deal', '123', {});

expect(activity1.contentId).toEqual(item._id);
});

test('Activity create board item movement log', async () => {
const customer = await customerFactory({});
const segment1 = await segmentFactory({});
const segment2 = await segmentFactory({});

const foundedActivity = await ActivityLogs.create({
contentType: 'customer',
action: 'segment',
contentId: customer._id,
content: {
id: segment1._id,
content: segment2,
},
});

const activity1 = await ActivityLogs.createSegmentLog(segment1, customer, 'customer');
const activity2 = await ActivityLogs.createSegmentLog(segment2, customer, 'customer');

expect(activity1._id).toEqual(foundedActivity._id);
expect(activity2._id).toEqual(activity2._id);
});
});
85 changes: 0 additions & 85 deletions src/__tests__/activityLogCronJob.test.ts

This file was deleted.

Loading

0 comments on commit dd68af5

Please sign in to comment.