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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
batamar committed Jan 8, 2020
2 parents fee40d4 + 4068251 commit c523b65
Show file tree
Hide file tree
Showing 129 changed files with 5,436 additions and 661 deletions.
3 changes: 1 addition & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ MAIN_APP_DOMAIN=http://localhost:3000
WIDGETS_DOMAIN=http://localhost:3200
INTEGRATIONS_API_DOMAIN=http://localhost:3400

# erxes non public domains
WIDGETS_API_DOMAIN=http://localhost:3100
# http://localhost:3600
CRONS_API_DOMAIN=
# http://localhost:3700
Expand Down Expand Up @@ -82,3 +80,4 @@ USE_BRAND_RESTRICTIONS=false

# separate upload file mime types by comma
UPLOAD_FILE_TYPES=image/png,image/jpeg,image/jpg,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,
WIDGETS_UPLOAD_FILE_TYPES=image/png,image/jpeg,image/jpg,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,
5 changes: 5 additions & 0 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ patch:
SNYK-JS-LODASH-450202:
- apollo-server-express > apollo-server-core > apollo-engine-reporting > lodash:
patched: '2019-10-29T23:28:52.891Z'
'@snyk/dep-graph > graphlib > lodash':
patched: '2020-01-08T11:18:38.625Z'
- apollo-server-express > apollo-server-core > lodash:
patched: '2019-10-29T23:28:52.891Z'
- firebase-admin > @google-cloud/storage > async > lodash:
Expand All @@ -96,3 +98,6 @@ patch:
patched: '2019-10-29T23:34:16.286Z'
- snyk > snyk-go-plugin > graphlib > lodash:
patched: '2019-10-29T23:34:16.286Z'
SNYK-JS-TREEKILL-536781:
- snyk > snyk-sbt-plugin > tree-kill:
patched: '2020-01-08T11:06:24.493Z'
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@
"request": "^2.88.0",
"requestify": "^0.2.5",
"sha256": "^0.2.0",
"snyk": "^1.239.5",
"snyk": "^1.277.1",
"strip": "^3.0.0",
"twit": "^2.2.9",
"underscore": "^1.8.3",
"uuid": "^3.3.3",
"validator": "^9.0.0",
"xlsx-populate": "^1.20.1",
"xss": "^1.0.6"
Expand Down
34 changes: 26 additions & 8 deletions src/__tests__/boardDb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
stageFactory,
userFactory,
} from '../db/factories';
import { Boards, Pipelines, Stages } from '../db/models';
import { Boards, Forms, Pipelines, Stages } from '../db/models';
import { IBoardDocument, IPipelineDocument, IStageDocument } from '../db/models/definitions/boards';
import { IUserDocument } from '../db/models/definitions/users';

Expand Down Expand Up @@ -77,13 +77,14 @@ describe('Test board model', () => {
});

test('Remove board', async () => {
const doc = { boardId: 'boardId' };
const removeBoard = await boardFactory();

await Pipelines.updateMany({}, { $set: doc });
const removedPipeline = await pipelineFactory({ boardId: removeBoard._id });

const isDeleted = await Boards.removeBoard(board.id);
const isDeleted = await Boards.removeBoard(removeBoard.id);

expect(isDeleted).toBeTruthy();
expect(await Stages.findOne({ _id: removedPipeline._id })).toBeNull();
});

