diff --git a/migrations/1720553769343-changeMicroserviceAndCategoryOfNotifyRewardNotificationType.ts b/migrations/1720553769343-changeMicroserviceAndCategoryOfNotifyRewardNotificationType.ts index d83a425..4f1a1f9 100644 --- a/migrations/1720553769343-changeMicroserviceAndCategoryOfNotifyRewardNotificationType.ts +++ b/migrations/1720553769343-changeMicroserviceAndCategoryOfNotifyRewardNotificationType.ts @@ -1,23 +1,25 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; +import { MigrationInterface, QueryRunner } from 'typeorm'; import { MICRO_SERVICES } from '../src/utils/utils'; import { NOTIFICATION_CATEGORY } from '../src/types/general'; -export class changeMicroserviceAndCategoryOfNotifyRewardNotificationType1720553769343 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` +export class changeMicroserviceAndCategoryOfNotifyRewardNotificationType1720553769343 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` UPDATE notification_type SET "microService" = '${MICRO_SERVICES.notifyReward}', category = '${NOTIFICATION_CATEGORY.ORTTO}' WHERE name = 'Notify reward amount'; `); - } + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` UPDATE notification_type SET "microService" = '${MICRO_SERVICES.givethio}', categoty = '${NOTIFICATION_CATEGORY.GENERAL}' WHERE name = 'Notify reward amount'; `); - } + } } diff --git a/migrations/1720828190666-seedThirdPartyForNotifyReward.ts b/migrations/1720828190666-seedThirdPartyForNotifyReward.ts index 14b8d51..21df824 100644 --- a/migrations/1720828190666-seedThirdPartyForNotifyReward.ts +++ b/migrations/1720828190666-seedThirdPartyForNotifyReward.ts @@ -1,27 +1,28 @@ -import { MigrationInterface, QueryRunner } from "typeorm" +import { MigrationInterface, QueryRunner } from 'typeorm'; -export class seedThirdPartyForNotifyReward1720828190666 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - if ( - process.env.NODE_ENV === 'test' || - process.env.NODE_ENV === 'development' - ) { - // Create third part record for notifyreward in development and test ENVs - await queryRunner.query(` +export class seedThirdPartyForNotifyReward1720828190666 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + if ( + process.env.NODE_ENV === 'test' || + process.env.NODE_ENV === 'development' + ) { + // Create third part record for notifyreward in development and test ENVs + await queryRunner.query(` INSERT INTO third_party( "microService", secret, "isActive") VALUES ('notifyreward', 'secret', true) ; `); - } } + } - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` DELETE FROM third_party WHERE "microService" = 'notifyreward'; `); - } - + } } diff --git a/package.json b/package.json index 3c6ffaf..e601dcd 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,10 @@ "keywords": [], "author": "", "license": "ISC", + "packageManager": "yarn@1.22.22", "husky": { "hooks": { - "pre-commit": "npm run lint" + "pre-commit": "npm run lint:fix" } }, "dependencies": { diff --git a/src/routes/v1/notificationRouter.test.ts b/src/routes/v1/notificationRouter.test.ts index 8d5e6b9..713d0ba 100644 --- a/src/routes/v1/notificationRouter.test.ts +++ b/src/routes/v1/notificationRouter.test.ts @@ -2096,24 +2096,24 @@ function sendNotificationTestCases() { it('should create *Notify reward amount* notification, success', async () => { const data = { - eventName: "Notify reward amount", + eventName: 'Notify reward amount', sendEmail: true, sendSegment: true, creationTime: 1667992708000, - email: "aliebrahimi2079@gmail.com", + email: 'aliebrahimi2079@gmail.com', segment: { payload: { round: 10, - date: "1667992708000", - amount: "12134", - contractAddress: "0xsfglsjfdflk", - farm: "test farm", - message: "test message", - network: "ethereum", - script: "test script", - transactionHash: "test txhash" - } - } + date: '1667992708000', + amount: '12134', + contractAddress: '0xsfglsjfdflk', + farm: 'test farm', + message: 'test message', + network: 'ethereum', + script: 'test script', + transactionHash: 'test txhash', + }, + }, }; const result = await axios.post(sendNotificationUrl, data, { @@ -2129,25 +2129,25 @@ function sendNotificationTestCases() { it('should create *Notify reward amount* notification, failed invalid payload', async () => { try { const data = { - eventName: "Notify reward amount", + eventName: 'Notify reward amount', sendEmail: true, sendSegment: true, creationTime: 1667992708000, - email: "aliebrahimi2079@gmail.com", + email: 'aliebrahimi2079@gmail.com', segment: { payload: { round: 10, - date: "1667992708000", - amount: "12134", - contractAddress: "0xsfglsjfdflk", - farm: "test farm", - message: "test message", - network: "ethereum", - script: "test script", - transactionHash: "test txhash", - invalidField: "invalid data" - } - } + date: '1667992708000', + amount: '12134', + contractAddress: '0xsfglsjfdflk', + farm: 'test farm', + message: 'test message', + network: 'ethereum', + script: 'test script', + transactionHash: 'test txhash', + invalidField: 'invalid data', + }, + }, }; await axios.post(sendNotificationUrl, data, { headers: { @@ -2161,7 +2161,10 @@ function sendNotificationTestCases() { e.response.data.message, errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, ); - assert.equal(e.response.data.description, '"segment.payload.invalidField" is not allowed'); + assert.equal( + e.response.data.description, + '"segment.payload.invalidField" is not allowed', + ); } }); } diff --git a/src/services/notificationService.test.ts b/src/services/notificationService.test.ts index 9f5a5ce..6423232 100644 --- a/src/services/notificationService.test.ts +++ b/src/services/notificationService.test.ts @@ -1,6 +1,6 @@ +import { expect } from 'chai'; import { activityCreator } from './notificationService'; import { NOTIFICATIONS_EVENT_NAMES } from '../types/notifications'; -import { expect } from 'chai'; describe('activityCreator', () => { it('should create attributes for NOTIFY_REWARD_AMOUNT', () => { @@ -14,30 +14,35 @@ describe('activityCreator', () => { network: 'Test Network', script: 'Test Script', transactionHash: '0xabc', - email: 'test@example.com' + email: 'test@example.com', }; - const result = activityCreator(payload, NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT); - expect(JSON.stringify(result)).equal(JSON.stringify({ - activities: [ - { - activity_id: "act:cm:notify-reward-amount", - attributes: { - '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, - 'str:cm:message': payload.message, - 'str:cm:network': payload.network, - 'str:cm:script': payload.script, - 'str:cm:transactionhash': payload.transactionHash, - }, - fields: { - 'str::email': payload.email, + const result = activityCreator( + payload, + NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT, + ); + expect(JSON.stringify(result)).equal( + JSON.stringify({ + activities: [ + { + activity_id: 'act:cm:notify-reward-amount', + attributes: { + '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, + 'str:cm:message': payload.message, + 'str:cm:network': payload.network, + 'str:cm:script': payload.script, + 'str:cm:transactionhash': payload.transactionHash, + }, + fields: { + 'str::email': payload.email, + }, }, - }, - ], - merge_by: ['str::email'], - })); - }) + ], + merge_by: ['str::email'], + }), + ); + }); }); diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 8541003..9e3ae44 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -19,13 +19,16 @@ import { import { getEmailAdapter } from '../adapters/adapterFactory'; import { NOTIFICATION_CATEGORY } from '../types/general'; -export const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES) : any=> { +export const activityCreator = ( + payload: any, + orttoEventName: NOTIFICATIONS_EVENT_NAMES, +): any => { let attributes; switch (orttoEventName) { case NOTIFICATIONS_EVENT_NAMES.SUBSCRIBE_ONBOARDING: attributes = { - "str:cm:email": payload.email, - } + 'str:cm:email': payload.email, + }; break; case NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION: attributes = { diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 08d1902..0432a08 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -77,7 +77,8 @@ 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.SEND_EMAIL_CONFIRMATION]: + 'verification-form-email-verification', [NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward-amount', [NOTIFICATIONS_EVENT_NAMES.SUBSCRIBE_ONBOARDING]: 'onboarding-form', -} \ No newline at end of file +};