-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
163 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const moment = require('moment'); | ||
const { InstrumentationError } = require('@rudderstack/workflow-engine'); | ||
const { verifyAdInteractionTime } = require('./utils'); | ||
|
||
describe('verifyAdInteractionTime', () => { | ||
it('should pass when adInteractionTime is 2 years in the past (UNIX timestamp)', () => { | ||
// 2 years ago from now | ||
const adInteractionTime = moment().subtract(2, 'years').unix(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).not.toThrow(); | ||
}); | ||
|
||
it('should pass when adInteractionTime is 10 months in the future (UNIX timestamp)', () => { | ||
// 10 months in the future from now | ||
const adInteractionTime = moment().add(10, 'months').unix(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).not.toThrow(); | ||
}); | ||
|
||
it('should fail when adInteractionTime is 4 years in the past (UNIX timestamp)', () => { | ||
// 4 years ago from now | ||
const adInteractionTime = moment().subtract(4, 'years').unix(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).toThrow( | ||
'ad_interaction_time must be within one year in the future and three years in the past.', | ||
); | ||
}); | ||
|
||
it('should fail when adInteractionTime is 2 years in the future (UNIX timestamp)', () => { | ||
// 2 years in the future from now | ||
const adInteractionTime = moment().add(2, 'years').unix(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).toThrow( | ||
'ad_interaction_time must be within one year in the future and three years in the past.', | ||
); | ||
}); | ||
|
||
it('should pass when adInteractionTime is exactly 3 years in the past (UTC date string)', () => { | ||
// Exactly 3 years ago from now | ||
const adInteractionTime = moment.utc().subtract(3, 'years').toISOString(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).not.toThrow(); | ||
}); | ||
|
||
it('should pass when adInteractionTime is exactly 1 year in the future (UTC date string)', () => { | ||
// Exactly 1 year in the future from now | ||
const adInteractionTime = moment.utc().add(1, 'year').toISOString(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).not.toThrow(); | ||
}); | ||
|
||
it('should fail when adInteractionTime is 4 years in the past (UTC date string)', () => { | ||
// 4 years ago from now | ||
const adInteractionTime = moment.utc().subtract(4, 'years').toISOString(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).toThrow( | ||
'ad_interaction_time must be within one year in the future and three years in the past.', | ||
); | ||
}); | ||
|
||
it('should fail when adInteractionTime is 2 years in the future (UTC date string)', () => { | ||
// 2 years in the future from now | ||
const adInteractionTime = moment.utc().add(2, 'years').toISOString(); | ||
expect(() => verifyAdInteractionTime(adInteractionTime)).toThrow( | ||
'ad_interaction_time must be within one year in the future and three years in the past.', | ||
); | ||
}); | ||
|
||
it('should not throw an error if adInteractionTime is null or undefined', () => { | ||
expect(() => verifyAdInteractionTime(null)).not.toThrow(); | ||
expect(() => verifyAdInteractionTime(undefined)).not.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import { trackTestData } from './track'; | ||
import { validationFailures } from './validation'; | ||
|
||
export const data = [...trackTestData, ...validationFailures]; | ||
export const mockFns = (_) => { | ||
// @ts-ignore | ||
jest.useFakeTimers().setSystemTime(new Date('2024-02-01')); | ||
}; | ||
|
||
export const data = [...trackTestData, ...validationFailures].map((d) => ({ ...d, mockFns })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const moment = require('moment'); | ||
import { verifyAdInteractionTime } from '../../../../../src/cdk/v2/destinations/smartly/utils'; | ||
import { destination } from '../commonConfig'; | ||
|
||
export const trackTestData = [ | ||
|
@@ -13,11 +15,11 @@ export const trackTestData = [ | |
{ | ||
destination, | ||
message: { | ||
event: 'Add to cart', | ||
event_name: 'Add to cart', | ||
properties: { | ||
platform: 'meta', | ||
ad_unit_id: 228287, | ||
ad_interaction_time: '1650626278', | ||
ad_unit_id: '228287', | ||
ad_interaction_time: '1612137600', | ||
email: '[email protected]', | ||
}, | ||
type: 'track', | ||
|
@@ -44,16 +46,16 @@ export const trackTestData = [ | |
version: '1', | ||
type: 'REST', | ||
method: 'POST', | ||
endpoint: 'https://s2s.smartly.io/events', | ||
endpoint: 'https://s2s.smartly.io/events/batch', | ||
headers: {}, | ||
params: {}, | ||
body: { | ||
JSON: { | ||
platform: 'meta', | ||
ad_unit_id: 228287, | ||
ad_interaction_time: '1650626278', | ||
ad_unit_id: '228287', | ||
ad_interaction_time: '1612137600', | ||
conversions: '1', | ||
event: 'Add to cart', | ||
event_name: 'Add to cart', | ||
}, | ||
JSON_ARRAY: {}, | ||
XML: {}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.