From 10fe75278ea46570c15ee3f1d47b83a96687f9cd Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Mon, 22 Jul 2024 17:39:20 +0330 Subject: [PATCH 1/4] Change date schema to be compatible with ortto schema --- src/services/notificationService.test.ts | 2 +- src/services/notificationService.ts | 9 ++++++++- src/types/notifications.ts | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/services/notificationService.test.ts b/src/services/notificationService.test.ts index 9f5a5ce..72b1c67 100644 --- a/src/services/notificationService.test.ts +++ b/src/services/notificationService.test.ts @@ -20,7 +20,7 @@ describe('activityCreator', () => { expect(JSON.stringify(result)).equal(JSON.stringify({ activities: [ { - activity_id: "act:cm:notify-reward-amount", + activity_id: "act:cm:notify-reward", attributes: { 'int:cm:round': payload.round, 'str:cm:date': payload.date, diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 09d0bf1..293fd37 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -15,6 +15,7 @@ import { NOTIFICATION_CATEGORY } from '../types/general'; export const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES) : any=> { let attributes; + let date; switch (orttoEventName) { case NOTIFICATIONS_EVENT_NAMES.SUBSCRIBE_ONBOARDING: attributes = { @@ -170,9 +171,15 @@ export const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVEN } break case NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT: + date = new Date(Number(payload.date)); attributes = { + "dtz:cm:date": { + "year": date.getUTCFullYear(), + "month": date.getUTCMonth() + 1, // JavaScript's months are zero-indexed + "day": date.getUTCDate(), + "timezone": "UTC" + }, "int:cm:round": payload.round, - "str:cm:date": payload.date, "str:cm:amount": payload.amount, "str:cm:contractaddress": payload.contractAddress, "str:cm:farm": payload.farm, diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 4247a02..cfb40ce 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -71,6 +71,6 @@ export const ORTTO_EVENT_NAMES = { [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING]: 'second-update-warning', [NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile', [NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION]: 'verification-form-email-verification', - [NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward-amount', + [NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward', [NOTIFICATIONS_EVENT_NAMES.SUBSCRIBE_ONBOARDING]: 'onboarding-form', } \ No newline at end of file From fe1c9f9819d3c9a25c29005b5b86964388440254 Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Mon, 22 Jul 2024 20:54:02 +0330 Subject: [PATCH 2/4] Fix unit test based on changes --- src/services/notificationService.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/notificationService.test.ts b/src/services/notificationService.test.ts index 72b1c67..39ed763 100644 --- a/src/services/notificationService.test.ts +++ b/src/services/notificationService.test.ts @@ -6,7 +6,7 @@ describe('activityCreator', () => { it('should create attributes for NOTIFY_REWARD_AMOUNT', () => { const payload = { round: 1, - date: '2024-06-01', + date: '1721668910580', amount: '1000', contractAddress: '0x123', farm: 'Test Farm', @@ -22,8 +22,13 @@ describe('activityCreator', () => { { activity_id: "act:cm:notify-reward", attributes: { + 'dtz:cm:date': { + 'year':2024, + 'month':7, + 'day':22, + 'timezone':"UTC", + }, 'int:cm:round': payload.round, - 'str:cm:date': payload.date, 'str:cm:amount': payload.amount, 'str:cm:contractaddress': payload.contractAddress, 'str:cm:farm': payload.farm, From 90528ac1858f98333bd8ac941b27f6c0b5faa9de Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Mon, 22 Jul 2024 21:07:17 +0330 Subject: [PATCH 3/4] Fix lint errors --- src/services/notificationService.test.ts | 15 +++++++++------ src/services/notificationService.ts | 8 ++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/services/notificationService.test.ts b/src/services/notificationService.test.ts index c388f72..13a3c85 100644 --- a/src/services/notificationService.test.ts +++ b/src/services/notificationService.test.ts @@ -16,18 +16,21 @@ describe('activityCreator', () => { transactionHash: '0xabc', email: 'test@example.com', }; - const result = activityCreator(payload, NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT); + const result = activityCreator( + payload, + NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT, + ); expect(JSON.stringify(result)).equal( JSON.stringify({ activities: [ { - activity_id: "act:cm:notify-reward", + activity_id: 'act:cm:notify-reward', attributes: { 'dtz:cm:date': { - 'year':2024, - 'month':7, - 'day':22, - 'timezone':"UTC", + year:2024, + month:7, + day:22, + timezone:'UTC', }, 'int:cm:round': payload.round, 'str:cm:amount': payload.amount, diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 9ff4c21..1667f92 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -183,10 +183,10 @@ export const activityCreator = ( date = new Date(Number(payload.date)); attributes = { 'dtz:cm:date': { - 'year': date.getUTCFullYear(), - 'month': date.getUTCMonth() + 1, // JavaScript's months are zero-indexed - 'day': date.getUTCDate(), - 'timezone': "UTC", + year: date.getUTCFullYear(), + month: date.getUTCMonth() + 1, // JavaScript's months are zero-indexed + day: date.getUTCDate(), + timezone: 'UTC', }, 'int:cm:round': payload.round, 'str:cm:amount': payload.amount, From 5eab9ebdec5a6cce1689141d1f3f35c829877c7c Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Mon, 22 Jul 2024 21:10:58 +0330 Subject: [PATCH 4/4] Fix lint errors --- src/services/notificationService.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/notificationService.test.ts b/src/services/notificationService.test.ts index 13a3c85..01c0f75 100644 --- a/src/services/notificationService.test.ts +++ b/src/services/notificationService.test.ts @@ -27,10 +27,10 @@ describe('activityCreator', () => { activity_id: 'act:cm:notify-reward', attributes: { 'dtz:cm:date': { - year:2024, - month:7, - day:22, - timezone:'UTC', + year: 2024, + month: 7, + day: 22, + timezone: 'UTC', }, 'int:cm:round': payload.round, 'str:cm:amount': payload.amount,