Skip to content

Commit

Permalink
fix: adding map for marketo known values and javascript known values
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jan 29, 2024
1 parent 1c6a83c commit e979e4e
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"name": "Launch TS",
"program": "${workspaceFolder}/dist/src/index.js",
"outFiles": ["${workspaceFolder}/dist/src/**/*.js"],
"runtimeExecutable": "/usr/local/bin/node"
"runtimeExecutable": "/Users/shrouti/.nvm/versions/node/v18.19.0/bin/node"
},
{
"name": "benchmark",
Expand All @@ -29,7 +29,7 @@
"args": ["--destinations=${input:destinations}", "--feature=${input:feature}"],
"runtimeArgs": ["--nolazy"],
"sourceMaps": true,
"runtimeExecutable": "/usr/local/bin/node"
"runtimeExecutable": "/Users/shrouti/.nvm/versions/node/v18.19.0/bin/node"
},
{
"runtimeExecutable": "/usr/local/bin/node",
Expand Down
18 changes: 18 additions & 0 deletions src/v0/destinations/marketo_bulk_upload/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ const FETCH_FAILURE_JOB_STATUS_ERR_MSG = 'Could not fetch failure job status';
const FETCH_WARNING_JOB_STATUS_ERR_MSG = 'Could not fetch warning job status';
const ACCESS_TOKEN_FETCH_ERR_MSG = 'Error during fetching access token';

const SCHEMA_DATA_TYPE_MAP = {
string: 'string',
number: 'number',
boolean: 'boolean',
undefined: 'undefined',
float: 'number',
text: 'string',
currency: 'string',
integer: 'number',
reference: 'string',
datetime: 'string',
date: 'string',
email: 'string',
phone: 'string',
url: 'string',
};

module.exports = {
ABORTABLE_CODES,
RETRYABLE_CODES,
Expand All @@ -33,4 +50,5 @@ module.exports = {
FETCH_FAILURE_JOB_STATUS_ERR_MSG,
FETCH_WARNING_JOB_STATUS_ERR_MSG,
ACCESS_TOKEN_FETCH_ERR_MSG,
SCHEMA_DATA_TYPE_MAP,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
handlePollResponse,
handleFileUploadResponse,
getAccessToken,
checkEventStatusViaSchemaMatching,
} = require('./util');

const {
Expand Down Expand Up @@ -353,3 +354,187 @@ describe('getAccessToken', () => {
await expect(getAccessToken(config)).rejects.toThrow(TransformationError);
});
});

describe('checkEventStatusViaSchemaMatching', () => {
// The function correctly identifies fields with expected data types.
it('should correctly identify fields with expected data types', () => {
const event = {
input: [
{
message: {
email: 'value1',
id: 123,
isLead: true,
},
metadata: {
job_id: 'job1',
},
},
],
};
const fieldSchemaMapping = {
email: 'string',
id: 'integer',
isLead: 'boolean',
};

const result = checkEventStatusViaSchemaMatching(event, fieldSchemaMapping);

expect(result).toEqual({});
});

// The function correctly identifies fields with unexpected data types.
it('should correctly identify fields with unexpected data types', () => {
const event = {
input: [
{
message: {
email: 123,
city: '123',
islead: true,
},
metadata: {
job_id: 'job1',
},
},
],
};
const fieldSchemaMapping = {
email: 'string',
city: 'number',
islead: 'boolean',
};

const result = checkEventStatusViaSchemaMatching(event, fieldSchemaMapping);

expect(result).toEqual({
job1: 'invalid email',
});
});

// The function correctly handles events with multiple fields.
it('should correctly handle events with multiple fields', () => {
const event = {
input: [
{
message: {
id: 'value1',
testCustomFieldScore: 123,
isLead: true,
},
metadata: {
job_id: 'job1',
},
},
{
message: {
email: 'value2',
id: 456,
testCustomFieldScore: false,
},
metadata: {
job_id: 'job2',
},
},
],
};
const fieldSchemaMapping = {
email: 'string',
id: 'integer',
testCustomFieldScore: 'integer',
isLead: 'boolean',
};

const result = checkEventStatusViaSchemaMatching(event, fieldSchemaMapping);

expect(result).toEqual({
job1: 'invalid id',
job2: 'invalid testCustomFieldScore',
});
});

// The function correctly handles events with missing fields.
it('should have no effect with missing fields', () => {
const event = {
input: [
{
message: {
field1: 'value1',
field3: true,
},
metadata: {
job_id: 'job1',
},
},
],
};
const fieldSchemaMapping = {
field1: 'string',
field2: 'number',
field3: 'boolean',
};

const result = checkEventStatusViaSchemaMatching(event, fieldSchemaMapping);

expect(result).toEqual({});
});

// The function correctly handles events with additional fields. But this will not happen in our use case
it('should correctly handle events with additional fields', () => {
const event = {
input: [
{
message: {
email: 'value1',
id: 124,
isLead: true,
abc: 'value2',
},
metadata: {
job_id: 'job1',
},
},
],
};
const fieldSchemaMapping = {
email: 'string',
id: 'number',
isLead: 'boolean',
};

const result = checkEventStatusViaSchemaMatching(event, fieldSchemaMapping);

expect(result).toEqual({
job1: 'invalid abc',
});
});

// The function correctly handles events with null values.
it('should correctly handle events with null values', () => {
const event = {
input: [
{
message: {
email: 'value1',
id: null,
isLead: true,
},
metadata: {
job_id: 'job1',
},
},
],
};
const fieldSchemaMapping = {
email: 'string',
id: 'number',
isLead: 'boolean',
};

const result = checkEventStatusViaSchemaMatching(event, fieldSchemaMapping);

expect(result).toEqual({
job1: 'invalid id',
});
});
});
3 changes: 2 additions & 1 deletion src/v0/destinations/marketo_bulk_upload/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
POLL_STATUS_ERR_MSG,
FILE_UPLOAD_ERR_MSG,
ACCESS_TOKEN_FETCH_ERR_MSG,
SCHEMA_DATA_TYPE_MAP,
} = require('./config');
const logger = require('../../../logger');

Expand Down Expand Up @@ -401,7 +402,7 @@ const checkEventStatusViaSchemaMatching = (event, fieldMap) => {
const { job_id } = metadata;

Object.entries(message).forEach(([paramName, paramValue]) => {
let expectedDataType = fieldMap[paramName];
let expectedDataType = SCHEMA_DATA_TYPE_MAP[fieldMap[paramName]];
const actualDataType = typeof paramValue;

// If expectedDataType is not one of the primitive data types, treat it as a string
Expand Down

0 comments on commit e979e4e

Please sign in to comment.