diff --git a/src/routes/v1/notificationRouter.test.ts b/src/routes/v1/notificationRouter.test.ts index 6f6fa7a..0bb403d 100644 --- a/src/routes/v1/notificationRouter.test.ts +++ b/src/routes/v1/notificationRouter.test.ts @@ -2167,6 +2167,126 @@ function sendNotificationTestCases() { ); } }); + + it('should create *Project Ownership Changed To* notification, success', async () => { + const data = { + eventName: 'Project ownership changed to', + sendEmail: true, + sendSegment: true, + creationTime: 1667992708000, + segment: { + payload: { + email: 'aliebrahimi2079@gmail.com', + ownerName: 'Ali', + projectName: 'Test Project', + }, + }, + }; + + 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 Ownership Changed To* notification, failed invalid payload', async () => { + try { + const data = { + eventName: 'Project ownership changed to', + sendEmail: true, + sendSegment: true, + creationTime: 1667992708000, + segment: { + payload: { + email: 'aliebrahimi2079@gmail.com', + ownerName: 'Ali', + projectName: 'Test Project', + invalidField: 'invalid data', + }, + }, + }; + 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, + '"segment.payload.invalidField" is not allowed', + ); + } + }); + + it('should create *Project Ownership Changed From* notification, success', async () => { + const data = { + eventName: 'Project ownership changed from', + sendEmail: true, + sendSegment: true, + creationTime: 1667992708000, + segment: { + payload: { + email: 'aliebrahimi2079@gmail.com', + ownerName: 'Ali', + projectName: 'Test Project', + }, + }, + }; + + 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 Ownership Changed From* notification, failed invalid payload', async () => { + try { + const data = { + eventName: 'Project ownership changed from', + sendEmail: true, + sendSegment: true, + creationTime: 1667992708000, + segment: { + payload: { + email: 'aliebrahimi2079@gmail.com', + ownerName: 'Ali', + projectName: 'Test Project', + invalidField: 'invalid data', + }, + }, + }; + 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, + '"segment.payload.invalidField" is not allowed', + ); + } + }); } function sendBulkNotificationsTestCases() { diff --git a/src/services/notificationService.test.ts b/src/services/notificationService.test.ts index 01c0f75..ec23aad 100644 --- a/src/services/notificationService.test.ts +++ b/src/services/notificationService.test.ts @@ -50,4 +50,62 @@ describe('activityCreator', () => { }), ); }); + + it('should create attributes for PROJECT_OWNER_CHANGED_TO', () => { + const payload = { + email: 'test@example.com', + ownerName: 'Test Owner', + projectName: 'Test Project', + }; + const result = activityCreator( + payload, + NOTIFICATIONS_EVENT_NAMES.PROJECT_OWNERSHIP_CHANGED_TO, + ); + expect(JSON.stringify(result)).equal( + JSON.stringify({ + activities: [ + { + activity_id: 'act:cm:ownership-changed-to', + attributes: { + 'str:cm:ownername': payload.ownerName, + 'str:cm:projectname': payload.projectName, + }, + fields: { + 'str::email': payload.email, + }, + }, + ], + merge_by: ['str::email'], + }), + ); + }); + + it('should create attributes for PROJECT_OWNER_CHANGED_FROM', () => { + const payload = { + email: 'test@example.com', + ownerName: 'Test Owner', + projectName: 'Test Project', + }; + const result = activityCreator( + payload, + NOTIFICATIONS_EVENT_NAMES.PROJECT_OWNERSHIP_CHANGED_FROM, + ); + expect(JSON.stringify(result)).equal( + JSON.stringify({ + activities: [ + { + activity_id: 'act:cm:ownership-changed-from', + attributes: { + 'str:cm:ownername': payload.ownerName, + 'str:cm:projectname': payload.projectName, + }, + fields: { + 'str::email': payload.email, + }, + }, + ], + merge_by: ['str::email'], + }), + ); + }); });