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

Commit

Permalink
perf(customers): flatten customFieldsData, trackedData fields
Browse files Browse the repository at this point in the history
close #774
  • Loading branch information
batamar committed May 6, 2020
1 parent c5b4cb4 commit 934970b
Show file tree
Hide file tree
Showing 30 changed files with 434 additions and 170 deletions.
15 changes: 15 additions & 0 deletions elkSyncer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

client = Elasticsearch([ELASTICSEARCH_URL])

nestedType = {
"type" : "nested",
"properties" : {
"field" : { "type" : "keyword"},
"value" : { "type" : "text" },
"stringValue" : { "type" : "text" },
"numberValue" : { "type" : "float" },
"dateValue" : { "type" : "date" }
}
}

customer_mapping = {
'state': {
'type': 'keyword',
Expand Down Expand Up @@ -55,6 +66,8 @@
'emailValidationStatus': {
'type': 'keyword',
},
"customFieldsData" : nestedType,
"trackedData" : nestedType,
}

company_mapping = {
Expand Down Expand Up @@ -89,6 +102,7 @@
'businessType': {
'type': 'keyword',
},
"customFieldsData" : nestedType
}

event_mapping = {
Expand All @@ -101,6 +115,7 @@
'customerId': {
'type': 'keyword',
},
"attributes" : nestedType
}

analysis = {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/companyDb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Companies model tests', () => {
try {
await Companies.createCompany({
primaryName: 'name',
customFieldsData: { [field._id]: 'invalid number' },
customFieldsData: [{ field: field._id, value: 'invalid number' }],
});
} catch (e) {
expect(e.message).toBe(`${field.text}: Invalid number`);
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('Companies model tests', () => {
try {
await Companies.updateCompany(_company._id, {
primaryName: 'name',
customFieldsData: { [field._id]: 'invalid number' },
customFieldsData: [{ field: field._id, value: 'invalid number' }],
});
} catch (e) {
expect(e.message).toBe(`${field.text}: Invalid number`);
Expand Down
6 changes: 2 additions & 4 deletions src/__tests__/companyMutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ describe('Companies mutations', () => {
size: faker.random.number(),
industry: 'Airlines',
tagIds: company.tagIds,
customFieldsData: {},
parentCompanyId: parent._id,
};

Expand Down Expand Up @@ -102,7 +101,7 @@ describe('Companies mutations', () => {
expect(result.size).toBe(args.size);
expect(result.industry).toBe(args.industry);
expect(expect.arrayContaining(result.tagIds)).toEqual(args.tagIds);
expect(result.customFieldsData).toEqual(args.customFieldsData);
expect(result.customFieldsData.length).toEqual(0);
expect(result.parentCompanyId).toBe(parent._id);
});

Expand All @@ -127,7 +126,6 @@ describe('Companies mutations', () => {
emails: [faker.internet.email()],
size: faker.random.number(),
industry: faker.random.word(),
customFieldsData: {},
ownerId: _user._id,
parentCompanyId: parent._id,
tagIds: [tag2._id],
Expand Down Expand Up @@ -166,7 +164,7 @@ describe('Companies mutations', () => {
expect(result.size).toBe(args.size);
expect(result.industry).toBe(args.industry);
expect(expect.arrayContaining(result.tagIds)).toEqual(args.tagIds);
expect(result.customFieldsData).toEqual(args.customFieldsData);
expect(result.customFieldsData.length).toEqual(0);
expect(result.ownerId).toBe(_user._id);
expect(result.parentCompanyId).toBe(parent._id);
expect(result.mergedIds.length).toBe(1);
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/customerDb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('Customers model tests', () => {
await Customers.createCustomer({
primaryEmail: 'email',
emails: ['dombo@yahoo.com'],
customFieldsData: { [field._id]: 'invalid number' },
customFieldsData: [{ field: field._id, value: 'invalid number' }],
});
} catch (e) {
expect(e.message).toBe(`${field.text}: Invalid number`);
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('Customers model tests', () => {
await Customers.updateCustomer(_customer._id, {
primaryEmail: 'email',
emails: ['dombo@yahoo.com'],
customFieldsData: { [field._id]: 'invalid number' },
customFieldsData: [{ field: field._id, value: 'invalid number' }],
});
} catch (e) {
expect(e.message).toBe(`${field.text}: Invalid number`);
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/customerMutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const args = {
github: 'github',
website: 'website',
},
customFieldsData: {},
};

const checkCustomer = src => {
Expand Down Expand Up @@ -142,7 +141,7 @@ describe('Customers mutations', () => {
const customer = await graphqlRequest(mutation, 'customersAdd', args, context);

checkCustomer(customer);
expect(customer.customFieldsData).toEqual(null);
expect(customer.customFieldsData.length).toEqual(0);
});

test('Edit customer', async () => {
Expand Down Expand Up @@ -181,7 +180,7 @@ describe('Customers mutations', () => {
expect(customer._id).toBe(_customer._id);

checkCustomer(customer);
expect(customer.customFieldsData).toEqual({});
expect(customer.customFieldsData.length).toEqual(0);
});

test('Remove customer', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/customerQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('customerQueries', () => {
location
visitorContactInfo
customFieldsData
getTrackedData
trackedData
ownerId
position
department
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/dealQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { BOARD_STATUSES } from '../db/models/definitions/constants';
import './setup.ts';

describe('dealQueries', () => {
const commonDealTypes = `
const commonDealFields = `
_id
name
stageId
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('dealQueries', () => {
initialStageId: $initialStageId
userIds: $userIds
) {
${commonDealTypes}
${commonDealFields}
}
}
`;
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('dealQueries', () => {
throw new Error('Field not found');
}

const customFieldsData = { [field1._id]: 'text' };
const customFieldsData = [{ field: field1._id, value: 'text' }];

const product = await productFactory({ customFieldsData });
const productNoCustomData = await productFactory();
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('dealQueries', () => {
const qry = `
query deals($stageId: String!, $pipelineId: String, $sortField: String, $sortDirection: Int) {
deals(stageId: $stageId, pipelineId: $pipelineId, sortField: $sortField, sortDirection: $sortDirection) {
${commonDealTypes}
${commonDealFields}
}
}
`;
Expand Down Expand Up @@ -374,7 +374,7 @@ describe('dealQueries', () => {
const qry = `
query dealDetail($_id: String!) {
dealDetail(_id: $_id) {
${commonDealTypes}
${commonDealFields}
}
}
`;
Expand Down
33 changes: 25 additions & 8 deletions src/__tests__/fieldQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,33 @@ describe('fieldQueries', () => {
});

test('Fields combined by content type', async () => {
const mock = sinon.stub(elk, 'getMappings').callsFake(() => {
const mock = sinon.stub(elk, 'fetchElk').callsFake(() => {
return Promise.resolve({
[`${elk.getIndexPrefix()}customers`]: {
mappings: {
properties: {
trackedData: {
properties: {
name: 'value',
aggregations: {
trackedDataKeys: {
fieldKeys: {
buckets: [
{
key: 'pageView',
hits: {
hits: {
hits: [
{
_source: {
name: 'pageView',
attributes: [
{
field: 'url',
value: '/test',
},
],
},
},
],
},
},
},
},
],
},
},
},
Expand Down
15 changes: 10 additions & 5 deletions src/__tests__/productDb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ describe('Test products model', () => {
expect(productObj.sku).toEqual(`${product.sku}-update`);

// testing custom field data
const field = await fieldFactory({ contentType: 'product', contentTypeId: product._id });
args.customFieldsData = {
[field._id]: 10,
};
const field1 = await fieldFactory({ contentType: 'product', contentTypeId: product._id });
const field2 = await fieldFactory({ contentType: 'product', contentTypeId: product._id, validation: 'date' });

args.customFieldsData = [
{ field: field1._id, value: 10 },
{ field: field2._id, value: '2011-01-01' },
];

productObj = await Products.updateProduct(product._id, args);

expect(productObj.customFieldsData[field._id]).toBe(10);
if (productObj.customFieldsData) {
expect(productObj.customFieldsData[0].value).toBe('10');
}
});

test('Can not remove products', async () => {
Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/segmentQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ describe('segmentQueries', () => {
{
_source: {
name: 'pageView',
attributes: [],
attributes: [
{
field: 'url',
value: '/test',
},
],
},
},
],
Expand Down
Loading

0 comments on commit 934970b

Please sign in to comment.