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

Commit dd68af5

Browse files
Enkhtuvshin0513Battulga BatAmar
authored andcommitted
feat(activity-log): reimplement activity log
close #665
1 parent a6b1254 commit dd68af5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1152
-937
lines changed

jest.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = {
1111
collectCoverage: true,
1212
collectCoverageFrom: [
1313
'src/db/models/**',
14-
'!src/db/models/ActivityLogs.ts',
1514
'!src/db/models/Robot.ts',
1615
'!src/db/models/definitions/**',
1716
'src/data/resolvers/**',
@@ -33,4 +32,4 @@ module.exports = {
3332
tsConfigFile: 'tsconfig.json',
3433
},
3534
},
36-
};
35+
};

src/__tests__/activityDb.test.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import * as faker from 'faker';
2+
import { ActivityLogs, Customers, Deals, Segments } from '../db/models';
3+
4+
import { activityLogFactory, customerFactory, dealFactory, segmentFactory } from '../db/factories';
5+
import './setup.ts';
6+
7+
describe('Test activity model', () => {
8+
afterEach(async () => {
9+
// Clearing test data
10+
await ActivityLogs.deleteMany({});
11+
await Deals.deleteMany({});
12+
await Segments.deleteMany({});
13+
await Customers.deleteMany({});
14+
});
15+
16+
test('Activity add activity', async () => {
17+
const contentId = faker.random.uuid();
18+
const contentType = 'customer';
19+
const createdBy = faker.random.uuid();
20+
const action = 'create';
21+
22+
const activity = await ActivityLogs.addActivityLog({
23+
contentId,
24+
contentType,
25+
createdBy,
26+
action,
27+
});
28+
29+
expect(activity).toBeDefined();
30+
expect(activity.contentId).toEqual(contentId);
31+
expect(activity.contentType).toEqual(contentType);
32+
expect(activity.createdBy).toEqual(createdBy);
33+
expect(activity.action).toEqual(action);
34+
});
35+
36+
test('Activity remove activity', async () => {
37+
const activity = await activityLogFactory();
38+
39+
await ActivityLogs.removeActivityLog(activity.contentId);
40+
41+
const count = await ActivityLogs.find({ contentId: activity.contentId }).countDocuments();
42+
43+
expect(count).toBe(0);
44+
});
45+
46+
test('Activity create board item log', async () => {
47+
const deal = await dealFactory({});
48+
49+
const activity = await ActivityLogs.createBoardItemLog({ item: deal, contentType: 'deal' });
50+
51+
expect(activity.contentId).toEqual(deal._id);
52+
});
53+
54+
test('Activity create log from widget', async () => {
55+
const item = await customerFactory({});
56+
57+
const activity1 = await ActivityLogs.createLogFromWidget('create-customer', item);
58+
const activity2 = await ActivityLogs.createLogFromWidget('create-company', item);
59+
60+
expect(activity1.contentId).toEqual(item._id);
61+
expect(activity2.contentId).toEqual(item._id);
62+
});
63+
64+
test('Activity create coc log', async () => {
65+
const item = await customerFactory({ mergedIds: ['1', '2'] });
66+
const item2 = await customerFactory({ integrationId: '123', ownerId: undefined });
67+
68+
const activity1 = await ActivityLogs.createCocLog({ coc: item, contentType: 'customer' });
69+
const activity2 = await ActivityLogs.createCocLog({ coc: item2, contentType: 'customer' });
70+
71+
expect(activity1.contentId).toEqual(item._id);
72+
expect(activity2.contentId).toEqual(item2._id);
73+
});
74+
75+
test('Activity create board item movement log', async () => {
76+
const item = await dealFactory({});
77+
78+
const activity1 = await ActivityLogs.createBoardItemMovementLog(item, 'deal', '123', {});
79+
80+
expect(activity1.contentId).toEqual(item._id);
81+
});
82+
83+
test('Activity create board item movement log', async () => {
84+
const customer = await customerFactory({});
85+
const segment1 = await segmentFactory({});
86+
const segment2 = await segmentFactory({});
87+
88+
const foundedActivity = await ActivityLogs.create({
89+
contentType: 'customer',
90+
action: 'segment',
91+
contentId: customer._id,
92+
content: {
93+
id: segment1._id,
94+
content: segment2,
95+
},
96+
});
97+
98+
const activity1 = await ActivityLogs.createSegmentLog(segment1, customer, 'customer');
99+
const activity2 = await ActivityLogs.createSegmentLog(segment2, customer, 'customer');
100+
101+
expect(activity1._id).toEqual(foundedActivity._id);
102+
expect(activity2._id).toEqual(activity2._id);
103+
});
104+
});

src/__tests__/activityLogCronJob.test.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)