Skip to content
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
2 changes: 1 addition & 1 deletion .infra/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ debezium.source.database.user=%database_user%
debezium.source.database.password=%database_pass%
debezium.source.database.dbname=%database_dbname%
debezium.source.database.server.name=api
debezium.source.table.include.list=public.comment,public.user_comment,public.comment_mention,public.source_request,public.post,public.user,public.post_report,public.source_feed,public.settings,public.reputation_event,public.submission,public.user_state,public.notification_v2,public.source_member,public.feature,public.source,public.post_mention,public.content_image,public.comment_report,public.user_post,public.banner,public.post_relation,public.marketing_cta,public.squad_public_request,public.user_streak,public.bookmark,public.bookmark_list,public.user_company,public.source_report,public.user_top_reader,public.source_post_moderation,public.user_report,public.user_transaction,public.content_preference,public.campaign,public.opportunity_match,public.opportunity,public.organization,public.user_candidate_preference,public.user_experience,public.feedback,public.hot_take,public.user_stack,public.quest,public.quest_reward,public.quest_rotation,public.user_quest,public.user_quest_profile
debezium.source.table.include.list=public.comment,public.user_comment,public.comment_mention,public.source_request,public.post,public.user,public.post_report,public.source_feed,public.settings,public.reputation_event,public.submission,public.user_state,public.notification_v2,public.source_member,public.feature,public.source,public.post_mention,public.content_image,public.comment_report,public.user_post,public.banner,public.post_relation,public.marketing_cta,public.squad_public_request,public.user_streak,public.bookmark,public.bookmark_list,public.user_company,public.source_report,public.user_top_reader,public.source_post_moderation,public.user_report,public.user_transaction,public.content_preference,public.campaign,public.opportunity_match,public.opportunity,public.organization,public.user_candidate_preference,public.user_experience,public.feedback,public.hot_take,public.user_stack,public.quest,public.quest_reward,public.quest_rotation,public.user_quest,public.user_quest_profile,public.post_highlight
debezium.source.column.exclude.list=public.post.tsv,public.post.placeholder,public.source.flags,public.user_top_reader.image
debezium.source.skip.messages.without.change=true
debezium.source.plugin.name=pgoutput
Expand Down
69 changes: 69 additions & 0 deletions __tests__/workers/cdc/primary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CandidateStatus,
OpportunityState,
OpportunityType,
PostHighlightedMessage,
} from '@dailydotdev/schema';
import {
Achievement,
Expand Down Expand Up @@ -36,6 +37,8 @@ import {
Post,
PostKeyword,
PostMention,
PostHighlight,
PostHighlightSignificance,
PostRelation,
PostRelationType,
PostReport,
Expand Down Expand Up @@ -3209,6 +3212,72 @@ describe('marketing cta', () => {
});
});

describe('post highlight', () => {
type ObjectType = PostHighlight;

const base: ChangeObject<ObjectType> = {
id: 'ph_1',
channel: 'javascript',
postId: 'p1',
highlightedAt: 1_770_000_000_000_000,
headline: 'JavaScript in 2026',
significance: PostHighlightSignificance.Major,
reason: 'Fast ecosystem update',
retiredAt: null,
createdAt: 1_770_000_000_000_000,
updatedAt: 1_770_000_000_000_000,
};

beforeEach(() => {
jest.clearAllMocks();
});

it('should publish highlighted event on create', async () => {
await expectSuccessfulBackground(
worker,
mockChangeMessage<ObjectType>({
after: base,
before: null,
op: 'c',
table: 'post_highlight',
}),
);

expectTypedEvent(
'api.v1.post-highlighted',
new PostHighlightedMessage({
highlightId: base.id,
channel: base.channel,
postId: base.postId,
headline: base.headline,
significance: base.significance,
reason: base.reason ?? undefined,
highlightedAt: base.highlightedAt,
}),
);
});

it('should not publish highlighted event on update', async () => {
const after: ChangeObject<ObjectType> = {
...base,
headline: 'Updated headline',
updatedAt: 1_770_000_100_000_000,
};

await expectSuccessfulBackground(
worker,
mockChangeMessage<ObjectType>({
after,
before: base,
op: 'u',
table: 'post_highlight',
}),
);

expect(triggerTypedEvent).not.toHaveBeenCalled();
});
});

describe('squad public request', () => {
type ObjectType = SquadPublicRequest;
const base: ChangeObject<ObjectType> = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@connectrpc/connect-fastify": "^1.6.1",
"@connectrpc/connect-node": "^1.6.1",
"@dailydotdev/graphql-redis-subscriptions": "^2.4.3",
"@dailydotdev/schema": "0.3.3",
"@dailydotdev/schema": "0.3.6",
"@dailydotdev/ts-ioredis-pool": "^1.0.2",
"@fastify/cookie": "^11.0.2",
"@fastify/cors": "^11.2.0",
Expand Down
44 changes: 27 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/common/typedPubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
MatchedCandidate,
type OpportunityMessage,
type OpportunityPreviewResult,
PostHighlightedMessage,
RecruiterAcceptedCandidateMatchMessage,
type TransferResponse,
type UserBriefingRequest,
Expand Down Expand Up @@ -189,6 +190,7 @@ export type PubSubSchema = {
};
'skadi.v2.campaign-updated': CampaignUpdateEventArgs;
'api.v1.post-metrics-updated': z.infer<typeof postMetricsUpdatedTopic>;
'api.v1.post-highlighted': PostHighlightedMessage;
'api.v1.reputation-event': {
op: ChangeMessage<unknown>['payload']['op'];
payload: ChangeObject<ReputationEvent>;
Expand Down
37 changes: 36 additions & 1 deletion src/workers/cdc/primary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { OpportunityState, OpportunityType } from '@dailydotdev/schema';
import {
OpportunityState,
OpportunityType,
PostHighlightedMessage,
} from '@dailydotdev/schema';
import {
Alerts,
Banner,
Expand Down Expand Up @@ -44,6 +48,7 @@ import {
UserStreak,
UserTopReader,
Feedback,
PostHighlight,
} from '../../entity';
import { BookmarkList } from '../../entity/BookmarkList';
import { HotTake } from '../../entity/user/HotTake';
Expand Down Expand Up @@ -2444,6 +2449,33 @@ const onFeedbackChange = async (
}
};

const onPostHighlightChange = async (
con: DataSource,
logger: FastifyBaseLogger,
data: ChangeMessage<PostHighlight>,
) => {
if (data.payload.op !== 'c' || !data.payload.after) {
return;
}

const { id, channel, postId, headline, significance, reason, highlightedAt } =
data.payload.after;

await triggerTypedEvent(
logger,
'api.v1.post-highlighted',
new PostHighlightedMessage({
highlightId: id,
channel,
postId,
headline,
significance,
reason: reason ?? undefined,
highlightedAt,
}),
);
};

const onHotTakeChange = async (
con: DataSource,
logger: FastifyBaseLogger,
Expand Down Expand Up @@ -2713,6 +2745,9 @@ const worker: Worker = {
case getTableName(con, Feedback):
await onFeedbackChange(con, logger, data);
break;
case getTableName(con, PostHighlight):
await onPostHighlightChange(con, logger, data);
break;
case getTableName(con, HotTake):
await onHotTakeChange(con, logger, data);
break;
Expand Down
Loading