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
55 changes: 55 additions & 0 deletions __tests__/workers/postUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,30 @@ it('save a post as private if source is private', async () => {
expect(posts[3].flags.private).toBe(true);
});

it('should save a new post with recommendation and quality signals', async () => {
await expectSuccessfulBackground(worker, {
id: 'f99a445f-e2fb-48e8-959c-e02a17f5e816',
title: 'Title',
url: 'https://post.com',
source_id: 'a',
extra: {
specificity: 'high',
intent: 'tutorial',
substance_depth: 'deep',
title_content_alignment: 'aligned',
self_promotion_score: 0.25,
},
});
const posts = await con.getRepository(Post).find();
expect(posts.length).toEqual(4);
const post = posts[3];
expect(post.flags.specificity).toEqual('high');
expect(post.flags.intent).toEqual('tutorial');
expect(post.flags.substanceDepth).toEqual('deep');
expect(post.flags.titleContentAlignment).toEqual('aligned');
expect(post.flags.selfPromotionScore).toEqual(0.25);
});

it('do not save post if source can not be found', async () => {
await expectSuccessfulBackground(worker, {
id: 'f99a445f-e2fb-48e8-959c-e02a17f5e816',
Expand Down Expand Up @@ -1325,6 +1349,37 @@ describe('on post update', () => {
});
});

it('should update post with recommendation and quality signals', async () => {
const postId = 'p1';

await con.getRepository(ArticlePost).save({
id: postId,
yggdrasilId: 'f99a445f-e2fb-48e8-959c-e02a17f5e816',
});

await expectSuccessfulBackground(worker, {
id: 'f99a445f-e2fb-48e8-959c-e02a17f5e816',
post_id: postId,
extra: {
specificity: 'medium',
intent: 'reference',
substance_depth: 'surface',
title_content_alignment: 'misaligned',
self_promotion_score: 0.75,
},
});

const updatedPost = await con.getRepository(ArticlePost).findOneBy({
id: postId,
});

expect(updatedPost?.flags.specificity).toEqual('medium');
expect(updatedPost?.flags.intent).toEqual('reference');
expect(updatedPost?.flags.substanceDepth).toEqual('surface');
expect(updatedPost?.flags.titleContentAlignment).toEqual('misaligned');
expect(updatedPost?.flags.selfPromotionScore).toEqual(0.75);
});

describe('vordr', () => {
it('should vordr post based on title', async () => {
const uuid = randomUUID();
Expand Down
7 changes: 7 additions & 0 deletions src/entity/posts/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export type PostFlags = Partial<{
savedTime: number;
generatedAt: Date;
dedupKey: string;
// Recommendation signals
specificity: string;
intent: string;
// Quality signals
substanceDepth: string;
titleContentAlignment: string;
selfPromotionScore: number;
}>;

export type PostFlagsPublic = Pick<
Expand Down
10 changes: 10 additions & 0 deletions src/workers/postUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ interface Data {
content: string;
video_id?: string;
duration?: number;
specificity?: string;
intent?: string;
substance_depth?: string;
title_content_alignment?: string;
self_promotion_score?: number;
};
meta?: {
scraped_html?: string;
Expand Down Expand Up @@ -607,6 +612,11 @@ const fixData = async ({
private: privacy,
showOnFeed: !data?.order,
sentAnalyticsReport: privacy || !authorId,
specificity: data?.extra?.specificity,
intent: data?.extra?.intent,
substanceDepth: data?.extra?.substance_depth,
titleContentAlignment: data?.extra?.title_content_alignment,
selfPromotionScore: data?.extra?.self_promotion_score,
},
yggdrasilId: data?.id,
type: data?.content_type as PostType,
Expand Down
Loading