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: vordr on posts #2108

Merged
merged 27 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ac2c872
refactor: `checkWithVordr` accepts posts too
omBratteng Aug 6, 2024
8f2f709
feat: vordr check freeform posts
omBratteng Aug 8, 2024
c92c45e
feat: hide posts that vordr prevented
omBratteng Aug 8, 2024
3d43c39
feat: don't send notification if vordr prevented post
omBratteng Aug 8, 2024
7f6ebed
feat: add vordr check to share post
omBratteng Aug 8, 2024
fd61d23
fix: use transaction connection and pass ctx for checkWithVordr
omBratteng Aug 8, 2024
e130498
test: fix vordr test
omBratteng Aug 8, 2024
0ef5432
feat: set vordr flag on submissions
omBratteng Aug 8, 2024
e83770a
fix: return false if there is no content to validate
omBratteng Aug 8, 2024
10f2d71
feat: vordr on comment edit and add tests
omBratteng Aug 8, 2024
6e2d3ff
test: fix submission test
omBratteng Aug 8, 2024
ed4bef9
test: don't send notification if vordr prevented post
omBratteng Aug 8, 2024
fa9be9c
test: set vordr flag on submissions
omBratteng Aug 8, 2024
9a64646
test: add vordr check to share post
omBratteng Aug 8, 2024
44a3ee5
test: hide posts that vordr prevented
omBratteng Aug 8, 2024
58c8f70
fix: remove commented out code
omBratteng Aug 9, 2024
e7c39e2
fix: also set flags
omBratteng Aug 9, 2024
5302d79
test: add specific posts for vordr tests in feed
omBratteng Aug 9, 2024
fe7501c
test: rename some tests
omBratteng Aug 9, 2024
2d96512
test: rename some more tests
omBratteng Aug 9, 2024
c2faa3f
test: rename some more tests 2
omBratteng Aug 9, 2024
ee7a0f6
test: rename some more tests 3
omBratteng Aug 9, 2024
e72e61c
fix: use spread on flags
omBratteng Aug 12, 2024
1be8aca
fix: use vordr flag on community picks feed to
omBratteng Aug 12, 2024
3f18fe7
refactor: pass id, type and content to `checkWithVordr` instead of en…
omBratteng Aug 12, 2024
629216b
Revert "fix: use vordr flag on community picks feed to"
omBratteng Aug 13, 2024
c94f146
Merge branch 'main' into AS-463-vordr-posts
omBratteng Aug 13, 2024
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
72 changes: 69 additions & 3 deletions __tests__/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,23 @@ describe('mutation commentOnPost', () => {
expect(comment.flags).toEqual({ vordr: false });
});

