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

Commit 08e060d

Browse files
author
batamar
committed
Merge branch 'release-0.9.4'
2 parents 7563abe + fc32eef commit 08e060d

Some content is hidden

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

72 files changed

+2270
-405
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ static
55
npm-debug.log*
66
.env
77
coverage
8+
dump.rdb

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
This repository is the main web app of the erxes platform that consists of 2 other repositories:
77

8-
- [Flatform](https://github.com/erxes/erxes)
8+
- [Erxes](https://github.com/erxes/erxes)
99
- [Widgets](https://github.com/erxes/erxes-widgets)
1010

1111
Clone erxes repository and install its dependencies:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "erxes-app-api",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"description": "GraphQL API for erxes main project",
55
"homepage": "https://erxes.io",
66
"repository": "https://github.com/erxes/erxes-app-api",
@@ -51,13 +51,14 @@
5151
"fbgraph": "^1.4.1",
5252
"formidable": "^1.1.1",
5353
"graphql": "^0.10.1",
54-
"graphql-redis-subscriptions": "^1.3.1",
54+
"graphql-redis-subscriptions": "^1.4.0",
5555
"graphql-server-core": "^0.8.2",
5656
"graphql-server-express": "^0.8.2",
5757
"graphql-server-module-graphiql": "^0.8.2",
5858
"graphql-subscriptions": "^0.4.4",
5959
"graphql-tools": "^1.0.0",
6060
"handlebars": "^4.0.10",
61+
"ioredis": "^3.2.2",
6162
"jsonwebtoken": "^8.1.0",
6263
"meteor-random": "^0.0.3",
6364
"moment": "^2.18.1",

src/__tests__/activityLogDb.test.js

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ describe('ActivityLogs model methods', () => {
125125
});
126126
});
127127

128+
test(`Testing found segment`, async () => {
129+
const segment = await segmentFactory({});
130+
const customer = await customerFactory({});
131+
await ActivityLogs.createSegmentLog(segment, customer);
132+
133+
await ActivityLogs.createSegmentLog(segment, customer);
134+
135+
expect(
136+
await ActivityLogs.find({
137+
'activity.type': ACTIVITY_TYPES.SEGMENT,
138+
'activity.action': ACTIVITY_ACTIONS.CREATE,
139+
'activity.id': segment._id,
140+
'coc.type': segment.contentType,
141+
'coc.id': customer._id,
142+
}),
143+
).toHaveLength(1);
144+
});
145+
128146
test(`check if exceptions are being thrown as intended when
129147
calling createConversationLog`, async () => {
130148
expect.assertions(2);
@@ -151,7 +169,9 @@ describe('ActivityLogs model methods', () => {
151169
const conversation = await conversationFactory({});
152170
const companyA = await companyFactory({});
153171
const companyB = await companyFactory({});
154-
const customer = await customerFactory({ companyIds: [companyA._id, companyB._id] });
172+
const customer = await customerFactory({
173+
companyIds: [companyA._id, companyB._id],
174+
});
155175

156176
let aLog = await ActivityLogs.createConversationLog(conversation, customer);
157177

@@ -245,4 +265,74 @@ describe('ActivityLogs model methods', () => {
245265
id: company._id,
246266
});
247267
});
268+
269+
test(`changeCustomer`, async () => {
270+
const customer = await customerFactory({});
271+
const newCustomer = await customerFactory({});
272+
const conversation = await conversationFactory({});
273+
274+
await ActivityLogs.createConversationLog(conversation, customer);
275+
276+
const aLogs = await ActivityLogs.changeCustomer(newCustomer._id, [customer._id]);
277+
278+
for (let aLog of aLogs) {
279+
expect(aLog.coc.toObject()).toEqual({
280+
type: COC_CONTENT_TYPES.CUSTOMER,
281+
id: newCustomer._id,
282+
});
283+
}
284+
});
285+
286+
test(`changeCompany`, async () => {
287+
const company = await companyFactory({});
288+
const newCompany = await companyFactory({});
289+
const user = await userFactory({});
290+
291+
await ActivityLogs.createCompanyRegistrationLog(company, user);
292+
293+
const aLogs = await ActivityLogs.changeCompany(newCompany._id, [company._id]);
294+
295+
for (let aLog of aLogs) {
296+
expect(aLog.coc.toObject()).toEqual({
297+
type: COC_CONTENT_TYPES.COMPANY,
298+
id: newCompany._id,
299+
});
300+
}
301+
});
302+
303+
test(`removeCustomerActivityLog`, async () => {
304+
const customer = await customerFactory({});
305+
const conversation = await conversationFactory({});
306+
307+
await ActivityLogs.createConversationLog(conversation, customer);
308+
const removed = await ActivityLogs.removeCustomerActivityLog(customer._id);
309+
310+
const activityLog = await ActivityLogs.find({
311+
coc: {
312+
type: COC_CONTENT_TYPES.CUSTOMER,
313+
id: customer._id,
314+
},
315+
});
316+
317+
expect(activityLog).toHaveLength(0);
318+
expect(removed.result).toEqual({ ok: 1, n: 1 });
319+
});
320+
321+
test(`removeCompanyActivityLog`, async () => {
322+
const company = await companyFactory({});
323+
const user = await userFactory({});
324+
325+
await ActivityLogs.createCompanyRegistrationLog(company, user);
326+
const removed = await ActivityLogs.removeCompanyActivityLog(company._id);
327+
328+
const activityLog = await ActivityLogs.find({
329+
coc: {
330+
type: COC_CONTENT_TYPES.COMPANY,
331+
id: company._id,
332+
},
333+
});
334+
335+
expect(activityLog).toHaveLength(0);
336+
expect(removed.result).toEqual({ ok: 1, n: 1 });
337+
});
248338
});

src/__tests__/brandDb.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/* eslint-disable no-underscore-dangle */
33

44
import { connect, disconnect } from '../db/connection';
5-
import { Brands, Users } from '../db/models';
6-
import { brandFactory, userFactory } from '../db/factories';
5+
import { Brands, Users, Integrations } from '../db/models';
6+
import { brandFactory, userFactory, integrationFactory } from '../db/factories';
77

88
beforeAll(() => connect());
99

@@ -81,4 +81,22 @@ describe('Brands db', () => {
8181
expect(brandObj.emailConfig.type).toBe(_brand.emailConfig.type);
8282
expect(brandObj.emailConfig.template).toBe(_brand.emailConfig.template);
8383
});
84+
85+
test('Manage integrations', async () => {
86+
const brand = await brandFactory({});
87+
88+
let integration1 = await integrationFactory({});
89+
let integration2 = await integrationFactory({});
90+
91+
await Brands.manageIntegrations({
92+
_id: brand._id,
93+
integrationIds: [integration1._id, integration2._id],
94+
});
95+
96+
integration1 = await Integrations.findOne({ _id: integration1._id });
97+
integration2 = await Integrations.findOne({ _id: integration2._id });
98+
99+
expect(integration1.brandId).toBe(brand._id);
100+
expect(integration2.brandId).toBe(brand._id);
101+
});
84102
});

