Skip to content

Commit

Permalink
chore: function updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aanshi07 committed Dec 9, 2024
1 parent 3f7f782 commit ae18c9a
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/v0/destinations/topsort/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const {
} = require('./utils');

// Function to process events with a product array
const processProductArray = (
const processProductArray = ({
products,
basePayload,
placementPayload,
topsortEvent,
apiKey,
finalPayloads,
) => {
}) => {
const itemPayloads = constructItemPayloads(products, mappingConfig[ConfigCategory.ITEM.name]);
itemPayloads.forEach((itemPayload) => {
const eventData = createEventData(basePayload, placementPayload, itemPayload, topsortEvent);
Expand All @@ -30,15 +30,15 @@ const processProductArray = (
};

// Function to process events with a single product or no product data
const processSingleProduct = (
const processSingleProduct = ({
basePayload,
placementPayload,
message,
topsortEvent,
apiKey,
finalPayloads,
messageId,
) => {
}) => {
const itemPayload = constructPayload(message, mappingConfig[ConfigCategory.ITEM.name]);
const eventData = createEventData(basePayload, placementPayload, itemPayload, topsortEvent);

Check warning on line 43 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L41-L43

Added lines #L41 - L43 were not covered by tests

Expand All @@ -61,37 +61,40 @@ const responseBuilder = (message, { Config }) => {
throw new InstrumentationError("Event not mapped in 'topsortEvents'. Dropping the event.");

Check warning on line 61 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L61

Added line #L61 was not covered by tests
}

const topsortEvent = mappedEventName;
const topsortEventName = mappedEventName;

// Construct base and placement payloads
const basePayload = constructPayload(message, mappingConfig[ConfigCategory.TRACK.name]);
const placementPayload = constructPayload(message, mappingConfig[ConfigCategory.PLACEMENT.name]);

Check warning on line 68 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L68

Added line #L68 was not covered by tests

// Destructure products from properties (if available)
const { products, messageId } = properties;

Check warning on line 71 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L71

Added line #L71 was not covered by tests

// Check if the event involves a product array (using ECOMM_EVENTS_WITH_PRODUCT_ARRAY)
const isProductArrayAvailable =
ECOMM_EVENTS_WITH_PRODUCT_ARRAY.includes(event) && isProductArrayValid(event, properties);

const finalPayloads = [];

Check warning on line 77 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L77

Added line #L77 was not covered by tests

// Handle events based on the presence of a product array
const commonArgs = {

Check warning on line 79 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L79

Added line #L79 was not covered by tests
basePayload,
placementPayload,
topsortEventName,
apiKey,
finalPayloads,
};

if (isProductArrayAvailable) {
processProductArray(
properties.products,
basePayload,
placementPayload,
topsortEvent,
apiKey,
finalPayloads,
);
processProductArray({

Check warning on line 88 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L88

Added line #L88 was not covered by tests
...commonArgs,
products, // Directly use destructured products
});
} else {
processSingleProduct(
basePayload,
placementPayload,
processSingleProduct({

Check warning on line 93 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L92-L93

Added lines #L92 - L93 were not covered by tests
...commonArgs,
message,
topsortEvent,
apiKey,
finalPayloads,
);
messageId, // Add 'messageId' for single product event
});
}

return finalPayloads;

Check warning on line 100 in src/v0/destinations/topsort/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/topsort/transform.js#L100

Added line #L100 was not covered by tests
Expand Down

0 comments on commit ae18c9a

Please sign in to comment.