-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from Giveth/4194-add-unit-test-and-debug
Add unit tests for notify reward amount
- Loading branch information
Showing
11 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
migrations/1720553769343-changeMicroserviceAndCategoryOfNotifyRewardNotificationType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { activityCreator } from './notificationService'; | ||
import { NOTIFICATIONS_EVENT_NAMES } from '../types/notifications'; | ||
import { expect } from 'chai'; | ||
|
||
describe('activityCreator', () => { | ||
it('should create attributes for NOTIFY_REWARD_AMOUNT', () => { | ||
const payload = { | ||
round: 1, | ||
date: '2024-06-01', | ||
amount: '1000', | ||
contractAddress: '0x123', | ||
farm: 'Test Farm', | ||
message: 'Test Message', | ||
network: 'Test Network', | ||
script: 'Test Script', | ||
transactionHash: '0xabc', | ||
email: 'test@example.com' | ||
}; | ||
const result = activityCreator(payload, NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT); | ||
expect(JSON.stringify(result)).equal(JSON.stringify({ | ||
activities: [ | ||
{ | ||
activity_id: "act:cm:notify-reward-amount", | ||
attributes: { | ||
'int:cm:round': payload.round, | ||
'str:cm:date': payload.date, | ||
'str:cm:amount': payload.amount, | ||
'str:cm:contractaddress': payload.contractAddress, | ||
'str:cm:farm': payload.farm, | ||
'str:cm:message': payload.message, | ||
'str:cm:network': payload.network, | ||
'str:cm:script': payload.script, | ||
'str:cm:transactionhash': payload.transactionHash, | ||
}, | ||
fields: { | ||
'str::email': payload.email, | ||
}, | ||
}, | ||
], | ||
merge_by: ['str::email'], | ||
})); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters