Skip to content

Commit

Permalink
Add test cases for notify reward amount notification type to the noti…
Browse files Browse the repository at this point in the history
…ficationRouter.test.ts
  • Loading branch information
ae2079 committed Jul 13, 2024
1 parent f3ff7ac commit c3f34ed
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ GIVETH_IO_THIRD_PARTY_MICRO_SERVICE=givethio
GIV_ECONOMY_THIRD_PARTY_SECRET=secret
GIV_ECONOMY_THIRD_PARTY_MICRO_SERVICE=giveconomy-notification-service

NOTIFY_REWARD_THIRD_PARTY_SECRET=secret
NOTIFY_REWARD_THIRD_PARTY_MICRO_SERVICE=notifyreward

# OPTIONAL - force logging to stdout when the value is true
LOG_STDOUT=false

Expand Down
72 changes: 72 additions & 0 deletions src/routes/v1/notificationRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getAccessTokenForMockAuthMicroService,
getGivEconomyBasicAuth,
getGivethIoBasicAuth,
getNotifyRewardBasicAuth,
serverUrl,
sleep,
} from '../../../test/testUtils';
Expand Down Expand Up @@ -2092,6 +2093,77 @@ function sendNotificationTestCases() {
const createdNotification = await findNotificationByTrackId(trackId);
assert.equal(createdNotification?.createdAt.getTime(), creationTime);
});

it('should create *Notify reward amount* notification, success', async () => {
const data = {
eventName: "Notify reward amount",
sendEmail: true,
sendSegment: true,
creationTime: 1667992708000,
email: "aliebrahimi2079@gmail.com",
segment: {
payload: {
round: 10,
date: "1667992708000",
amount: "12134",
contractAddress: "0xsfglsjfdflk",
farm: "test farm",
message: "test message",
network: "ethereum",
script: "test script",
transactionHash: "test txhash"
}
}
};

const result = await axios.post(sendNotificationUrl, data, {
headers: {
authorization: getNotifyRewardBasicAuth(),
},
});

assert.equal(result.status, 200);
assert.isOk(result.data);
assert.isTrue(result.data.success);
});
it('should create *Notify reward amount* notification, failed invalid payload', async () => {
try {
const data = {
eventName: "Notify reward amount",
sendEmail: true,
sendSegment: true,
creationTime: 1667992708000,
email: "aliebrahimi2079@gmail.com",
segment: {
payload: {
round: 10,
date: "1667992708000",
amount: "12134",
contractAddress: "0xsfglsjfdflk",
farm: "test farm",
message: "test message",
network: "ethereum",
script: "test script",
transactionHash: "test txhash",
invalidField: "invalid data"
}
}
};
await axios.post(sendNotificationUrl, data, {
headers: {
authorization: getNotifyRewardBasicAuth(),
},
});
// 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
7 changes: 7 additions & 0 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ export const getGivEconomyBasicAuth = () => {
});
};

export const getNotifyRewardBasicAuth = () => {
return createBasicAuthentication({
secret: process.env.NOTIFY_REWARD_THIRD_PARTY_SECRET as string,
username: process.env.NOTIFY_REWARD_THIRD_PARTY_MICRO_SERVICE as string,
});
};

export const getAccessTokenForMockAuthMicroService = (
walletAddress: string,
) => {
Expand Down

0 comments on commit c3f34ed

Please sign in to comment.