src/__tests__/brandMutations.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,15 @@ describe('Brands mutations', () => {
113113
expect(Brands.updateEmailConfig.mock.calls.length).toBe(1);
114114
expect(Brands.updateEmailConfig).toBeCalledWith(_brand._id, _brand.emailConfig);
115115
});
116+
117+
test('Manage integrations', async () => {
118+
Brands.manageIntegrations = jest.fn();
119+
120+
const args = { _id: _brand._id, integrationIds: ['_id1', '_id2'] };
121+
122+
await brandMutations.brandsManageIntegrations({}, args, { user: _adminUser });
123+
124+
expect(Brands.manageIntegrations.mock.calls.length).toBe(1);
125+
expect(Brands.manageIntegrations).toBeCalledWith(args);
126+
});
116127
});

src/__tests__/companyDb.test.js

Lines changed: 163 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
/* eslint-disable no-underscore-dangle */
33

44
import { connect, disconnect } from '../db/connection';
5-
import { Companies } from '../db/models';
6-
import { companyFactory, fieldFactory } from '../db/factories';
5+
import { Companies, Customers, InternalNotes, ActivityLogs } from '../db/models';
6+
import {
7+
companyFactory,
8+
fieldFactory,
9+
internalNoteFactory,
10+
activityLogFactory,
11+
customerFactory,
12+
} from '../db/factories';
13+
import { COC_CONTENT_TYPES } from '../data/constants';
714

815
beforeAll(() => connect());
916

