Skip to content

Commit

Permalink
chore: refactor and restructure test and transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Nov 6, 2024
1 parent 994b5ba commit d31a90f
Show file tree
Hide file tree
Showing 12 changed files with 3,478 additions and 6,318 deletions.
4 changes: 2 additions & 2 deletions src/v1/sources/shopify/transform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
const { processEventFromPixel } = require('./pixelTransform');
const { processEventFromPixel } = require('./webpixelTransformations/pixelTransform');
const { process: processWebhookEvents } = require('../../../v0/sources/shopify/transform');
const { process: processWebhookEventsV2 } = require('./serverSideTransform');
const { process: processWebhookEventsV2 } = require('./webhookTransformations/serverSideTransform');

const process = async (inputEvent) => {
const { event } = inputEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const lodash = require('lodash');
const get = require('get-value');
// const { RedisError } = require('@rudderstack/integrations-lib');
const stats = require('../../../util/stats');
const stats = require('../../../../util/stats');
const {
getShopifyTopic,
// createPropertiesForEcomEvent,
Expand All @@ -11,12 +11,12 @@ const {
checkAndUpdateCartItems,
// getHashLineItems,
getDataFromRedis,
} = require('../../../v0/sources/shopify/util');
} = require('../../../../v0/sources/shopify/util');
// const logger = require('../../../logger');
const { removeUndefinedAndNullValues, isDefinedAndNotNull } = require('../../../v0/util');
const { removeUndefinedAndNullValues, isDefinedAndNotNull } = require('../../../../v0/util');
// const { RedisDB } = require('../../../util/redis/redisConnector');
const Message = require('../../../v0/sources/message');
const { EventType } = require('../../../constants');
const Message = require('../../../../v0/sources/message');
const { EventType } = require('../../../../constants');
const {
INTEGERATION,
MAPPING_CATEGORIES,
Expand All @@ -27,7 +27,7 @@ const {
SHOPIFY_TRACK_MAP,
useRedisDatabase,
lineItemsMappingJSON,
} = require('../../../v0/sources/shopify/config');
} = require('../../../../v0/sources/shopify/config');
const { createPropertiesForV2EcomEvent, getProductsFromLineItems } = require('./serverSideUtlis');

const NO_OPERATION_SUCCESS = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
const {
constructPayload,
// extractCustomFields,
// flattenJson,
// generateUUID,
// isDefinedAndNotNull,
} = require('../../../v0/util');
const { constructPayload } = require('../../../../v0/util');

const {
lineItemsMappingJSON,
productMappingJSON,
// LINE_ITEM_EXCLUSION_FIELDS,
// PRODUCT_MAPPING_EXCLUSION_FIELDS,
// SHOPIFY_TRACK_MAP,
// SHOPIFY_ADMIN_ONLY_EVENTS,
// useRedisDatabase,
// maxTimeToIdentifyRSGeneratedCall,
} = require('../../../v0/sources/shopify/config');
} = require('../../../../v0/sources/shopify/config');

const getProductsFromLineItems = (lineItems, mapping) => {
if (!lineItems || lineItems.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
const _ = require('lodash');
const { isDefinedNotNullNotEmpty } = require('@rudderstack/integrations-lib');
const stats = require('../../../util/stats');
const logger = require('../../../logger');
const { removeUndefinedAndNullValues } = require('../../../v0/util');
const { RedisDB } = require('../../../util/redis/redisConnector');
const stats = require('../../../../util/stats');
const logger = require('../../../../logger');
const { removeUndefinedAndNullValues } = require('../../../../v0/util');
const { RedisDB } = require('../../../../util/redis/redisConnector');
const {
pageViewedEventBuilder,
cartViewedEventBuilder,
Expand All @@ -20,7 +20,7 @@ const {
INTEGERATION,
PIXEL_EVENT_TOPICS,
pixelEventToCartTokenLocationMapping,
} = require('./config');
} = require('../config');

const NO_OPERATION_SUCCESS = {
outputToSource: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const { extractCartToken, handleCartTokenRedisOperations } = require('./pixelTransform');
const { RedisDB } = require('../../../util/redis/redisConnector');
const stats = require('../../../util/stats');
const logger = require('../../../logger');
const { pixelEventToCartTokenLocationMapping } = require('./config');
const { RedisDB } = require('../../../../util/redis/redisConnector');
const stats = require('../../../../util/stats');
const logger = require('../../../../logger');
const { pixelEventToCartTokenLocationMapping } = require('../config');

jest.mock('../../../util/redis/redisConnector', () => ({
jest.mock('../../../../util/redis/redisConnector', () => ({
RedisDB: {
setVal: jest.fn(),
},
}));

jest.mock('../../../util/stats', () => ({
jest.mock('../../../../util/stats', () => ({
increment: jest.fn(),
}));

jest.mock('../../../logger', () => ({
jest.mock('../../../../logger', () => ({
info: jest.fn(),
error: jest.fn(),
}));

jest.mock('./config', () => ({
jest.mock('../config', () => ({
pixelEventToCartTokenLocationMapping: { cart_viewed: 'properties.cart_id' },
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */
const Message = require('../../../v0/sources/message');
const { EventType } = require('../../../constants');
const Message = require('../../../../v0/sources/message');
const { EventType } = require('../../../../constants');
const {
INTEGERATION,
PIXEL_EVENT_MAPPING,
Expand All @@ -10,7 +10,7 @@ const {
productViewedEventMappingJSON,
productToCartEventMappingJSON,
checkoutStartedCompletedEventMappingJSON,
} = require('./config');
} = require('../config');

function getNestedValue(object, path) {
const keys = path.split('.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const {
checkoutStepEventBuilder,
searchEventBuilder,
} = require('./pixelUtils');
const { EventType } = require('../../../constants');
const Message = require('../../../v0/sources/message');
const Message = require('../../../../v0/sources/message');
jest.mock('ioredis', () => require('../../../../test/__mocks__/redis'));
jest.mock('../../../v0/sources/message');
jest.mock('../../../../v0/sources/message');

describe('utilV2.js', () => {
beforeEach(() => {
Expand Down
Loading

0 comments on commit d31a90f

Please sign in to comment.