it('should set correct vordr flags on bad user', async () => {
it('should set correct vordr flags on comment by good user if vordr filter catches it', async () => {
loggedUser = '1';

const res = await client.mutate(MUTATION, {
variables: { postId: 'p1', content: 'VordrWillCatchYou' },
});

expect(res.errors).toBeFalsy();

const comment = await con.getRepository(Comment).findOneByOrFail({
id: res.data.commentOnPost.id,
});

expect(comment.flags).toEqual({ vordr: true });
});

it('should set correct vordr flags on comment by bad user', async () => {
loggedUser = 'vordr';

const res = await client.mutate(MUTATION, {
Expand Down Expand Up @@ -1192,7 +1208,7 @@ describe('mutation commentOnComment', () => {
});

describe('vordr', () => {
it('should set correct vordr flags on good user', async () => {
it('should set correct vordr flags on comment reply by good user', async () => {
loggedUser = '1';

const res = await client.mutate(MUTATION, {
Expand All @@ -1208,7 +1224,23 @@ describe('mutation commentOnComment', () => {
expect(comment.flags).toEqual({ vordr: false });
});

it('should set correct vordr flags on bad user', async () => {
it('should set correct vordr flags on comment reply by good user if vordr filter catches it', async () => {
loggedUser = '1';

const res = await client.mutate(MUTATION, {
variables: { commentId: 'c1', content: 'VordrWillCatchYou' },
});

expect(res.errors).toBeFalsy();

const comment = await con.getRepository(Comment).findOneByOrFail({
id: res.data.commentOnComment.id,
});

expect(comment.flags).toEqual({ vordr: true });
});

it('should set correct vordr flags on comment reply by bad user', async () => {
loggedUser = 'vordr';

const res = await client.mutate(MUTATION, {
Expand Down Expand Up @@ -1440,6 +1472,40 @@ describe('mutation editComment', () => {
content: 'Edit',
});
});

describe('vordr', () => {
it('should set correct vordr flags on edited comment by good user', async () => {
loggedUser = '1';

const res = await client.mutate(MUTATION, {
variables: { id: 'c2', content: 'comment' },
});

expect(res.errors).toBeFalsy();

const comment = await con.getRepository(Comment).findOneByOrFail({
id: res.data.editComment.id,
});

expect(comment.flags).toEqual({ vordr: false });
});

it('should set correct vordr flags on edited comment by good user if vordr filter catches it', async () => {
loggedUser = '1';

const res = await client.mutate(MUTATION, {
variables: { id: 'c2', content: 'VordrWillCatchYou' },
});

expect(res.errors).toBeFalsy();

const comment = await con.getRepository(Comment).findOneByOrFail({
id: res.data.editComment.id,
});

expect(comment.flags).toEqual({ vordr: true });
});
});
});

describe('mutation reportComment', () => {
Expand Down
122 changes: 85 additions & 37 deletions __tests__/common/vordr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { DataSource } from 'typeorm';
import createOrGetConnection from '../../src/db';
import { Comment, Post, Source, User } from '../../src/entity';
import { badUsersFixture, sourcesFixture, usersFixture } from '../fixture';
import { checkWithVordr } from '../../src/common/vordr';
import { Context } from '../../src/Context';
import { checkWithVordr, VordrFilterType } from '../../src/common/vordr';
import { postsFixture } from '../fixture/post';
import { saveFixtures } from '../helpers';

Expand Down Expand Up @@ -50,11 +49,18 @@ describe('commmon/vordr', () => {
.getRepository(Comment)
.findOneByOrFail({ id: 'c1' });

const result = await checkWithVordr(comment, {
req: { ip: '127.0.0.1' },
userId: 'vordr',
con,
} as Context);
const result = await checkWithVordr(
{
id: comment.id,
type: VordrFilterType.Comment,
content: comment.content,
},
{
req: { ip: '127.0.0.1' },
userId: 'vordr',
con,
},
);

expect(result).toBeTruthy();
});
Expand All @@ -64,11 +70,18 @@ describe('commmon/vordr', () => {
.getRepository(Comment)
.findOneByOrFail({ id: 'c1' });

const result = await checkWithVordr(comment, {
req: { ip: '127.0.0.1' },
userId: 'low-score',
con,
} as Context);
const result = await checkWithVordr(
{
id: comment.id,
type: VordrFilterType.Comment,
content: comment.content,
},
{
req: { ip: '127.0.0.1' },
userId: 'low-score',
con,
},
);

expect(result).toBeTruthy();
});
Expand All @@ -78,11 +91,18 @@ describe('commmon/vordr', () => {
.getRepository(Comment)
.findOneByOrFail({ id: 'c1' });

const result = await checkWithVordr(comment, {
req: { ip: '192.0.2.1' },
userId: '1',
con,
} as Context);
const result = await checkWithVordr(
{
id: comment.id,
type: VordrFilterType.Comment,
content: comment.content,
},
{
req: { ip: '192.0.2.1' },
userId: '1',
con,
},
);

expect(result).toBeTruthy();
});
Expand All @@ -92,11 +112,18 @@ describe('commmon/vordr', () => {
.getRepository(Comment)
.findOneByOrFail({ id: 'c2' });

const result = await checkWithVordr(comment, {
req: { ip: '127.0.0.1' },
userId: '1',
con,
} as Context);
const result = await checkWithVordr(
{
id: comment.id,
type: VordrFilterType.Comment,
content: comment.content,
},
{
req: { ip: '127.0.0.1' },
userId: '1',
con,
},
);

expect(result).toBeTruthy();
});
Expand All @@ -106,11 +133,18 @@ describe('commmon/vordr', () => {
.getRepository(Comment)
.findOneByOrFail({ id: 'c1' });

const result = await checkWithVordr(comment, {
req: { ip: '127.0.0.1' },
userId: 'low-reputation',
con,
} as Context);
const result = await checkWithVordr(
{
id: comment.id,
type: VordrFilterType.Comment,
content: comment.content,
},
{
req: { ip: '127.0.0.1' },
userId: 'low-reputation',
con,
},
);

expect(result).toBeTruthy();
});
Expand All @@ -120,11 +154,18 @@ describe('commmon/vordr', () => {
.getRepository(Comment)
.findOneByOrFail({ id: 'c1' });

const result = await checkWithVordr(comment, {
req: { ip: '127.0.0.1' },
userId: '1',
con,
} as Context);
const result = await checkWithVordr(
{
id: comment.id,
type: VordrFilterType.Comment,
content: comment.content,
},
{
req: { ip: '127.0.0.1' },
userId: '1',
con,
},
);

expect(result).toBeFalsy();
});
Expand All @@ -134,11 +175,18 @@ describe('commmon/vordr', () => {
.getRepository(Comment)
.findOneByOrFail({ id: 'c1' });

const result = await checkWithVordr(comment, {
req: { ip: '127.0.0.1' },
userId: '1',
con,
} as Context);
const result = await checkWithVordr(
{
id: comment.id,
type: VordrFilterType.Comment,
content: comment.content,
},
{
req: { ip: '127.0.0.1' },
userId: '1',
con,
},
);

expect(result).toBeFalsy();
});
Expand Down
52 changes: 52 additions & 0 deletions __tests__/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,58 @@ describe('query sourceFeed', () => {
'FORBIDDEN',
);
});

describe('vordr', () => {
beforeEach(async () => {
await saveFixtures(con, ArticlePost, [
{
id: 'vordr1',
shortId: 'svordr1',
title: 'vordr1',
url: 'http://vordr1.com',
image: 'https://daily.dev/image.jpg',
score: 10,
sourceId: 'b',
createdAt: new Date(new Date().getTime() - 4000),
tagsStr: 'html,javascript',
type: PostType.Article,
contentCuration: ['c1', 'c2'],
authorId: '2',
flags: { vordr: true },
},
{
id: 'vordr2',
shortId: 'svordr2',
title: 'vordr2',
url: 'http://vordr2.com',
image: 'https://daily.dev/image.jpg',
score: 10,
sourceId: 'b',
createdAt: new Date(new Date().getTime() - 4000),
tagsStr: 'html,javascript',
type: PostType.Article,
contentCuration: ['c1', 'c2'],
authorId: '2',
flags: { vordr: true },
},
]);
});
it('should filter out posts that vordr has prevented', async () => {
loggedUser = '1';

const res = await client.query(QUERY('b'));

expect(res.data.sourceFeed.edges.length).toBe(2);
});

it('should not filter out posts that vordr has prevented when author is viewer', async () => {
loggedUser = '2';

const res = await client.query(QUERY('b'));

expect(res.data.sourceFeed.edges.length).toBe(4);
});
});
});

describe('query tagFeed', () => {
Expand Down
Loading
Loading