diff --git a/config/test.env b/config/test.env index d320fdb..3ba439c 100644 --- a/config/test.env +++ b/config/test.env @@ -17,3 +17,6 @@ SEGMENT_API_KEY=FAKE_API_KEY JWT_AUTHORIZATION_ADAPTER=mock HOSTNAME_WHITELIST=next.giveth.io,www.next.giveth.io,staging.giveth.io,www.staging.giveth.io,localhost,giveth.io,vercel.app,www.giveth.io + +GIVETH_IO_THIRD_PARTY_SECRET=secret +GIVETH_IO_THIRD_PARTY_MICRO_SERVICE=givethio diff --git a/migrations/1660716115917-seedNotificationType.ts b/migrations/1660716115917-seedNotificationType.ts index e6743aa..b103d0c 100644 --- a/migrations/1660716115917-seedNotificationType.ts +++ b/migrations/1660716115917-seedNotificationType.ts @@ -4,7 +4,10 @@ import { SCHEMA_VALIDATORS_NAMES, } from '../src/entities/notificationType'; import { MICRO_SERVICES, THIRD_PARTY_EMAIL_SERVICES } from '../src/utils/utils'; +import { SegmentEvents } from '../src/services/segment/analytics'; +import { NOTIFICATION_CATEGORY } from '../src/types/general'; +// https://github.com/Giveth/notification-center/issues/6 , https://gist.github.com/MohammadPCh/24434d50bc9ccd9b74905c271ee05482 export const GivethNotificationTypes = { EMAIL_NOTIFICATIONS: { name: 'Email notifications', @@ -40,11 +43,35 @@ export const GivethNotificationTypes = { emailNotifierService: null, emailNotificationId: null, // doesn't sent pushNotifierService: null, - title: 'Complete profile', - content: 'You need to complete your profile.', // Missing copy + title: 'You need to complete your profile.', + content: "Don't forget to complete your profile!", + htmlTemplate: [ + { + type: 'p', + content: "Don't forget to complete your profile!", + }, + ], + }, + WELCOME: { + name: 'Welcome', + description: "Welcome to Giveth! ❤️ So happy you're here.", + microService: MICRO_SERVICES.givethio, + category: 'general', + schemaValidator: null, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Welcome!', + htmlTemplate: [ + { + type: 'p', + content: "Welcome to Giveth! ❤️ So happy you're here.", + }, + ], + content: "Welcome to Giveth! ❤️ So happy you're here.", }, COMPLETE_PROFILE: { - name: 'Profile completed', + name: 'The profile has been completed', description: 'Thanks for completing your profile', microService: MICRO_SERVICES.givethio, category: 'general', @@ -53,146 +80,934 @@ export const GivethNotificationTypes = { emailNotificationId: null, pushNotifierService: null, title: 'Profile Completed', - content: 'The profile has been completed', // Missing copy + htmlTemplate: [ + { + type: 'p', + content: 'Done! Your profile is complete 🙂', + }, + ], + content: 'Done! Your profile is complete 🙂', + }, + ADMIN_MESSAGE: { + name: 'Admin message', + description: 'Admin message', + microService: MICRO_SERVICES.givethio, + category: 'general', + schemaValidator: SCHEMA_VALIDATORS_NAMES.ADMIN_MESSAGE, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Admin message', + htmlTemplate: [ + { + type: 'b', + content: '$content', + }, + { + type: 'p', + content: '$instruction', + }, + { + type: 'a', + content: '$linkTitle', + href: '$href', + }, + ], + Content: { + content: '', + instruction: '', + linkTitle: '', + href: '', + }, + }, + DRAFTED_PROJECT_SAVED: { + name: 'The project saved as draft', + description: 'The project saved as draft', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + microService: MICRO_SERVICES.givethio, + schemaValidator: SCHEMA_VALIDATORS_NAMES.DRAFTED_PROJECT_SAVED, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'The project saved as draft', + content: 'Hurray! Your {project name} project is live 🥳', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project draft was successfully saved.', + }, + ], }, DRAFTED_PROJECT_ACTIVATED: { name: 'Draft published', description: 'Project draft has been published', - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, microService: MICRO_SERVICES.givethio, schemaValidator: SCHEMA_VALIDATORS_NAMES.DRAFTED_PROJECT_ACTIVATED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Draft published', + emailNotificationId: SegmentEvents.DRAFTED_PROJECT_ACTIVATED, pushNotifierService: null, title: 'Project is published', - content: '', // Missing copy + content: 'Hurray! Your {project name} project is live 🥳', + htmlTemplate: [ + { + type: 'p', + content: 'Hurray! Your ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is live 🥳', + }, + ], }, PROJECT_LISTED: { name: 'Project listed', description: 'Project has been listed!', - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, microService: MICRO_SERVICES.givethio, schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_LISTED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project listed', + emailNotificationId: SegmentEvents.PROJECT_LISTED, pushNotifierService: null, title: 'Project is listed', - content: 'Well done your project has been published!', // Missing copy + htmlTemplate: [ + { + type: 'p', + content: 'Nice! Your ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is listed.', + }, + ], + content: 'Nice! Your {project name} project is listed.', }, PROJECT_UNLISTED: { name: 'Project unlisted', - description: 'Project has unlisted!', + description: 'Project has been unlisted!', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UNLISTED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project unlisted', + emailNotificationId: SegmentEvents.PROJECT_UNLISTED, pushNotifierService: null, - title: 'Project is unlisted - ', - content: '', // Missing copy + title: 'Project is unlisted', + htmlTemplate: [ + { + type: 'p', + content: 'Your ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is no longer visible.', + }, + ], + content: 'Your {project name} project is no longer visible.', }, - PROJECT_EDITED: { - name: 'Project edited', - description: 'Project has been edited', + PROJECT_UNLISTED_FOR_DONORS: { + name: 'Project unlisted - Donors', + description: 'Project has been unlisted!', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_EDITED, - emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project edited', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UNLISTED, + emailNotifierService: null, + emailNotificationId: null, pushNotifierService: null, - title: 'Project has been edited', - content: '', // Missing copy + title: 'Project is unlisted', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' that you donated before is no longer visible.', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: + 'The {project name} that you donated before is no longer visible.\n{reason}', }, - PROJECT_BADGE_REVOKED: { - name: 'Project badge revoked', - description: 'Project verified badge revoked', + PROJECT_UNLISTED_FOR_USERS_WHO_LIKED: { + name: 'Project unlisted - Users Who Liked', + description: 'Project has been unlisted!', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_BADGE_REVOKED, - emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project badge revoked', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UNLISTED, + emailNotifierService: null, + emailNotificationId: null, pushNotifierService: null, - title: 'Project verification revoked', - content: '', // Missing copy + title: 'Project is unlisted', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' that you liked is no longer visible.', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: + 'The {project name} that you donated before is no longer visible.\n{reason}', }, - PROJECT_VERIFIED: { - name: 'Project verified', - description: 'Project has been verified! Rejoice!', + PROJECT_CANCELLED: { + name: 'Project cancelled', + description: 'Project has been cancelled', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_VERIFIED, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_CANCELLED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project verified', + emailNotificationId: SegmentEvents.PROJECT_CANCELLED, pushNotifierService: null, - title: 'Project verification approved', - content: '', // Missing copy + title: 'Project is cancelled by admin', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project has been cancelled by admin action.', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: + 'The {project name} project has been cancelled by admin action.\n{reason}', }, - PROJECT_REJECTED: { - name: 'Project rejected', - description: 'Project has been rejected!', + PROJECT_CANCELLED_FOR_DONORS: { + name: 'Project cancelled - Donors', + description: 'Project has been cancelled', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_REJECTED, - emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project rejected', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_CANCELLED, + emailNotifierService: null, + emailNotificationId: null, pushNotifierService: null, - title: 'Project verification rejected', - content: '', // Missing copy + title: 'Project is cancelled by admin', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project that you donated before has been cancelled', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: + 'The {project name} project that you donated before has been cancelled.\n{reason}', }, - PROJECT_UNVERIFIED: { - name: 'Project unverified', - description: 'Project has been unverified', + PROJECT_CANCELLED_FOR_USERS_WHO_LIKED: { + name: 'Project cancelled - Users Who Liked', + description: 'Project has been cancelled', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UNVERIFIED, - emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project unverified', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_CANCELLED, + emailNotifierService: null, + emailNotificationId: null, pushNotifierService: null, - title: 'Project verification removed', - content: '', // Missing copy + title: 'Project is cancelled by admin', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project that you liked has been cancelled.', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: + 'The {project name} project that you liked has been cancelled.\n{reason}', }, + PROJECT_ACTIVATED: { name: 'Project activated', description: 'Project has been activated!', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_ACTIVATED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project activated', + emailNotificationId: SegmentEvents.PROJECT_ACTIVATED, pushNotifierService: null, - title: 'Project is activated - ', - content: '', // Missing copy + title: 'Project is activated', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is active now.', + }, + ], + content: 'The {project name} project is active now.', + }, + + PROJECT_ACTIVATED_FOR_DONORS: { + name: 'Project activated - Donors', + description: 'Project has been activated!', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_ACTIVATED, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Project is activated', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project that you donated before is active now.', + }, + ], + content: + 'The {project name} project that you donated before is active now.', }, + PROJECT_ACTIVATED_FOR_USERS_WHO_LIKED: { + name: 'Project activated - Users Who Liked', + description: 'Project has been activated!', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_ACTIVATED, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Project is activated', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project that you liked is active now.', + }, + ], + content: 'The {project name} project that you liked is active now.', + }, + PROJECT_DEACTIVATED: { name: 'Project deactivated', description: 'Project has been deactivated', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_DEACTIVATED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project deactivated', + emailNotificationId: SegmentEvents.PROJECT_DEACTIVATED, pushNotifierService: null, - title: 'Project is activated - ', - content: '', // Missing copy + title: 'Project is deactivated', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is de-actived.', + }, + ], + content: 'The {project name} project is de-actived.', }, - PROJECT_CANCELLED: { - name: 'Project cancelled', - description: 'Project has been cancelled', + PROJECT_DEACTIVATED_DONORS: { + name: 'Project deactivated - Donors', + description: 'Project has been deactivated', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_CANCELLED, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_DEACTIVATED, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Project is deactivated', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project that you donated before is de-actived.', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: + 'The {project name} project that you donated before is de-actived.\n{reason}', + }, + PROJECT_DEACTIVATED_USERS_WHO_LIKED: { + name: 'Project deactivated - Users Who Liked', + description: 'Project has been deactivated', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_DEACTIVATED, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Project is deactivated', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project that you liked is de-actived', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: + 'The {project name} project that you liked is de-actived.\n{reason}', + }, + PROJECT_VERIFIED: { + name: 'Project verified', + description: 'Project has been verified!', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_VERIFIED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project cancelled', + emailNotificationId: SegmentEvents.PROJECT_VERIFIED, pushNotifierService: null, - title: 'Project is cancelled - ', - content: '', // Missing copy + title: 'Project verified', + htmlTemplate: [ + { + type: 'p', + content: 'Well done! ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is officially verified! 🎉', + }, + ], + content: 'Well done! {project name} project is officially verified! 🎉', + }, + PROJECT_VERIFIED_DONORS: { + name: 'Project verified - Donors', + description: 'Project has been verified!', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_VERIFIED, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Project verified', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' that you donated before has received verified badge!', + }, + ], + content: + 'The {project name} that you donated before has received verified badge!', + }, + PROJECT_VERIFIED_USERS_WHO_LIKED: { + name: 'Project verified - Users Who Liked', + description: 'Project has been verified!', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_VERIFIED, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Project verified', + htmlTemplate: [ + { + type: 'p', + content: 'The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' that you liked has received verified badge!', + }, + ], + content: 'The {project name} that you liked has received verified badge!', + }, + VERIFICATION_FORM_SENT: { + name: 'Form sent (Under review)', + description: 'Form sent (Under review)', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.VERIFICATION_FORM_SENT, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Form sent (Under review)', + htmlTemplate: [ + { + type: 'p', + content: 'Hang tight! The ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is currently under review.', + }, + ], + content: + 'Hang tight! The {project name} project is currently under review.', }, + VERIFICATION_FORM_REJECTED: { + name: 'Form rejected', + description: 'Form rejected', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.VERIFICATION_FORM_REJECTED, + emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, + emailNotificationId: SegmentEvents.PROJECT_REJECTED, + pushNotifierService: null, + title: 'Form rejected', + htmlTemplate: [ + { + type: 'p', + content: "We can't verify the ", + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: '.', + }, + { + type: 'br', + }, + { + type: 'p', + content: '$reason', + }, + ], + content: "We can't verify the {project name}. {reason}.\n{instruction}", + }, + REAPPLY_VERIFICATION_FORM_REMINDER: { + name: 'Re-apply for verification reminder', + description: 'Re-apply for verification reminder', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.VERIFICATION_FORM_Reapply_Reminder, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Re-apply for verification reminder', + htmlTemplate: [ + { + type: 'p', + content: 'The verification process for ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' project is still pending.', + }, + { + type: 'br', + }, + { + type: 'a', + content: 'click here', + href: '$href', + }, + { + type: 'p', + content: ' to continue.', + }, + ], + content: + 'The verification process for {project name} project is still pending. \n[Click here] to continue.}', + }, + CLAIM_REWARD: { + name: 'Claim', + description: 'Claim reward', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + schemaValidator: SCHEMA_VALIDATORS_NAMES.GIV_FARM_CLAIM, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Claim', + htmlTemplate: [ + { + type: 'p', + content: 'Pssst! your rewards are ready to claim', + }, + { + type: 'br', + }, + { + type: 'p', + content: 'Checkout GIVeconomy to claim your rewards.', + }, + ], + content: + 'Pssst! your rewards are ready to claim 😉\nCheckout GIVeconomy to claim your rewards.', + }, + REWARDS_HARVESTED: { + name: 'Rewards harvested', + description: 'Rewards harvested', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + schemaValidator: SCHEMA_VALIDATORS_NAMES.GIV_FARM_REWARD_HARVEST, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Rewards harvested', + htmlTemplate: [ + { + type: 'p', + content: 'Rewards harvest complete.', + }, + ], + content: 'Rewards harvest complete.', + }, + STAKE: { + name: 'Stake', + description: 'Stake', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + schemaValidator: SCHEMA_VALIDATORS_NAMES.GIV_FARM_STAKE, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'Stake', + htmlTemplate: [ + { + type: 'p', + content: 'Staking ', + }, + { + type: 'b', + content: '$amount', + }, + { + type: 'p', + content: ' of ', + }, + { + type: 'a', + content: '$poolName', + href: '/givfarm', + }, + { + type: 'p', + content: ' was successful.', + }, + ], + content: 'Staking {amount} of {poolName} was successful.', + }, + UN_STAKE: { + name: 'UnStake', + description: 'UnStake', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + schemaValidator: SCHEMA_VALIDATORS_NAMES.GIV_FARM_UN_STAKE, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + title: 'UnStake', + htmlTemplate: [ + { + type: 'p', + content: 'Unstaking ', + }, + { + type: 'b', + content: '$amount', + }, + { + type: 'p', + content: ' of ', + }, + { + type: 'a', + content: '$poolName', + href: '/givfarm', + }, + { + type: 'p', + content: ' was successful.', + }, + ], + content: 'Unstaking {amount} of {poolname} was successful.', + }, + GIV_BACKS_ARE_READY_TO_CLAIM: { + name: 'GIVbacks are ready to claim', + description: 'GIVbacks are ready to claim', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + schemaValidator: SCHEMA_VALIDATORS_NAMES.GIV_FARM_READY_TO_CLAIM, + emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, + emailNotificationId: SegmentEvents.PROJECT_REJECTED, + pushNotifierService: null, + title: 'GIVbacks are ready to claim', + htmlTemplate: [ + { + type: 'p', + content: 'Your GIVbacks for round ', + }, + { + type: 'b', + content: '$round', + }, + { + type: 'p', + content: ' are ready to claim! ', + }, + { type: 'br' }, + { + type: 'a', + content: 'Click here', + href: '/givbacks', + }, + { + type: 'p', + content: ' to take a shortcut.', + }, + ], + content: + 'Your GIVbacks for round {round number} are ready to claim! \n{Click here} to take a shortcut.', + }, + PROJECT_EDITED: { + name: 'Project edited', + description: 'Project has been edited', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_EDITED, + emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, + emailNotificationId: 'Project edited', + pushNotifierService: null, + title: 'Project edited', + htmlTemplate: [ + { + type: 'p', + content: 'Your Project ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' has been edited', + }, + ], + content: 'You project {project name} has been edited', + }, + PROJECT_BADGE_REVOKED: { + name: 'Project badge revoked', + description: 'Project verified badge revoked', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_BADGE_REVOKED, + emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, + emailNotificationId: 'Project badge revoked', + pushNotifierService: null, + title: 'Project verification revoked', + htmlTemplate: [ + { + type: 'p', + content: 'Your Project ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' is not verified anymore', + }, + ], + content: 'You project {project name} is not verified anymore', + }, + PROJECT_UNVERIFIED: { + name: 'Project unverified', + description: 'Project has been unverified', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UNVERIFIED, + emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, + emailNotificationId: 'Project unverified', + pushNotifierService: null, + title: 'Project verification removed', + htmlTemplate: [ + { + type: 'p', + content: 'Your Project ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' is not verified anymore', + }, + ], + content: 'You project {project name} is not verified anymore', + }, + // DAPP MAILER SEND_EMAIL_CONFIRMATION: { name: 'Send email confirmation', description: 'Project Verification form email confirmation has been sent!', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, schemaValidator: SCHEMA_VALIDATORS_NAMES.SEND_EMAIL_CONFIRMATION, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.DAPP_MAILER, emailNotificationId: 'Send email confirmation', @@ -200,106 +1015,268 @@ export const GivethNotificationTypes = { title: 'Project verification email confirmation', content: '', // Missing copy }, - // SEGMENT AGAIN + MADE_DONATION: { name: 'Made donation', description: 'User made a donation to a project', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, schemaValidator: SCHEMA_VALIDATORS_NAMES.MADE_DONATION, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, emailNotificationId: 'Made donation', pushNotifierService: null, - title: 'Donation is successfull', - content: '', // Missing copy + title: 'Donations is successfull', + htmlTemplate: [ + { + type: 'p', + content: 'Congrats! Your donation to ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' was successful', + }, + { type: 'br' }, + { + type: 'p', + content: "You're a Giveth Donor now :)", + }, + ], + content: + "congrats! Your donation to {project name} was successful.\nYou're a Giveth Donor now :)", }, DONATION_RECEIVED: { name: 'Donation received', description: 'Project has received a donation', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, schemaValidator: SCHEMA_VALIDATORS_NAMES.DONATION_RECEIVED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, emailNotificationId: 'Donation received', pushNotifierService: null, title: 'Project received a donation', - content: '', // Missing copy + htmlTemplate: [ + { + type: 'p', + content: 'Hurray! Your project ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' received a donation 🥳', + }, + ], + content: 'Hurray! Your project {project name} received a donation 🥳', }, - PROJECT_UPDATED_DONOR: { - name: 'Project updated - donor', - description: - 'Send notification to donors that the project has added an updated', + DONATION_FAILED: { + name: 'Failed donation', + description: 'Project has received a donation', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UPDATED_DONOR, - emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project updated - donor', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.GET_DONATION_PRICE_FAILED, + emailNotifierService: null, + emailNotificationId: null, pushNotifierService: null, - title: 'Project posted an update', - content: '', // Missing copy + title: 'Failed donation', + htmlTemplate: [ + { + type: 'p', + content: 'Your donation to ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' was not successful.', + }, + { + type: 'p', + content: '$reason', + }, + { type: 'br' }, + { + type: 'a', + content: 'transaction link', + href: '$txLink', + }, + ], + content: + 'Your donation to {project name} was not successful. {reason} \n{tx link}', }, - PROJECT_UPDATED_OWNER: { - name: 'Project updated - owner', - description: - 'Send notification to owner that the project has added an update', + NEW_PROJECT_UPDATE: { + name: 'Project update', + description: 'Project update', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.DISCUSSION, schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UPDATED_OWNER, - emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project updated - owner', + emailNotifierService: null, + emailNotificationId: null, pushNotifierService: null, - title: 'Project posted an update', - content: '', // Missing copy + title: 'Project update', + htmlTemplate: [ + { + type: 'p', + content: 'Your project update was successful.', + }, + ], + content: 'Your project update was successful.', }, - PROJECT_CREATED: { - name: 'Project created', - description: 'Project has been created.', + NEW_PROJECT_UPDATE_DONORS: { + name: 'Project update - Donors', + description: 'Project update - Donors', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_CREATED, - emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Project created', + category: NOTIFICATION_CATEGORY.DISCUSSION, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UPDATED_DONOR, + emailNotifierService: null, + emailNotificationId: null, pushNotifierService: null, - title: 'Project created', - content: '', // Missing copy + title: 'Project update - Donors', + htmlTemplate: [ + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' that you donated before posted an update.', + }, + ], + content: '{Project name} that you donated before posted an update.', }, - UPDATED_PROFILE: { - // No need to notify this - name: 'Updated profile', - description: 'User updated his profile', + NEW_PROJECT_UPDATE_USERS_WHO_LIKED: { + name: 'Project update - Users Who Liked', + description: 'Project update - Users Who Liked', microService: MICRO_SERVICES.givethio, - schemaValidator: null, - category: 'general', + category: NOTIFICATION_CATEGORY.DISCUSSION, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_UPDATED_WHO_LIKED, emailNotifierService: null, emailNotificationId: null, pushNotifierService: null, - title: 'Updated profile', - content: '', // Missing copy + title: 'Project update - Users Who Liked', + htmlTemplate: [ + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: 'that you liked before posted an update.', + }, + ], + content: '{Project name} that you liked before posted an update.', }, - GET_DONATION_PRICE_FAILED: { - name: 'Get Donation Price Failed', - description: 'Project has been created.', + + PROJECT_UPDATED_OWNER: { + name: 'Project updated - owner', + description: + 'Send notification to owner that the project has added an update', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', - schemaValidator: SCHEMA_VALIDATORS_NAMES.GET_DONATION_PRICE_FAILED, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_EDITED, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, - emailNotificationId: 'Get Donation Price Failed', + emailNotificationId: 'Project updated - owner', pushNotifierService: null, - title: 'Donation has been failed', + title: 'Project posted an update', + htmlTemplate: [ + { + type: 'p', + content: 'Your project update was successful.', + }, + ], content: '', // Missing copy }, + PROJECT_UPDATED_DONOR: { + name: 'Project updated - donor', + description: + 'Send notification to donors that the project has added an updated', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_EDITED, + emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, + emailNotificationId: 'Project updated - donor', + pushNotifierService: null, + title: 'Project posted an update', + htmlTemplate: [ + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' that you donated before posted an update.', + }, + ], + content: '{Project name} that you donated before posted an update.', + }, + VERIFICATION_FORM_GOT_DRAFT_BY_ADMIN: { name: 'Verification form got draft by admin', - description: 'Project has been created.', + description: 'Verification form got drafted by admin', microService: MICRO_SERVICES.givethio, - category: 'projectRelated', + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, schemaValidator: SCHEMA_VALIDATORS_NAMES.VERIFICATION_FORM_GOT_DRAFT_BY_ADMIN, emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, emailNotificationId: 'Verification form got draft by admin', pushNotifierService: null, title: 'Project verification under review', - content: '', // Missing copy + htmlTemplate: [ + { + type: 'p', + content: 'Your project ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' got draft by admin', + }, + ], + content: 'Your project {project name} got draft by admin', + }, + PROJECT_RECEIVED_LIKE: { + name: 'project liked', + description: 'project liked', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.PROJECT_RELATED, + schemaValidator: SCHEMA_VALIDATORS_NAMES.PROJECT_RECEIVED_LIKE, + emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT, + emailNotificationId: null, + pushNotifierService: null, + title: 'project liked', + htmlTemplate: [ + { + type: 'p', + content: 'Nice! Your project ', + }, + { + type: 'a', + content: '$projectTitle', + href: '$projectLink', + }, + { + type: 'p', + content: ' received a like', + }, + ], + content: 'Nice! Your project {project name} received a like', }, }; diff --git a/src/controllers/v1/notificationsController.ts b/src/controllers/v1/notificationsController.ts index 4e9dfa1..a891dfb 100644 --- a/src/controllers/v1/notificationsController.ts +++ b/src/controllers/v1/notificationsController.ts @@ -14,8 +14,6 @@ import { import { logger } from '../../utils/logger'; import { - getNotificationsValidator, - readSingleNotificationsValidator, sendNotificationValidator, validateWithJoiSchema, } from '../../validators/schemaValidators'; @@ -44,11 +42,10 @@ import { getNotificationTypeByEventName, getNotificationTypeByEventNameAndMicroservice, } from '../../repositories/notificationTypeRepository'; -import { SCHEMA_VALIDATORS } from '../../utils/validators/segmentValidators'; -import { THIRD_PARTY_EMAIL_SERVICES } from '../../utils/utils'; import { EMAIL_STATUSES } from '../../entities/notification'; import { getAnalytics, SegmentEvents } from '../../services/segment/analytics'; import { createNewUserAddressIfNotExists } from '../../repositories/userAddressRepository'; +import { SEGMENT_METADATA_SCHEMA_VALIDATOR } from '../../utils/validators/segmentAndMetadataValidators'; const analytics = getAnalytics(); @@ -84,10 +81,17 @@ export class NotificationsController { let emailStatus = body.sendEmail ? EMAIL_STATUSES.WAITING_TO_BE_SEND : EMAIL_STATUSES.NO_NEED_TO_SEND; - if (body.sendSegment && notificationType.schemaValidator) { - const schemaValidator = - SCHEMA_VALIDATORS[notificationType.schemaValidator as string]; - validateWithJoiSchema(body.segmentData, schemaValidator); + + const segmentValidator = + SEGMENT_METADATA_SCHEMA_VALIDATOR[ + notificationType?.schemaValidator as string + ]?.segment; + const metadataValidator = + SEGMENT_METADATA_SCHEMA_VALIDATOR[ + notificationType?.schemaValidator as string + ]?.metadata; + if (body.sendSegment && segmentValidator) { + validateWithJoiSchema(body.segmentData, segmentValidator); analytics.track( notificationType.emailNotificationId!, body.analyticsUserId, @@ -97,6 +101,9 @@ export class NotificationsController { emailStatus = EMAIL_STATUSES.SENT; } + if (metadataValidator) { + validateWithJoiSchema(body.metadata, metadataValidator); + } await createNotification({ notificationType, user: userAddress, diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index b392a30..7327452 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -16,58 +16,40 @@ import { NotificationSetting } from './notificationSetting'; // Export Object with Schemas to N1 lookup export const SCHEMA_VALIDATORS_NAMES = { - DRAFTED_PROJECT_ACTIVATED: 'draftedProjectValidator', + ADMIN_MESSAGE: 'adminMessage', + DRAFTED_PROJECT_SAVED: 'draftedProjectSavedValidator', + DRAFTED_PROJECT_ACTIVATED: 'draftedProjectPublishedValidator', PROJECT_LISTED: 'projectListed', PROJECT_UNLISTED: 'projectUnlisted', PROJECT_EDITED: 'projectEdited', PROJECT_BADGE_REVOKED: 'projectBadgeRevoked', PROJECT_VERIFIED: 'projectVerified', - PROJECT_REJECTED: 'projectRejected', PROJECT_UNVERIFIED: 'projectUnverified', PROJECT_ACTIVATED: 'projectActivated', PROJECT_DEACTIVATED: 'projectDeactivated', PROJECT_CANCELLED: 'projectCancelled', + VERIFICATION_FORM_SENT: 'verificationFormSent', + VERIFICATION_FORM_Reapply_Reminder: 'verificationFormReapplyReminder', + VERIFICATION_FORM_REJECTED: 'verificationFormRejected', + + GIV_FARM_CLAIM: 'givFarmClaim', + GIV_FARM_STAKE: 'givFarmStake', + GIV_FARM_UN_STAKE: 'givFarmUnStake', + GIV_FARM_READY_TO_CLAIM: 'givFarmReadyToClaim', + GIV_FARM_REWARD_HARVEST: 'givFarmRewardHarvest', + SEND_EMAIL_CONFIRMATION: 'sendEmailConfirmation', // verificationForm, MADE_DONATION: 'madeDonation', DONATION_RECEIVED: 'donationReceived', PROJECT_UPDATED_DONOR: 'projectUpdatedDonor', PROJECT_UPDATED_OWNER: 'projectUpdatedOwner', + PROJECT_UPDATED_WHO_LIKED: 'projectUpdatedWhoLiked', PROJECT_CREATED: 'projectCreated', GET_DONATION_PRICE_FAILED: 'getDonationPriceFailed', VERIFICATION_FORM_GOT_DRAFT_BY_ADMIN: 'verificationFormDrafted', + PROJECT_RECEIVED_LIKE: 'projectReceivedLike', }; - -export class HtmlTemplate { - /** - * sample - * { - "icon": "", - "content": [ - { - "type": "p", - "content" : "you staked" - }, - { - "type": "b", - "content": "$amount" - }, - { - "type": "p", - "content" : "on" - }, - { - "type": "a", - "content" : "$farm", - "href": "$href1" - } - ], - "qutoe": "hey bro, how are you?" - } - */ - icon?: string; - content: { type: string; content: string; href?: string }[]; - quote: string; -} +export type HtmlTemplate = { type: string; content: string; href?: string }[]; // This table needs to be prefilled with all notifications in the design // Schema designed based on https://github.com/Giveth/giveth-dapps-v2/issues/475 diff --git a/src/repositories/notificationRepository.test.ts b/src/repositories/notificationRepository.test.ts index 0958d75..41232c0 100644 --- a/src/repositories/notificationRepository.test.ts +++ b/src/repositories/notificationRepository.test.ts @@ -42,7 +42,7 @@ describe( describe('createNotification() test cases', createNotificationTestCases); const eventName = 'Project listed'; -const profileEventName = 'Updated profile'; +const profileEventName = 'Incomplete profile'; function createNotificationTestCases() { it('should create notification with required params', async () => { diff --git a/src/routes/v1/notificationRouter.test.ts b/src/routes/v1/notificationRouter.test.ts index 16bf011..6739e00 100644 --- a/src/routes/v1/notificationRouter.test.ts +++ b/src/routes/v1/notificationRouter.test.ts @@ -1,37 +1,2038 @@ +import { + generateRandomEthereumAddress, + getGivethIoBasicAuth, + serverUrl, +} from '../../../test/testUtils'; import axios from 'axios'; -import { SEED_DATA, serverUrl } from '../../../test/testUtils'; import { assert } from 'chai'; -import { createBasicAuthentication } from '../../utils/authorizationUtils'; -import { SendNotificationRequest } from '../../types/requestResponses'; -import { x } from 'joi'; +import { errorMessages, errorMessagesEnum } from '../../utils/errorMessages'; describe('/notifications POST test cases', sendNotification); function sendNotification() { - it('should return success response', async () => { - // const data : SendNotificationRequest ={ - // email: 'x@giveth.io', - // metadata: {}, - // notificationTemplate:'projectListed', - // - // - // } - // const result = await axios.post( - // `${serverUrl}/v1/notifications`, - // { - // scopes: [scopeLabels.CREATE_DONATION], - // }, - // { - // headers: { - // authorization: createBasicAuthentication({ - // username: applicationData.label, - // secret: applicationData.secret, - // }), - // }, - // }, - // ); - // assert.equal(result.status, 200); - // assert.isOk(result.data.result.accessToken); - // assert.equal(result.data.result.payload.applicationId, applicationData.id); + const sendNotificationUrl = `${serverUrl}/v1/thirdParty/notifications`; + const projectTitle = 'project title'; + const projectLink = 'https://giveth.io/project/project-title'; + + it('should create *Incomplete profile* notification, success, segment is off', async () => { + const data = { + eventName: 'Incomplete profile', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: {}, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + console.log('**result**', result.data); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + + it('should create *The profile has been completed* notification, success, segment is off', async () => { + const data = { + eventName: 'The profile has been completed', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: {}, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + console.log('**result**', result.data); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + + it('should create *Admin message* notification, success, segment is off', async () => { + const data = { + eventName: 'Admin message', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + href: 'href', + linkTitle: 'linkTitle', + instruction: 'instruction', + content: 'content', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Admin message* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Admin message', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + href: 'href', + instruction: 'instruction', + content: 'content', + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"linkTitle" is required'); + } + }); + + it('should create *draft project saved* notification, success, segment is off', async () => { + const data = { + eventName: 'The project saved as draft', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *draft project saved* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'The project saved as draft', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Draft published* notification, success, segment is off', async () => { + const data = { + eventName: 'Draft published', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Draft published* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Draft published', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project listed* notification, success, segment is off', async () => { + const data = { + eventName: 'Project listed', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project listed* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project listed', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project unlisted* notification, success, segment is off', async () => { + const data = { + eventName: 'Project unlisted', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project unlisted* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project unlisted', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project unlisted - Donors* notification, success, segment is off', async () => { + const data = { + eventName: 'Project unlisted - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project unlisted - Donors* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project unlisted - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project unlisted - Users Who Liked* notification, success, segment is off', async () => { + const data = { + eventName: 'Project unlisted - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project unlisted - Users Who Liked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project unlisted - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project cancelled* notification, success, segment is off', async () => { + const data = { + eventName: 'Project cancelled', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project cancelled* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project cancelled', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project cancelled - Donors* notification, success, segment is off', async () => { + const data = { + eventName: 'Project cancelled - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project cancelled - Donors* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project cancelled - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project cancelled - Users Who Liked* notification, success, segment is off', async () => { + const data = { + eventName: 'Project cancelled - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project cancelled - Users Who Liked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project cancelled - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project activated* notification, success, segment is off', async () => { + const data = { + eventName: 'Project activated', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project activated* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project activated', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project activated - Donors* notification, success, segment is off', async () => { + const data = { + eventName: 'Project activated - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project activated - Donors* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project activated - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project activated - Users Who Liked* notification, success, segment is off', async () => { + const data = { + eventName: 'Project activated - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project activated - Users Who Liked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project activated - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project deactivated* notification, success, segment is off', async () => { + const data = { + eventName: 'Project deactivated', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + reason: 'hi', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project deactivated* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project deactivated', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project deactivated - Donors* notification, success, segment is off', async () => { + const data = { + eventName: 'Project deactivated - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + reason: 'hi', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project deactivated - Donors* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project deactivated - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project deactivated - Users Who Liked* notification, success, segment is off', async () => { + const data = { + eventName: 'Project deactivated - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + reason: 'hi', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project deactivated - Users Who Liked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project deactivated - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project verified* notification, success, segment is off', async () => { + const data = { + eventName: 'Project verified', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project verified* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project verified', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project verified - Donors* notification, success, segment is off', async () => { + const data = { + eventName: 'Project verified - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project verified - Donors* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project verified - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project verified - Users Who Liked* notification, success, segment is off', async () => { + const data = { + eventName: 'Project verified - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project verified - Users Who Liked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project verified - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Form sent (Under review)* notification, success, segment is off', async () => { + const data = { + eventName: 'Form sent (Under review)', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Form sent (Under review)* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Form sent (Under review)', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Form rejected* notification, success, segment is off', async () => { + const data = { + eventName: 'Form rejected', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + reason: 'hi', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Form rejected* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Form rejected', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Re-apply for verification reminder* notification, success, segment is off', async () => { + const data = { + eventName: 'Re-apply for verification reminder', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + href: 'href', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Re-apply for verification reminder* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Re-apply for verification reminder', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + href: 'href', + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Claim* notification, success, segment is off', async () => { + const data = { + eventName: 'Claim', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: {}, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + console.log('**result**', result.data); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + + it('should create *Rewards harvested* notification, success, segment is off', async () => { + const data = { + eventName: 'Rewards harvested', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: {}, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + console.log('**result**', result.data); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + + it('should create *Stake* notification, success, segment is off', async () => { + const data = { + eventName: 'Stake', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + poolName: 'GIV farm', + amount: '20', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Stake* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Stake', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + poolName: 'GIV farm', + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"amount" is required'); + } + }); + + it('should create *UnStake* notification, success, segment is off', async () => { + const data = { + eventName: 'UnStake', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + poolName: 'GIV farm', + amount: '20', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *UnStake* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'UnStake', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + poolName: 'GIV farm', + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"amount" is required'); + } + }); + + it('should create *GIVbacks are ready to claim* notification, success, segment is off', async () => { + const data = { + eventName: 'GIVbacks are ready to claim', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + round: 5, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *GIVbacks are ready to claim* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'GIVbacks are ready to claim', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: {}, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"round" is required'); + } + }); + + it('should create *Project edited* notification, success, segment is off', async () => { + const data = { + eventName: 'Project edited', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project edited* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project edited', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project badge revoked* notification, success, segment is off', async () => { + const data = { + eventName: 'Project badge revoked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project badge revoked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project badge revoked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project unverified* notification, success, segment is off', async () => { + const data = { + eventName: 'Project unverified', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project unverified* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project unverified', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Send email confirmation* notification, success, segment is off', async () => { + const data = { + eventName: 'Send email confirmation', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: {}, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + console.log('**result**', result.data); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + + it('should create *Made donation* notification, success, segment is off', async () => { + const data = { + eventName: 'Made donation', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Made donation* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Made donation', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Donation received* notification, success, segment is off', async () => { + const data = { + eventName: 'Donation received', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Donation received* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Donation received', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Failed donation* notification, success, segment is off', async () => { + const data = { + eventName: 'Failed donation', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + reason: 'reason', + txLink: 'txLink', + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Failed donation* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Failed donation', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + reason: 'reason', + txLink: 'txLink', + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project update - Donors* notification, success, segment is off', async () => { + const data = { + eventName: 'Project update - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project update - Donors* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project update - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project update* notification, success, segment is off', async () => { + const data = { + eventName: 'Project update', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project update* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project update', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project update - Donors* notification, success, segment is off', async () => { + const data = { + eventName: 'Project update - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project update - Donors* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project update - Donors', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project update - Users Who Liked* notification, success, segment is off', async () => { + const data = { + eventName: 'Project update - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project update - Users Who Liked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project update - Users Who Liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project updated - owner* notification, success, segment is off', async () => { + const data = { + eventName: 'Project updated - owner', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project updated - owner* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project updated - owner', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Project updated - donor* notification, success, segment is off', async () => { + const data = { + eventName: 'Project updated - donor', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Project updated - donor* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Project updated - donor', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *Verification form got draft by admin* notification, success, segment is off', async () => { + const data = { + eventName: 'Verification form got draft by admin', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *Verification form got draft by admin* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'Verification form got draft by admin', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } + }); + + it('should create *project liked* notification, success, segment is off', async () => { + const data = { + eventName: 'project liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + }; + + const result = await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + assert.equal(result.status, 200); + assert.isOk(result.data); + assert.isTrue(result.data.success); + }); + it('should create *project liked* notification, failed invalid metadata, segment is off', async () => { + try { + const data = { + eventName: 'project liked', + sendEmail: false, + sendSegment: false, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectLink, + }, + }; + + await axios.post(sendNotificationUrl, data, { + headers: { + authorization: getGivethIoBasicAuth(), + }, + }); + // If request doesn't fail, it means this test failed + assert.isTrue(false); + } catch (e: any) { + assert.equal( + e.response.data.message, + errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message, + ); + assert.equal(e.response.data.description, '"projectTitle" is required'); + } }); } diff --git a/src/services/segment/analytics.ts b/src/services/segment/analytics.ts index f1a8140..858c706 100644 --- a/src/services/segment/analytics.ts +++ b/src/services/segment/analytics.ts @@ -8,6 +8,7 @@ export enum SegmentEvents { PROJECT_BADGE_REVOKED = 'Project badge revoked', PROJECT_VERIFIED = 'Project verified', PROJECT_REJECTED = 'Project rejected', + GIVBACK_ARE_READY_TO_CLAIM = 'We dont have event yet', PROJECT_UNVERIFIED = 'Project unverified', PROJECT_ACTIVATED = 'Project activated', PROJECT_DEACTIVATED = 'Project deactivated', diff --git a/src/types/general.ts b/src/types/general.ts index c643e12..3834623 100644 --- a/src/types/general.ts +++ b/src/types/general.ts @@ -6,6 +6,7 @@ export type User = { export enum NOTIFICATION_CATEGORY { PROJECT_RELATED = 'projectRelated', + DISCUSSION = 'discussion', GENERAL = 'general', GIV_ECONOMY = 'givEconomy', } diff --git a/src/utils/validators/segmentValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts similarity index 55% rename from src/utils/validators/segmentValidators.ts rename to src/utils/validators/segmentAndMetadataValidators.ts index eb7f8e9..fec57dd 100644 --- a/src/utils/validators/segmentValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -27,7 +27,16 @@ const projectSchema = { slug: Joi.string().required(), }; -const draftedProjectValidator = Joi.object({ +const draftedProjectPublishedSegmentValidator = Joi.object({ + event: Joi.string() + .required() + .valid(GIVETH_IO_EVENTS.DRAFTED_PROJECT_ACTIVATED), + analyticsUserId: Joi.string().required(), + properties: projectSchema, + anonymousId: Joi.string(), +}); + +const draftedProjectSavedSegmentValidator = Joi.object({ event: Joi.string() .required() .valid(GIVETH_IO_EVENTS.DRAFTED_PROJECT_ACTIVATED), @@ -46,7 +55,7 @@ const projectTrackerSchema = { walletAddress: Joi.string().required().pattern(ethereumWalletAddressRegex), }; -const projectListed = Joi.object({ +const projectListedSegmentValidator = Joi.object({ event: Joi.string() .required() .valid(GIVETH_IO_EVENTS.DRAFTED_PROJECT_ACTIVATED), @@ -55,7 +64,7 @@ const projectListed = Joi.object({ anonymousId: Joi.string(), }); -const projectUnlisted = Joi.object({ +const projectUnlistedSegmentValidator = Joi.object({ event: Joi.string() .required() .valid(GIVETH_IO_EVENTS.DRAFTED_PROJECT_ACTIVATED), @@ -64,56 +73,56 @@ const projectUnlisted = Joi.object({ anonymousId: Joi.string(), }); -const projectEdited = Joi.object({ +const projectEditedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_EDITED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const projectBadgeRevoked = Joi.object({ +const projectBadgeRevokedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_BADGE_REVOKED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const projectVerified = Joi.object({ +const projectVerifiedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_VERIFIED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const projectRejected = Joi.object({ +const projectRejectedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_REJECTED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const projectUnverified = Joi.object({ +const projectUnverifiedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_UNVERIFIED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const projectActivated = Joi.object({ +const projectActivatedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_ACTIVATED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const projectDeactivated = Joi.object({ +const projectDeactivatedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_DEACTIVATED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const projectCancelled = Joi.object({ +const projectCancelledSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_CANCELLED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, @@ -126,7 +135,7 @@ const sendVerificationEmailSchema = Joi.object({ confirmationToken: Joi.string().required(), }); -const sendEmailConfirmation = Joi.object({ +const sendEmailConfirmationSegmentValidator = Joi.object({ event: Joi.string() .required() .valid(GIVETH_IO_EVENTS.SEND_EMAIL_CONFIRMATION), @@ -163,14 +172,14 @@ const donationTrackerSchema = Joi.object({ transakStatus: Joi.string().allow(null), }); -const madeDonation = Joi.object({ +const madeDonationSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.MADE_DONATION), analyticsUserId: Joi.string().required(), properties: donationTrackerSchema, anonymousId: Joi.string(), }); -const donationReceived = Joi.object({ +const donationReceivedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.DONATION_RECEIVED), analyticsUserId: Joi.string().required(), properties: donationTrackerSchema, @@ -196,28 +205,28 @@ const projectUpdatesForOwnerSchema = Joi.object({ firstName: Joi.string().required(), }); -const projectUpdatedDonor = Joi.object({ +const projectUpdatedDonorSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_UPDATED_DONOR), analyticsUserId: Joi.string().required(), properties: projectUpdatesForDonorSchema, anonymousId: Joi.string(), }); -const projectUpdatedOwner = Joi.object({ +const projectUpdatedOwnerSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_UPDATED_OWNER), analyticsUserId: Joi.string().required(), properties: projectUpdatesForOwnerSchema, anonymousId: Joi.string(), }); -const projectCreated = Joi.object({ +const projectCreatedSegmentValidator = Joi.object({ event: Joi.string().required().valid(GIVETH_IO_EVENTS.PROJECT_CREATED), analyticsUserId: Joi.string().required(), properties: projectTrackerSchema, anonymousId: Joi.string(), }); -const getDonationPriceFailed = Joi.object({ +const getDonationPriceFailedSegmentValidator = Joi.object({ event: Joi.string() .required() .valid(GIVETH_IO_EVENTS.GET_DONATION_PRICE_FAILED), @@ -226,7 +235,7 @@ const getDonationPriceFailed = Joi.object({ anonymousId: Joi.string(), }); -const verificationFormDrafted = Joi.object({ +const verificationFormDraftedSegmentValidator = Joi.object({ event: Joi.string() .required() .valid(GIVETH_IO_EVENTS.VERIFICATION_FORM_GOT_DRAFT_BY_ADMIN), @@ -235,27 +244,151 @@ const verificationFormDrafted = Joi.object({ anonymousId: Joi.string(), }); -export const SCHEMA_VALIDATORS = { - draftedProjectValidator: draftedProjectValidator, - projectListed: projectListed, - projectUnlisted: projectUnlisted, - projectEdited: projectEdited, - projectBadgeRevoked: projectBadgeRevoked, - projectVerified: projectVerified, - projectRejected: projectRejected, - projectUnverified: projectUnverified, - projectActivated: projectActivated, - projectDeactivated: projectDeactivated, - projectCancelled: projectCancelled, - sendEmailConfirmation: sendEmailConfirmation, - madeDonation: madeDonation, - donationReceived: donationReceived, - projectUpdatedDonor: projectUpdatedDonor, - projectUpdatedOwner: projectUpdatedOwner, - projectCreated: projectCreated, - getDonationPriceFailed: getDonationPriceFailed, - verificationFormDrafted: verificationFormDrafted, +const projectTitleProjectLinkSchema = Joi.object({ + projectTitle: Joi.string().required(), + projectLink: Joi.string().required(), +}); +const projectTitleProjectLinkReasonSchema = Joi.object({ + projectTitle: Joi.string().required(), + projectLink: Joi.string().required(), + reason: Joi.string(), +}); +const verificationFormReapplyReminderSchema = Joi.object({ + projectTitle: Joi.string().required(), + projectLink: Joi.string().required(), + href: Joi.string(), +}); +const getDonationPriceFailedMetadataSchema = Joi.object({ + projectTitle: Joi.string().required(), + projectLink: Joi.string().required(), + reason: Joi.string().required(), + txLink: Joi.string().required(), +}); +const stakeUnStakeSchema = Joi.object({ + poolName: Joi.string().required(), + amount: Joi.number().required(), +}); +const claimSchema = Joi.object({ + round: Joi.number().required(), +}); + +const adminMessageSchema = Joi.object({ + linkTitle: Joi.string().required(), + content: Joi.string().required(), + instruction: Joi.string().required(), + href: Joi.string().required(), +}); + +export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { + [key: string]: { + segment: ObjectSchema | null; + metadata: ObjectSchema | null; + }; +} = { + draftedProjectSavedValidator: { + metadata: projectTitleProjectLinkSchema, + segment: draftedProjectSavedSegmentValidator, + }, + draftedProjectPublishedValidator: { + metadata: projectTitleProjectLinkSchema, + segment: draftedProjectPublishedSegmentValidator, + }, + projectListed: { + metadata: projectTitleProjectLinkSchema, + segment: projectListedSegmentValidator, + }, + projectUnlisted: { + metadata: projectTitleProjectLinkSchema, + segment: projectUnlistedSegmentValidator, + }, + projectEdited: { + metadata: projectTitleProjectLinkSchema, + segment: projectEditedSegmentValidator, + }, + projectBadgeRevoked: { + metadata: projectTitleProjectLinkSchema, + segment: projectBadgeRevokedSegmentValidator, + }, + projectVerified: { + metadata: projectTitleProjectLinkSchema, + segment: projectVerifiedSegmentValidator, + }, + projectUnverified: { + metadata: projectTitleProjectLinkSchema, + segment: projectUnverifiedSegmentValidator, + }, + projectActivated: { + metadata: projectTitleProjectLinkSchema, + segment: projectActivatedSegmentValidator, + }, + projectDeactivated: { + metadata: projectTitleProjectLinkReasonSchema, + segment: projectDeactivatedSegmentValidator, + }, + projectCancelled: { + metadata: projectTitleProjectLinkSchema, + segment: projectCancelledSegmentValidator, + }, + sendEmailConfirmation: { + metadata: null, + segment: sendEmailConfirmationSegmentValidator, + }, + madeDonation: { + metadata: projectTitleProjectLinkSchema, + segment: madeDonationSegmentValidator, + }, + donationReceived: { + metadata: projectTitleProjectLinkSchema, + segment: donationReceivedSegmentValidator, + }, + projectUpdatedDonor: { + metadata: projectTitleProjectLinkSchema, + segment: projectUpdatedDonorSegmentValidator, + }, + projectUpdatedOwner: { + metadata: projectTitleProjectLinkSchema, + segment: projectUpdatedOwnerSegmentValidator, + }, + projectCreated: { + metadata: projectTitleProjectLinkSchema, + segment: projectCreatedSegmentValidator, + }, + getDonationPriceFailed: { + metadata: getDonationPriceFailedMetadataSchema, + segment: getDonationPriceFailedSegmentValidator, + }, + verificationFormDrafted: { + metadata: projectTitleProjectLinkSchema, + segment: verificationFormDraftedSegmentValidator, + }, + verificationFormSent: { + metadata: projectTitleProjectLinkSchema, + segment: null, + }, + projectReceivedLike: { + metadata: projectTitleProjectLinkSchema, + segment: null, + }, + projectUpdatedWhoLiked: { + metadata: projectTitleProjectLinkSchema, + segment: null, + }, + verificationFormRejected: { + metadata: projectTitleProjectLinkReasonSchema, + segment: null, + }, + verificationFormReapplyReminder: { + metadata: verificationFormReapplyReminderSchema, + segment: null, + }, + givFarmClaim: { metadata: null, segment: null }, + givFarmRewardHarvest: { metadata: null, segment: null }, + givFarmStake: { metadata: stakeUnStakeSchema, segment: null }, + givFarmUnStake: { metadata: stakeUnStakeSchema, segment: null }, + givFarmReadyToClaim: { metadata: claimSchema, segment: null }, + adminMessage: { metadata: adminMessageSchema, segment: null }, }; + function throwHttpErrorIfJoiValidatorFails( validationResult: Joi.ValidationResult, ) { diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index 638a2f8..01c8cbd 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -31,12 +31,9 @@ export const sendNotificationValidator = Joi.object({ userWalletAddress: Joi.string() .pattern(ethereumWalletAddressRegex) .required(), - metadata: Joi.object({ - amount: Joi.number(), - currency: Joi.string(), - projectSlug: Joi.string(), - name: Joi.string(), - }), + + // We have a different validator for each notification type and validate it later in notification controller + metadata: Joi.object(), }); export const getNotificationsValidator = Joi.object({ diff --git a/test/pre-test-scripts.ts b/test/pre-test-scripts.ts index 179d158..f269af7 100644 --- a/test/pre-test-scripts.ts +++ b/test/pre-test-scripts.ts @@ -6,6 +6,9 @@ dotenv.config({ import { initServer } from '../src/server'; import { AppDataSource } from '../src/dataSource'; +import { ThirdParty } from '../src/entities/ThirdParty'; +import { Notification } from '../src/entities/notification'; +import { sleep } from './testUtils'; /* eslint-disable @typescript-eslint/no-var-requires */ const { dropdb, createdb } = require('pgtools'); @@ -48,7 +51,11 @@ async function runMigrations() { } const seedDb = async () => { - // + await ThirdParty.create({ + microService: process.env.GIVETH_IO_THIRD_PARTY_MICRO_SERVICE, + secret: process.env.GIVETH_IO_THIRD_PARTY_SECRET, + isActive: true, + }).save(); }; before(async () => { @@ -57,6 +64,7 @@ before(async () => { await runMigrations(); await seedDb(); await initServer(); + await sleep(500); } catch (e: any) { throw new Error(`Could not setup tests requirements \n${e.message}`); } diff --git a/test/testUtils.ts b/test/testUtils.ts index a094e83..1715efe 100644 --- a/test/testUtils.ts +++ b/test/testUtils.ts @@ -2,6 +2,7 @@ import { assert } from 'chai'; import { Notification } from '../src/entities/notification'; import { UserAddress } from '../src/entities/userAddress'; import { NotificationType } from '../src/entities/notificationType'; +import { createBasicAuthentication } from '../src/utils/authorizationUtils'; // eslint:disable-next-line export const serverUrl = 'http://localhost:3041'; @@ -90,3 +91,10 @@ export const saveNotificationDirectlyToDb = async ( return notification.save(); }; export const SEED_DATA = {}; + +export const getGivethIoBasicAuth = () => { + return createBasicAuthentication({ + secret: process.env.GIVETH_IO_THIRD_PARTY_SECRET as string, + username: process.env.GIVETH_IO_THIRD_PARTY_MICRO_SERVICE as string, + }); +};