Skip to content

Commit

Permalink
fix: review comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jan 29, 2024
1 parent 1c4074f commit 52bb977
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/v0/destinations/marketo_bulk_upload/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const SCHEMA_DATA_TYPE_MAP = {
email: 'string',
phone: 'string',
url: 'string',
object: 'object',
};

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ describe('getAccessToken', () => {

describe('checkEventStatusViaSchemaMatching', () => {
// The function correctly identifies fields with expected data types.
it('should correctly identify fields with expected data types', () => {
it('if event data types match with expected data types we send no field as mismatch', () => {
const event = {
input: [
{
Expand All @@ -384,7 +384,7 @@ describe('checkEventStatusViaSchemaMatching', () => {
});

// The function correctly identifies fields with unexpected data types.
it('should correctly identify fields with unexpected data types', () => {
it('if event data types do not match with expected data types we send that field as mismatch', () => {
const event = {
input: [
{
Expand Down Expand Up @@ -413,7 +413,7 @@ describe('checkEventStatusViaSchemaMatching', () => {
});

// The function correctly handles events with multiple fields.
it('should correctly handle events with multiple fields', () => {
it('For array of events the mismatch object fills up with each event errors', () => {
const event = {
input: [
{
Expand Down Expand Up @@ -454,7 +454,7 @@ describe('checkEventStatusViaSchemaMatching', () => {
});

// The function correctly handles events with missing fields.
it('should have no effect with missing fields', () => {
it('it is not mandatory to send all the fields present in schema', () => {
const event = {
input: [
{
Expand All @@ -480,7 +480,7 @@ describe('checkEventStatusViaSchemaMatching', () => {
});

// 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', () => {
it('for any field beyond schema fields will be mapped as invalid', () => {
const event = {
input: [
{
Expand Down
7 changes: 1 addition & 6 deletions src/v0/destinations/marketo_bulk_upload/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,9 @@ const checkEventStatusViaSchemaMatching = (event, fieldMap) => {
const { job_id } = metadata;

Object.entries(message).forEach(([paramName, paramValue]) => {
let expectedDataType = SCHEMA_DATA_TYPE_MAP[fieldMap[paramName]];
const 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
if (!['string', 'number', 'boolean', 'undefined'].includes(expectedDataType)) {
expectedDataType = 'string';
}

if (!mismatchedFields[job_id] && actualDataType !== expectedDataType) {
mismatchedFields[job_id] = `invalid ${paramName}`;
}
Expand Down

0 comments on commit 52bb977

Please sign in to comment.