diff --git a/src/routes/v1/notificationRouter.test.ts b/src/routes/v1/notificationRouter.test.ts index aaf8b07..e2c0532 100644 --- a/src/routes/v1/notificationRouter.test.ts +++ b/src/routes/v1/notificationRouter.test.ts @@ -1399,6 +1399,49 @@ function sendNotificationTestCases() { assert.isOk(result.data); assert.isTrue(result.data.success); }); + it('should create *Made donation* notification, success, segment is on, donationValueEth is null', async () => { + const data = { + eventName: 'Made donation', + sendEmail: true, + sendSegment: true, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + segment: { + analyticsUserId: 'givethId-255', + anonymousId: 'givethId-255', + payload: { + email: 'test@giveth.com', + title: 'How many photos is too many photos?', + firstName: 'firstName', + projectOwnerId: '68', + slug: 'how-many-photos-is-too-many-photos', + amount: 0.0001, + transactionId: generateRandomTxHash(), + transactionNetworkId: 5, + currency: 'ETH', + createdAt: '2022-11-10T07:36:13.182Z', + toWalletAddress: generateRandomEthereumAddress(), + donationValueUsd: 0.120492, + donationValueEth: null, + verified: true, + transakStatus: null, + fromWalletAddress: generateRandomEthereumAddress(), + }, + }, + }; + + 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 = { @@ -1427,6 +1470,92 @@ function sendNotificationTestCases() { } }); + it('should create *Donation received* notification, success, segment is on', async () => { + const data = { + eventName: 'Donation received', + sendEmail: true, + sendSegment: true, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + segment: { + analyticsUserId: 'givethId-255', + anonymousId: 'givethId-255', + payload: { + email: 'test@giveth.com', + title: 'How many photos is too many photos?', + firstName: 'firstName', + projectOwnerId: '68', + slug: 'how-many-photos-is-too-many-photos', + amount: 0.0001, + transactionId: generateRandomTxHash(), + transactionNetworkId: 5, + currency: 'ETH', + createdAt: '2022-11-10T07:36:13.182Z', + toWalletAddress: generateRandomEthereumAddress(), + donationValueUsd: 0.120492, + donationValueEth: 0.0001, + verified: true, + transakStatus: null, + fromWalletAddress: generateRandomEthereumAddress(), + }, + }, + }; + + 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, success, segment is on, donationValueEth is null', async () => { + const data = { + eventName: 'Donation received', + sendEmail: true, + sendSegment: true, + userWalletAddress: generateRandomEthereumAddress(), + metadata: { + projectTitle, + projectLink, + }, + segment: { + analyticsUserId: 'givethId-255', + anonymousId: 'givethId-255', + payload: { + email: 'test@giveth.com', + title: 'How many photos is too many photos?', + firstName: 'firstName', + projectOwnerId: '68', + slug: 'how-many-photos-is-too-many-photos', + amount: 0.0001, + transactionId: generateRandomTxHash(), + transactionNetworkId: 5, + currency: 'ETH', + createdAt: '2022-11-10T07:36:13.182Z', + toWalletAddress: generateRandomEthereumAddress(), + donationValueUsd: 0.120492, + donationValueEth: null, + verified: true, + transakStatus: null, + fromWalletAddress: generateRandomEthereumAddress(), + }, + }, + }; + + 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, success, segment is off', async () => { const data = { eventName: 'Donation received', diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index f1089a9..a8891d1 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -62,7 +62,7 @@ export const sendNotificationValidator = Joi.object({ toWalletAddress: Joi.string(), fromWalletAddress: Joi.string().allow(null).allow(''), donationValueUsd: Joi.number(), - donationValueEth: Joi.number(), + donationValueEth: Joi.number().allow(null), verified: Joi.boolean(), transakStatus: Joi.string().allow(null).allow(''),