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

feat(notice): add write_challenge_announcement notice #150

Merged
merged 4 commits into from
Jul 26, 2024
Merged
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
35 changes: 33 additions & 2 deletions lib/__test__/notificationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('user notify setting', () => {
article_reported: true,
write_challenge_applied: true,
badge_grand_slam_awarded: true,
write_challenge_announcement: true,
}

test('user receives notifications', async () => {
Expand Down Expand Up @@ -207,14 +208,14 @@ describe('trigger notifications', () => {
})
})
test('trigger `badge_grand_slam_awarded` notice', async () => {
// no error
// no errors
await notificationService.trigger({
event: OFFICIAL_NOTICE_EXTEND_TYPE.badge_grand_slam_awarded,
recipientId: '1',
})
})
test('trigger `collection_liked` notice', async () => {
// no error
// no errors
await notificationService.trigger({
event: NOTICE_TYPE.collection_liked,
actorId: '1',
Expand All @@ -228,4 +229,34 @@ describe('trigger notifications', () => {
],
})
})
test('trigger `write_challenge_announcement` notice', async () => {
const [{ id: campaignId }] = await knex('campaign')
.insert({
type: 'writing_challenge',
creatorId: '1',
name: 'test',
description: 'test',
state: 'active',
shortHash: 'test-notice-hash',
})
.returning('id')
await knex('campaign_user').insert({
campaignId,
userId: '1',
state: 'succeeded',
})
// no errors
await notificationService.trigger({
event: OFFICIAL_NOTICE_EXTEND_TYPE.write_challenge_announcement,
data: {
link: 'https://example.com',
campaignId,
messages: {
zh_hant: 'zh-Hant message',
zh_hans: 'zh-Hans message',
en: 'en message',
},
},
})
})
})
3 changes: 2 additions & 1 deletion lib/notification/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export enum OFFICIAL_NOTICE_EXTEND_TYPE {
article_reported = 'article_reported',
comment_reported = 'comment_reported',
// write challenge related
write_challenge_applied = 'write_challenge_applied',
badge_grand_slam_awarded = 'badge_grand_slam_awarded',
write_challenge_applied = 'write_challenge_applied',
write_challenge_announcement = 'write_challenge_announcement',
}

export enum USER_ACTION {
Expand Down
Loading
Loading