Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email verification for qacc #120

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import {
NOTIFICATION_CATEGORY,
NOTIFICATION_TYPE_NAMES,
} from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';
import {
NotificationType,
SCHEMA_VALIDATORS_NAMES,
} from '../src/entities/notificationType';

const QaccEmailVerificationNotificationType = [
{
name: NOTIFICATION_TYPE_NAMES.SEND_EMAIL_VERIFICATION_CODE_FOR_QACC,
description: 'sending email verification code for the Qacc project.',
microService: MICRO_SERVICES.qacc,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator:
SCHEMA_VALIDATORS_NAMES.SEND_EMAIL_VERIFICATION_CODE_FOR_QACC,
title: 'Qacc email verification',
},
];

export class SeedNotificationTypeForEmailVerificationOfQacc1724281179980
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(
NotificationType,
QaccEmailVerificationNotificationType,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = ${NOTIFICATION_TYPE_NAMES.SEND_EMAIL_VERIFICATION_CODE_FOR_QACC};`,
);
}
}
1 change: 1 addition & 0 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const SCHEMA_VALIDATORS_NAMES = {
YOUR_PROJECT_GOT_A_RANK: 'yourProjectGotARank',

NOTIFY_REWARD_AMOUNT: 'notifyRewardAmount',
SEND_EMAIL_VERIFICATION_CODE_FOR_QACC: 'sendEmailVerificationCodeForQacc',
};
export type HtmlTemplate = { type: string; content: string; href?: string }[];

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'],
}),
);
});
});
6 changes: 6 additions & 0 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ export const activityCreator = (
'str:cm:transactionhash': payload.transactionHash,
};
break;
case NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_VERIFICATION_CODE_FOR_QACC:
attributes = {
'int:cm:verificationcode': payload.verificationCode,
'str:cm:email': payload.email,
};
break;
default:
logger.debug('activityCreator() invalid event name', orttoEventName);
return;
Expand Down
1 change: 1 addition & 0 deletions src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ export enum NOTIFICATION_TYPE_NAMES {
CREATE_ORTTO_PROFILE = 'Create Ortto profile',

NOTIFY_REWARD_AMOUNT = 'Notify reward amount',
SEND_EMAIL_VERIFICATION_CODE_FOR_QACC = 'Send email verification code for Qacc',
}
5 changes: 5 additions & 0 deletions src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export enum NOTIFICATIONS_EVENT_NAMES {
SEND_EMAIL_CONFIRMATION = 'Send email confirmation',
SUBSCRIBE_ONBOARDING = 'Subscribe onboarding',
NOTIFY_REWARD_AMOUNT = 'Notify reward amount',

// Qacc Notification
SEND_EMAIL_VERIFICATION_CODE_FOR_QACC = 'Send email verification code for Qacc',
}

export const ORTTO_EVENT_NAMES = {
Expand Down Expand Up @@ -81,4 +84,6 @@ export const ORTTO_EVENT_NAMES = {
'verification-form-email-verification',
[NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward',
[NOTIFICATIONS_EVENT_NAMES.SUBSCRIBE_ONBOARDING]: 'onboarding-form',
[NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_VERIFICATION_CODE_FOR_QACC]:
'qacc-email-verification',
};
9 changes: 9 additions & 0 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ const notifyRewardAmountSegmentSchema = Joi.object({
email: Joi.string().required(),
});

const sendEmailVerificationCodeForQaccSegmentSchema = Joi.object({
verificationCode: Joi.number().required(),
email: Joi.string().required(),
});

export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
[key: string]: {
segment: ObjectSchema | null;
Expand Down Expand Up @@ -352,4 +357,8 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: null,
segment: notifyRewardAmountSegmentSchema,
},
sendEmailVerificationCodeForQacc: {
metadata: null,
segment: sendEmailVerificationCodeForQaccSegmentSchema,
},
};
3 changes: 3 additions & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export const sendNotificationValidator = Joi.object({
network: Joi.string(),
script: Joi.string(),
transactionHash: Joi.string(),

// Qacc email verification
verificationCode: Joi.number(),
}),
}),
});
Expand Down
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
Loading