test('Remove board not found', async () => {
Expand Down Expand Up @@ -258,12 +259,13 @@ describe('Test board model', () => {
});

test('Remove pipeline', async () => {
const doc = { pipelineId: 'pipelineId' };
const removePipeline = await pipelineFactory();
const removedStage = await stageFactory({ pipelineId: removePipeline._id });

await Stages.updateMany({}, { $set: doc });
const isDeleted = await Pipelines.removePipeline(removePipeline.id);

const isDeleted = await Pipelines.removePipeline(pipeline.id);
expect(isDeleted).toBeTruthy();
expect(await Stages.findOne({ _id: removedStage._id })).toBeNull();
});

test('Remove pipeline not found', async () => {
Expand Down Expand Up @@ -315,7 +317,6 @@ describe('Test board model', () => {
expect(response).toBeDefined();
});

// Test deal stage
test('Create stage', async () => {
const createdStage = await Stages.createStage({
name: stage.name,
Expand All @@ -332,6 +333,23 @@ describe('Test board model', () => {
expect(createdStage.userId).toEqual(user._id);
});

test('Remove stage', async () => {
const isDeleted = await Stages.removeStage(stage._id);

expect(isDeleted).toBeTruthy();
});

test('Remove stage with form', async () => {
const form = await formFactory();

const stageWithForm = await stageFactory({ formId: form._id });

const isDeleted = await Stages.removeStage(stageWithForm._id);

expect(isDeleted).toBeTruthy();
expect(await Forms.findOne({ _id: form._id })).toBeNull();
});

test('Update stage', async () => {
const stageName = 'Update stage name';
const updatedStage = await Stages.updateStage(stage._id, {
Expand Down
137 changes: 124 additions & 13 deletions src/__tests__/boardQueries.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { graphqlRequest } from '../db/connection';
import { boardFactory, dealFactory, pipelineFactory, productFactory, stageFactory, userFactory } from '../db/factories';
import {
boardFactory,
conversationFactory,
dealFactory,
pipelineFactory,
productFactory,
stageFactory,
taskFactory,
ticketFactory,
userFactory,
} from '../db/factories';
import { Boards, Pipelines, Stages } from '../db/models';

import moment = require('moment');
Expand Down Expand Up @@ -47,6 +57,14 @@ describe('boardQueries', () => {
}
`;

const pipelineQry = `
query pipelines($boardId: String, $type: String, $perPage: Int, $page: Int) {
pipelines(boardId: $boardId, type: $type, perPage: $perPage, page: $page) {
${commonPipelineTypes}
}
}
`;

afterEach(async () => {
// Clearing test data
await Boards.deleteMany({});
Expand All @@ -72,6 +90,41 @@ describe('boardQueries', () => {
expect(response.length).toBe(3);
});

test('Board count', async () => {
const boardOne = await boardFactory({ name: 'A' });
await pipelineFactory({ boardId: boardOne._id });
await pipelineFactory({ boardId: boardOne._id });

const boardTwo = await boardFactory({ name: 'B' });
await pipelineFactory({ boardId: boardTwo._id });

const boardThree = await boardFactory({ name: 'C' });

const qry = `
query boardCounts($type: String!) {
boardCounts(type: $type) {
_id
name
count
}
}
`;

const response = await graphqlRequest(qry, 'boardCounts', { type: 'deal' });

expect(response[0].name).toBe('All');
expect(response[0].count).toBe(3);

expect(response[1].name).toBe(boardOne.name);
expect(response[1].count).toBe(2);

expect(response[2].name).toBe(boardTwo.name);
expect(response[2].count).toBe(1);

expect(response[3].name).toBe(boardThree.name);
expect(response[3].count).toBe(0);
});

test('Board detail', async () => {
const board = await boardFactory();

Expand All @@ -96,7 +149,7 @@ describe('boardQueries', () => {
});

test('Board get last', async () => {
const board = await boardFactory({ type: BOARD_TYPES.DEAL });
const board = await boardFactory();

const qry = `
query boardGetLast($type: String!) {
Expand All @@ -112,25 +165,39 @@ describe('boardQueries', () => {
});

test('Pipelines', async () => {
await pipelineFactory();
await pipelineFactory();
await pipelineFactory();

const response = await graphqlRequest(pipelineQry, 'pipelines');

expect(response.length).toBe(3);
});

test('Pipelines with filter', async () => {
const board = await boardFactory();
const args = { boardId: board._id, type: 'deal' };

await pipelineFactory(args);
await pipelineFactory(args);
await pipelineFactory();

const response = await graphqlRequest(pipelineQry, 'pipelines', args);

const args = { boardId: board._id };
expect(response.length).toBe(2);
});

test('Pipelines with pagination', async () => {
const board = await boardFactory();
const args = { boardId: board._id, type: 'deal' };

await pipelineFactory(args);
await pipelineFactory(args);
await pipelineFactory(args);

const qry = `
query pipelines($boardId: String!) {
pipelines(boardId: $boardId) {
${commonPipelineTypes}
}
}
`;

const response = await graphqlRequest(qry, 'pipelines', args);
const response = await graphqlRequest(pipelineQry, 'pipelines', { ...args, perPage: 2, page: 1 });

expect(response.length).toBe(3);
expect(response.length).toBe(2);
});

test('Pipeline detail', async () => {
Expand Down Expand Up @@ -356,4 +423,48 @@ describe('boardQueries', () => {

expect(response._id).toBe(stage._id);
});

test('Convert to info', async () => {
const conversation = await conversationFactory();

const qry = `
query convertToInfo($conversationId: String!) {
convertToInfo(conversationId: $conversationId) {
dealUrl
ticketUrl
taskUrl
}
}
`;

const dealBoard = await boardFactory({ type: BOARD_TYPES.DEAL });
const dealPipeline = await pipelineFactory({ type: BOARD_TYPES.DEAL, boardId: dealBoard._id });
const dealStage = await stageFactory({ type: BOARD_TYPES.DEAL, pipelineId: dealPipeline._id });

const deal = await dealFactory({ sourceConversationId: conversation._id, stageId: dealStage._id });

const taskBoard = await boardFactory({ type: BOARD_TYPES.TASK });
const taskPipeline = await pipelineFactory({ type: BOARD_TYPES.TASK, boardId: taskBoard._id });
const taskStage = await stageFactory({ type: BOARD_TYPES.TASK, pipelineId: taskPipeline._id });
const task = await taskFactory({ sourceConversationId: conversation._id, stageId: taskStage._id });

const ticketBoard = await boardFactory({ type: BOARD_TYPES.DEAL });
const ticketPipeline = await pipelineFactory({ type: BOARD_TYPES.DEAL, boardId: ticketBoard._id });
const ticketStage = await stageFactory({ type: BOARD_TYPES.DEAL, pipelineId: ticketPipeline._id });
const ticket = await ticketFactory({ sourceConversationId: conversation._id, stageId: ticketStage._id });

let response = await graphqlRequest(qry, 'convertToInfo', { conversationId: conversation._id });

expect(response.dealUrl).toBe(`/deal/board?_id=${dealBoard._id}&pipelineId=${dealPipeline._id}&itemId=${deal._id}`);
expect(response.taskUrl).toBe(`/task/board?_id=${taskBoard._id}&pipelineId=${taskPipeline._id}&itemId=${task._id}`);
expect(response.ticketUrl).toBe(
`/inbox/ticket/board?_id=${ticketBoard._id}&pipelineId=${ticketPipeline._id}&itemId=${ticket._id}`,
);

response = await graphqlRequest(qry, 'convertToInfo', { conversationId: 'fakeId' });

expect(response.dealUrl).toBe('');
expect(response.ticketUrl).toBe('');
expect(response.taskUrl).toBe('');
});
});
36 changes: 33 additions & 3 deletions src/__tests__/companyQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,18 @@ describe('companyQueries', () => {
});

test('Companies filtered by search value', async () => {
await companyFactory({ names: [name], primaryName: name });
await companyFactory({ plan });
await companyFactory({ industry: 'Banks' });
const phone = '99999999';
const email = '[email protected]';
const website = 'www.google.com';

await companyFactory({
names: [name],
plan,
industry: 'Banks',
website,
emails: [email],
phones: [phone],
});

// companies by name ==============
let responses = await graphqlRequest(qryCompanies, 'companies', {
Expand All @@ -208,6 +217,27 @@ describe('companyQueries', () => {
});

expect(responses.length).toBe(1);

// companies by website ==============
responses = await graphqlRequest(qryCompanies, 'companies', {
searchValue: website,
});

expect(responses.length).toBe(1);

// companies by email ==============
responses = await graphqlRequest(qryCompanies, 'companies', {
searchValue: email,
});

expect(responses.length).toBe(1);

// companies by phone ==============
responses = await graphqlRequest(qryCompanies, 'companies', {
searchValue: phone,
});

expect(responses.length).toBe(1);
});

test('Companies filtered by brandId', async () => {
Expand Down
23 changes: 0 additions & 23 deletions src/__tests__/configMutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { graphqlRequest } from '../db/connection';

import { EngagesAPI } from '../data/dataSources';
import './setup.ts';

describe('Test configs mutations', () => {
Expand Down Expand Up @@ -32,26 +31,4 @@ describe('Test configs mutations', () => {
expect(config.value.length).toEqual(1);
expect(config.value[0]).toEqual('USD');
});

test('Insert config', async () => {
process.env.ENGAGES_API_DOMAIN = 'http://fake.erxes.io';

const mutation = `
mutation engagesConfigSave($accessKeyId: String, $secretAccessKey: String, $region: String) {
engagesConfigSave(accessKeyId: $accessKeyId, secretAccessKey: $secretAccessKey, region: $region) {
accessKeyId
secretAccessKey
region
}
}
`;

const dataSources = { EngagesAPI: new EngagesAPI() };

try {
await graphqlRequest(mutation, 'engagesConfigSave', {}, { dataSources });
} catch (e) {
expect(e[0].message).toBe('Engages api is not running');
}
});
});
Loading

0 comments on commit c523b65

Please sign in to comment.