@@ -121,4 +128,158 @@ describe('Companies model tests', () => {
121128
expect(e.message).toBe(`${field.text}: Invalid number`);
122129
}
123130
});
131+
132+
test('Update company customers', async () => {
133+
const customerIds = ['12313qwrqwe', '123', '11234'];
134+
135+
await Companies.updateCustomers(_company._id, customerIds);
136+
137+
for (let customerId of customerIds) {
138+
const customerObj = await Customers.findOne({ _id: customerId });
139+
140+
expect(customerObj.companyIds).toContain(_company._id);
141+
}
142+
});
143+
144+
test('removeCompany', async () => {
145+
const company = await companyFactory({});
146+
await customerFactory({ companyIds: [company._id] });
147+
148+
await internalNoteFactory({
149+
contentType: COC_CONTENT_TYPES.COMPANY,
150+
contentTypeId: company._id,
151+
});
152+
153+
const removed = await Companies.removeCompany(company._id);
154+
155+
const internalNote = await InternalNotes.find({
156+
contentType: COC_CONTENT_TYPES.COMPANY,
157+
contentTypeId: company._id,
158+
});
159+
160+
const activityLog = await ActivityLogs.find({
161+
coc: {
162+
type: COC_CONTENT_TYPES.COMPANY,
163+
id: company._id,
164+
},
165+
});
166+
167+
const customers = await Customers.find({ companyIds: { $in: [company._id] } });
168+
169+
expect(customers).toHaveLength(0);
170+
expect(internalNote).toHaveLength(0);
171+
expect(activityLog).toHaveLength(0);
172+
expect(removed.result).toEqual({ n: 1, ok: 1 });
173+
});
174+
175+
test('mergeCompanies', async () => {
176+
const testCompany = await companyFactory({
177+
tagIds: ['123', '456', '1234'],
178+
});
179+
180+
const testCompany2 = await companyFactory({
181+
tagIds: ['1231', '123', 'asd12'],
182+
});
183+
184+
let testCustomer = await customerFactory({
185+
companyIds: [testCompany._id],
186+
});
187+
188+
let testCustomer2 = await customerFactory({
189+
companyIds: [testCompany2._id],
190+
});
191+
192+
const companyIds = [testCompany._id, testCompany2._id];
193+
const mergedTagIds = Array.from(new Set(testCompany.tagIds.concat(testCompany2.tagIds)));
194+
195+
// test duplication
196+
try {
197+
await Companies.mergeCompanies(companyIds, { name: _company.name });
198+
} catch (e) {
199+
expect(e.message).toBe('Duplicated name');
200+
}
201+
202+
await internalNoteFactory({
203+
contentType: COC_CONTENT_TYPES.COMPANY,
204+
contentTypeId: companyIds[0],
205+
});
206+
207+
await activityLogFactory({
208+
coc: {
209+
type: COC_CONTENT_TYPES.COMPANY,
210+
id: companyIds[0],
211+
},
212+
});
213+
214+
const doc = {
215+
name: 'Test name',
216+
website: 'Test webiste',
217+
size: 230,
218+
industry: 'Test industry',
219+
plan: 'Test plan',
220+
};
221+
222+
const updatedCompany = await Companies.mergeCompanies(companyIds, doc);
223+
224+
expect(updatedCompany.name).toBe(doc.name);
225+
expect(updatedCompany.website).toBe(doc.website);
226+
expect(updatedCompany.size).toBe(doc.size);
227+
expect(updatedCompany.industry).toBe(doc.industry);
228+
expect(updatedCompany.plan).toBe(doc.plan);
229+
230+
// Checking old company datas deleted
231+
expect(await Companies.find({ _id: companyIds[0] })).toHaveLength(0);
232+
expect(updatedCompany.tagIds).toEqual(expect.arrayContaining(mergedTagIds));
233+
234+
testCustomer = await Customers.findOne({ _id: testCustomer._id });
235+
expect(testCustomer.companyIds).not.toContain(testCompany._id);
236+
237+
testCustomer2 = await Customers.findOne({ _id: testCustomer2._id });
238+
expect(testCustomer2.companyIds).not.toContain(testCompany2._id);
239+
240+
let internalNote = await InternalNotes.find({
241+
contentType: COC_CONTENT_TYPES.COMPANY,
242+
contentTypeId: companyIds[0],
243+
});
244+
245+
let activityLog = await ActivityLogs.find({
246+
coc: {
247+
type: COC_CONTENT_TYPES.COMPANY,
248+
id: companyIds[0],
249+
},
250+
});
251+
252+
expect(internalNote).toHaveLength(0);
253+
expect(activityLog).toHaveLength(0);
254+
255+
// Checking new company datas updated
256+
expect(updatedCompany.tagIds).toEqual(expect.arrayContaining(mergedTagIds));
257+
258+
expect(testCustomer.companyIds).toContain(updatedCompany._id);
259+
expect(testCustomer2.companyIds).toContain(updatedCompany._id);
260+
261+
internalNote = await InternalNotes.find({
262+
contentType: COC_CONTENT_TYPES.COMPANY,
263+
contentTypeId: updatedCompany._id,
264+
});
265+
266+
activityLog = await ActivityLogs.find({
267+
coc: {
268+
type: COC_CONTENT_TYPES.COMPANY,
269+
id: updatedCompany._id,
270+
},
271+
});
272+
273+
expect(internalNote).not.toHaveLength(0);
274+
expect(activityLog).not.toHaveLength(0);
275+
});
276+
277+
test('Check Duplication', async () => {
278+
// check duplication
279+
try {
280+
await Companies.checkDuplication({ name: _company.name }, '123132');
281+
} catch (e) {
282+
expect(e.message).toBe('Duplicated name');
283+
}
284+
});
124285
});

0 commit comments

Comments
 (0)