Skip to content

Commit

Permalink
Add unit tests for email verification for Qacc
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Aug 21, 2024
1 parent 7f81dfd commit b0ffe2c
Show file tree
Hide file tree
Showing 4 changed files with 92 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 @@ -26,6 +26,9 @@ GIV_ECONOMY_THIRD_PARTY_MICRO_SERVICE=giveconomy-notification-service
NOTIFY_REWARD_THIRD_PARTY_SECRET=secret
NOTIFY_REWARD_THIRD_PARTY_MICRO_SERVICE=notifyreward

QACC_THIRD_PARTY_SECRET=secret
QACC_THIRD_PARTY_MICRO_SERVICE=qacc

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

Expand Down
53 changes: 53 additions & 0 deletions src/routes/v1/notificationRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getGivEconomyBasicAuth,
getGivethIoBasicAuth,
getNotifyRewardBasicAuth,
getQaccBasicAuth,
serverUrl,
sleep,
} from '../../../test/testUtils';
Expand Down Expand Up @@ -2167,6 +2168,58 @@ function sendNotificationTestCases() {
);
}
});

it('should create *Send email verification code for Qacc* notification, success', async () => {
const data = {
eventName: 'Send email verification code for Qacc',
segment: {
payload: {
verificationCode: 654321,
email: '[email protected]',
},
},
};

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

assert.equal(result.status, 200);
assert.isOk(result.data);
assert.isTrue(result.data.success);
});
it('should create *Send email verification code for Qacc* notification, failed invalid payload', async () => {
try {
const data = {
eventName: 'Send email verification code for Qacc',
segment: {
payload: {
verificationCode: 654321,
email: '[email protected]',
invalidField: 'invalid data',
},
},
};
await axios.post(sendNotificationUrl, data, {
headers: {
authorization: getQaccBasicAuth(),
},
});
// 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
29 changes: 29 additions & 0 deletions src/services/notificationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,33 @@ describe('activityCreator', () => {
}),
);
});

it('should create attributes for SEND_EMAIL_VERIFICATION_CODE_FOR_QACC', () => {
const payload = {
verificationCode: 123456,
email: '[email protected]',
};
const result = activityCreator(
payload,
NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_VERIFICATION_CODE_FOR_QACC,
MICRO_SERVICES.qacc,
);
expect(JSON.stringify(result)).equal(
JSON.stringify({
activities: [
{
activity_id: 'act:cm:qacc-email-verification',
attributes: {
'int:cm:verificationcode': 123456,
'str:cm:email': '[email protected]',
},
fields: {
'str::email': payload.email,
},
},
],
merge_by: ['str::email'],
}),
);
});
});
7 changes: 7 additions & 0 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ export const getNotifyRewardBasicAuth = () => {
});
};

export const getQaccBasicAuth = () => {
return createBasicAuthentication({
secret: process.env.QACC_THIRD_PARTY_SECRET as string,
username: process.env.QACC_THIRD_PARTY_MICRO_SERVICE as string,
});
};

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

0 comments on commit b0ffe2c

Please sign in to comment.