-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for project ownership changed email notification
- Loading branch information
Showing
2 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[email protected]', | ||
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: '[email protected]', | ||
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: '[email protected]', | ||
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: '[email protected]', | ||
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() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,62 @@ describe('activityCreator', () => { | |
}), | ||
); | ||
}); | ||
|
||
it('should create attributes for PROJECT_OWNER_CHANGED_TO', () => { | ||
const payload = { | ||
email: '[email protected]', | ||
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: '[email protected]', | ||
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'], | ||
}), | ||
); | ||
}); | ||
}); |