-
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.
refactor: migrate ga, ga360, gcs_datalake, google adwords destination…
…s to component tests (#2675)
- Loading branch information
Showing
53 changed files
with
42,366 additions
and
36,982 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/v0/destinations/google_adwords_offline_conversions/helper.js
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,9 @@ | ||
const moment = require('moment-timezone'); | ||
|
||
module.exports = { | ||
formatTimestamp: (timestamp) => { | ||
const tsMomentInstance = moment(timestamp); | ||
const offsetFromUtc = tsMomentInstance.utcOffset(); | ||
return tsMomentInstance.utcOffset(offsetFromUtc).format('YYYY-MM-DD HH:mm:ssZ'); | ||
}, | ||
}; |
31 changes: 31 additions & 0 deletions
31
src/v0/destinations/google_adwords_offline_conversions/helper.test.js
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,31 @@ | ||
const moment = require('moment-timezone'); | ||
const { formatTimestamp } = require('./helper'); | ||
|
||
describe('google adwords offline conversions - helper', () => { | ||
it('should correctly format to IST', () => { | ||
moment.tz.setDefault('Asia/Calcutta'); | ||
expect(formatTimestamp('2019-10-14 11:15:18.299Z')).toEqual('2019-10-14 16:45:18+05:30'); | ||
}); | ||
it('should correctly format to UTC', () => { | ||
moment.tz.setDefault('UTC'); | ||
expect(formatTimestamp('2019-10-14 11:15:18.299Z')).toEqual('2019-10-14 11:15:18+00:00'); | ||
}); | ||
it('should return "Invalid date" when a string not in date-format is sent as argument', () => { | ||
expect(formatTimestamp('abc')).toEqual('Invalid date'); | ||
}); | ||
it('should return offset value correctly when number is passed', () => { | ||
moment.tz.setDefault('Asia/Tokyo'); | ||
expect(formatTimestamp(11245)).toEqual('1970-01-01 09:00:11+09:00'); | ||
}); | ||
it('should return current date when a value not string is sent as argument', () => { | ||
moment.tz.setDefault('UTC'); | ||
const spy = jest.spyOn(Date, 'now').mockReturnValue('2023-10-22 12:51:30+00:00'); | ||
expect(formatTimestamp([])).toEqual('2023-10-22 12:51:30+00:00'); | ||
expect(formatTimestamp({})).toEqual('2023-10-22 12:51:30+00:00'); | ||
expect(formatTimestamp(undefined)).toEqual('2023-10-22 12:51:30+00:00'); | ||
spy.mockClear(); | ||
}); | ||
it('should return "Invalid date" when null value is passed as argument', () => { | ||
expect(formatTimestamp(null)).toEqual('Invalid date'); | ||
}); | ||
}); |
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
Oops, something went wrong.