Skip to content

Commit 1c60371

Browse files
authored
refactor: remove deprecated community picks granted notification (#3367)
1 parent 2486cae commit 1c60371

17 files changed

Lines changed: 13 additions & 241 deletions

File tree

.infra/common.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ export const workers: Worker[] = [
169169
topic: 'community-link-rejected',
170170
subscription: 'api.community-picks-failed-notification',
171171
},
172-
{
173-
topic: 'community-link-access',
174-
subscription: 'api.community-picks-granted-notification',
175-
},
176172
{
177173
topic: 'post-commented',
178174
subscription: 'api.article-new-comment-notification.post-commented',

__tests__/notifications/index.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
generateNotificationV2,
33
type NotificationAwardContext,
4-
NotificationBaseContext,
54
NotificationBookmarkContext,
65
NotificationBundleV2,
76
type NotificationCampaignContext,
@@ -57,7 +56,6 @@ import {
5756
createSquadWelcomePost,
5857
emptyImage,
5958
notificationsLink,
60-
scoutArticleLink,
6159
squadsFeaturedPage,
6260
} from '../../src/common';
6361
import { usersFixture } from '../fixture/user';
@@ -213,21 +211,6 @@ describe('generateNotification', () => {
213211
]);
214212
});
215213

216-
it('should generate community_picks_granted notification', () => {
217-
const type = NotificationType.CommunityPicksGranted;
218-
const ctx: NotificationBaseContext = { userIds: [userId] };
219-
const actual = generateNotificationV2(type, ctx);
220-
221-
expect(actual.notification.type).toEqual(type);
222-
expect(actual.userIds).toEqual([userId]);
223-
expect(actual.notification.public).toEqual(true);
224-
expect(actual.notification.referenceId).toEqual('system');
225-
expect(actual.notification.referenceType).toEqual('system');
226-
expect(actual.notification.targetUrl).toEqual(scoutArticleLink);
227-
expect(actual.avatars.length).toEqual(0);
228-
expect(actual.attachments.length).toEqual(0);
229-
});
230-
231214
it('should generate article_picked notification', () => {
232215
const type = NotificationType.ArticlePicked;
233216
const ctx: NotificationPostContext = {

__tests__/workers/cdc/notifications.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('notification', () => {
2222
const id = randomUUID();
2323
const base: ChangeObject<ObjectType> = {
2424
id,
25-
type: NotificationType.CommunityPicksGranted,
25+
type: NotificationType.CommunityPicksSucceeded,
2626
title: 'hello',
2727
targetUrl: 'target',
2828
icon: 'icon',

__tests__/workers/cdc/primary.ts

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ import {
6060
UserMarketingCta,
6161
UserNotification,
6262
UserPost,
63-
UserState,
64-
UserStateKey,
6563
UserStreak,
6664
UserStreakAction,
6765
UserStreakActionType,
@@ -103,7 +101,6 @@ import {
103101
notifySourcePrivacyUpdated,
104102
notifySourceReport,
105103
notifySquadFeaturedUpdated,
106-
notifySubmissionGrantedAccess,
107104
notifySubmissionRejected,
108105
notifyUsernameChanged,
109106
notifyUserReadmeUpdated,
@@ -131,7 +128,6 @@ import {
131128
import { randomUUID } from 'crypto';
132129
import { DataSource, Not } from 'typeorm';
133130
import createOrGetConnection from '../../../src/db';
134-
import { TypeOrmError } from '../../../src/errors';
135131
import { SourceMemberRoles } from '../../../src/roles';
136132
import { CommentReport } from '../../../src/entity/CommentReport';
137133
import { badUsersFixture, usersFixture } from '../../fixture/user';
@@ -216,7 +212,6 @@ jest.mock('../../../src/common', () => ({
216212
notifySourceFeedRemoved: jest.fn(),
217213
notifySettingsUpdated: jest.fn(),
218214
notifySubmissionRejected: jest.fn(),
219-
notifySubmissionGrantedAccess: jest.fn(),
220215
notifyNewPostMention: jest.fn(),
221216
notifyNewCommentMention: jest.fn(),
222217
notifyNewNotification: jest.fn(),
@@ -843,52 +838,6 @@ describe('user', () => {
843838
table: 'user',
844839
}),
845840
);
846-
const [state] = await con.getRepository(UserState).find();
847-
expect(state?.key).toEqual(UserStateKey.CommunityLinkAccess);
848-
});
849-
850-
it('should throw an error when creating user state and not related to duplicate entry', async () => {
851-
const after: ChangeObject<ObjectType> = {
852-
...base,
853-
reputation: submissionAccessThreshold,
854-
};
855-
after.id = '1234567890123456789012345678901234567'; // 37 characters - exceeds limit
856-
try {
857-
await expectSuccessfulBackground(
858-
worker,
859-
mockChangeMessage<ObjectType>({
860-
after,
861-
before: base,
862-
op: 'u',
863-
table: 'user',
864-
}),
865-
);
866-
expect(true).toBeFalsy(); // ensure the worker threw an error and not reach this code
867-
} catch (ex) {
868-
const state = await con.getRepository(UserState).find();
869-
expect(state.length).toEqual(0);
870-
expect(ex.code).not.toEqual(TypeOrmError.DUPLICATE_ENTRY);
871-
}
872-
});
873-
874-
it('should handle the thrown error when user state already exists', async () => {
875-
const after: ChangeObject<ObjectType> = {
876-
...base,
877-
reputation: submissionAccessThreshold,
878-
};
879-
const repo = con.getRepository(UserState);
880-
await repo.save({ userId: '1', key: UserStateKey.CommunityLinkAccess });
881-
await expectSuccessfulBackground(
882-
worker,
883-
mockChangeMessage<ObjectType>({
884-
after,
885-
before: base,
886-
op: 'u',
887-
table: 'user',
888-
}),
889-
);
890-
const state = await con.getRepository(UserState).find();
891-
expect(state.length).toEqual(1);
892841
});
893842

894843
it('should call notifyReputationIncrease when the user reputation has increased', async () => {
@@ -1134,28 +1083,6 @@ describe('user', () => {
11341083
});
11351084
});
11361085

1137-
describe('user_state', () => {
1138-
type ObjectType = UserState;
1139-
it('should notify on user state is created with the right key', async () => {
1140-
await expectSuccessfulBackground(
1141-
worker,
1142-
mockChangeMessage<ObjectType>({
1143-
after: {
1144-
userId: defaultUser.id,
1145-
key: UserStateKey.CommunityLinkAccess,
1146-
value: false,
1147-
},
1148-
op: 'c',
1149-
table: 'user_state',
1150-
}),
1151-
);
1152-
expect(notifySubmissionGrantedAccess).toHaveBeenCalledTimes(1);
1153-
expect(
1154-
jest.mocked(notifySubmissionGrantedAccess).mock.calls[0].slice(1),
1155-
).toEqual(['1']);
1156-
});
1157-
});
1158-
11591086
describe('comment mention', () => {
11601087
type ObjectType = CommentMention;
11611088
const base: ChangeObject<ObjectType> = {

__tests__/workers/newNotificationV2Mail.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import { usersFixture } from '../fixture/user';
4949
import { DataSource } from 'typeorm';
5050
import createOrGetConnection from '../../src/db';
5151
import {
52-
NotificationBaseContext,
5352
NotificationCampaignContext,
5453
NotificationCollectionContext,
5554
NotificationCommentContext,
@@ -205,29 +204,6 @@ it('should set parameters for community_picks_succeeded email', async () => {
205204
expect(args.transactional_message_id).toEqual('27');
206205
});
207206

208-
it('should set parameters for community_picks_granted email', async () => {
209-
const ctx: NotificationBaseContext = {
210-
userIds: ['1'],
211-
};
212-
213-
const notificationId = await saveNotificationV2Fixture(
214-
con,
215-
NotificationType.CommunityPicksGranted,
216-
ctx,
217-
);
218-
await expectSuccessfulBackground(worker, {
219-
notification: {
220-
id: notificationId,
221-
userId: '1',
222-
},
223-
});
224-
expect(sendEmail).toHaveBeenCalledTimes(1);
225-
const args = jest.mocked(sendEmail).mock
226-
.calls[0][0] as SendEmailRequestWithTemplate;
227-
expect(args.message_data).toEqual({});
228-
expect(args.transactional_message_id).toEqual('26');
229-
});
230-
231207
it('should set parameters for article_picked email', async () => {
232208
const post = await con.getRepository(ArticlePost).save(postsFixture[0]);
233209
const ctx: NotificationPostContext = {

__tests__/workers/notifications.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ import { commentReply } from '../../src/workers/notifications/commentReply';
7676
import { commentUpvoteMilestone } from '../../src/workers/notifications/commentUpvoteMilestone';
7777
import { communityPicksFailed } from '../../src/workers/notifications/communityPicksFailed';
7878
import { SubmissionFailErrorKeys } from '../../src/errors';
79-
import { communityPicksGranted } from '../../src/workers/notifications/communityPicksGranted';
8079
import { devCardUnlocked } from '../../src/workers/notifications/devCardUnlocked';
8180
import { postAdded } from '../../src/workers/notifications/postAdded';
8281
import { postMention } from '../../src/workers/notifications/postMention';
@@ -138,20 +137,6 @@ it('should add community picks failed notification', async () => {
138137
});
139138
});
140139

141-
it('should add community picks granted notification', async () => {
142-
const actual = await invokeTypedNotificationWorker<'community-link-access'>(
143-
communityPicksGranted,
144-
{
145-
userId: '1',
146-
},
147-
);
148-
expect(actual.length).toEqual(1);
149-
expect(actual[0].type).toEqual('community_picks_granted');
150-
expect(actual[0].ctx).toEqual({
151-
userIds: ['1'],
152-
});
153-
});
154-
155140
it('should add devcard unlocked notification if user has reached the reputation threshold', async () => {
156141
const actual = await invokeTypedNotificationWorker<'user-reputation-updated'>(
157142
devCardUnlocked,

src/common/pubsub.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const viewsTopic = pubsub.topic('views');
4848
const postBannedOrRemovedTopic = pubsub.topic('post-banned-or-removed');
4949
const sourceFeedAddedTopic = pubsub.topic('source-feed-added');
5050
const sourceFeedRemovedTopic = pubsub.topic('source-feed-removed');
51-
const communityLinkAccessTopic = pubsub.topic('community-link-access');
5251
const communityLinkRejectedTopic = pubsub.topic('community-link-rejected');
5352
const newNotificationTopic = pubsub.topic('api.v1.new-notification');
5453
const newPostMentionTopic = pubsub.topic('api.v1.new-post-mention');
@@ -272,11 +271,6 @@ export const notifySubmissionRejected = async (
272271
submission: ChangeObject<Submission>,
273272
): Promise<void> => publishEvent(log, communityLinkRejectedTopic, submission);
274273

275-
export const notifySubmissionGrantedAccess = async (
276-
log: EventLogger,
277-
userId: string,
278-
): Promise<void> => publishEvent(log, communityLinkAccessTopic, { userId });
279-
280274
export const notifySourceMemberRoleChanged = async (
281275
log: EventLogger,
282276
previousRole: SourceMemberRoles,

src/common/typedPubsub.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,6 @@ export type PubSubSchema = {
210210
commentMention: ChangeObject<CommentMention>;
211211
};
212212
'community-link-rejected': ChangeObject<Submission>;
213-
'community-link-access': {
214-
userId: string;
215-
};
216213
'user-reputation-updated': {
217214
user: ChangeObject<User>;
218215
userAfter: ChangeObject<User>;

src/entity/user/UserState.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/entity/user/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './User';
22
export * from './UserPost';
3-
export * from './UserState';
43
export * from './UserAction';
54
export * from './UserStreak';
65
export * from './UserStreakAction';

0 commit comments

Comments
 (0)