Skip to content

Commit

Permalink
add unit tests for project ownership changed email notification
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Aug 6, 2024
1 parent ed2c3f6 commit 57d5d92
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/routes/v1/notificationRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
58 changes: 58 additions & 0 deletions src/services/notificationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}),
);
});
});

0 comments on commit 57d5d92

Please sign in to comment.