Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding map for marketo known values and javascript known values #3037

Merged
merged 7 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
shrouti1507 marked this conversation as resolved.
Show resolved Hide resolved
"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', () => {
shrouti1507 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading