Skip to content

Commit

Permalink
Merge pull request #107 from Giveth/Release
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
mohammadranjbarz authored Jul 21, 2024
2 parents 1cc27b0 + d33adbb commit f6e4fe6
Show file tree
Hide file tree
Showing 21 changed files with 1,049 additions and 44 deletions.
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

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
5 changes: 5 additions & 0 deletions funding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"opRetro": {
"projectId": "0xe434930e189c807b137ff0d8e2fa6a95eaa57dde574143a02ca0d7fb31a40bea"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 NotifyRewardAmountNotificationType = [
{
name: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT,
description: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.GENERAL,
schemaValidator: SCHEMA_VALIDATORS_NAMES.NOTIFY_REWARD_AMOUNT,
title: "Notify reward report",
}
]

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

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = ${NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT};`,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NOTIFICATION_CATEGORY } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
import { NOTIFICATIONS_EVENT_NAMES } from '../src/types/notifications';

const EmailConfirmationNotificationType = [
{
name: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
description: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator: SCHEMA_VALIDATORS_NAMES.SEND_EMAIL_CONFIRMATION,
}
]

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

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = 'Send email confirmation';`,
);
}
}
26 changes: 26 additions & 0 deletions migrations/1719410008992-seedNotificationTypeForOnboardingGuide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
import { NOTIFICATION_CATEGORY, NOTIFICATION_TYPE_NAMES } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';

const OnboardingNotificationType = [
{
name: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
description: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUBSCRIBE_ONBOARDING,
}
]

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

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = 'Subscribe onboarding';`,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { MICRO_SERVICES } from '../src/utils/utils';
import { NOTIFICATION_CATEGORY } from '../src/types/general';

export class changeMicroserviceAndCategoryOfNotifyRewardNotificationType1720553769343 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE notification_type
SET "microService" = '${MICRO_SERVICES.notifyReward}',
category = '${NOTIFICATION_CATEGORY.ORTTO}'
WHERE name = 'Notify reward amount';
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE notification_type
SET "microService" = '${MICRO_SERVICES.givethio}',
categoty = '${NOTIFICATION_CATEGORY.GENERAL}'
WHERE name = 'Notify reward amount';
`);
}
}
27 changes: 27 additions & 0 deletions migrations/1720828190666-seedThirdPartyForNotifyReward.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class seedThirdPartyForNotifyReward1720828190666 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
if (
process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development'
) {
// Create third part record for notifyreward in development and test ENVs
await queryRunner.query(`
INSERT INTO third_party(
"microService", secret, "isActive")
VALUES
('notifyreward', 'secret', true)
;
`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DELETE FROM third_party
WHERE "microService" = 'notifyreward';
`);
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notification-venter",
"version": "2.2.0",
"version": "2.3.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import {
CreateDateColumn,
Entity,
Index,
JoinTable,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
RelationId,
UpdateDateColumn,
} from 'typeorm';
import { NOTIFICATION_CATEGORY } from '../types/general';
import { NotificationSetting } from './notificationSetting';

// Export Object with Schemas to N1 lookup
export const SCHEMA_VALIDATORS_NAMES = {
SEND_EMAIL_CONFIRMATION: 'sendEmailConfirmation',
CREATE_ORTTO_PROFILE: 'createOrttoProfile',
SUBSCRIBE_ONBOARDING: 'subscribeOnboarding',
SUPERFLUID: 'userSuperTokensCritical',
ADMIN_MESSAGE: 'adminMessage',
RAW_HTML_BROADCAST: 'rawHtmlBroadcast',
Expand Down Expand Up @@ -68,6 +66,8 @@ export const SCHEMA_VALIDATORS_NAMES = {
PROJECT_HAS_A_NEW_RANK: 'projectHasANewRank',
PROJECT_HAS_RISEN_IN_THE_RANK: 'projectHasRisenInTheRank',
YOUR_PROJECT_GOT_A_RANK: 'yourProjectGotARank',

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

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 src/routes/v1/notificationRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '../../middlewares/authentication';
import { NotificationsController } from '../../controllers/v1/notificationsController';
import { sendStandardResponse } from '../../utils/responseUtils';
import { logger } from '../../utils/logger';
import { createNewUserAddressIfNotExists } from '../../repositories/userAddressRepository';

export const notificationRouter = express.Router();
Expand All @@ -22,6 +23,7 @@ notificationRouter.post(
});
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/thirdParty/notifications error', e);
next(e);
}
},
Expand All @@ -41,6 +43,7 @@ notificationRouter.post(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/thirdParty/notificationsBulk error', e);
next(e);
}
},
Expand All @@ -65,6 +68,7 @@ notificationRouter.get(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications error', e);
next(e);
}
},
Expand All @@ -85,6 +89,7 @@ notificationRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications/read/:notificationId error', e);
next(e);
}
},
Expand All @@ -100,6 +105,7 @@ notificationRouter.get(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications/countUnread/:walletAddress error', e);
next(e);
}
},
Expand All @@ -120,6 +126,7 @@ notificationRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications/readAll error', e);
next(e);
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/routes/v1/notificationSettingsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express, { Request, Response } from 'express';
import { validateAuthMicroserviceJwt } from '../../middlewares/authentication';
import { NotificationSettingsController } from '../../controllers/v1/notificationSettingsController';
import { sendStandardResponse } from '../../utils/responseUtils';
import { logger } from '../../utils/logger';

export const notificationSettingsRouter = express.Router();

Expand All @@ -25,6 +26,7 @@ notificationSettingsRouter.get(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('get /notification_settings error', e);
next(e);
}
},
Expand All @@ -47,6 +49,7 @@ notificationSettingsRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notification_settings/:id error', e);
next(e);
}
},
Expand All @@ -68,6 +71,7 @@ notificationSettingsRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('put /notification_settings error', e);
next(e);
}
},
Expand Down
Loading

0 comments on commit f6e4fe6

Please sign in to comment.