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

test: add missed tests in #2136 #2137

Merged
merged 4 commits into from
Aug 13, 2024
Merged
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
199 changes: 199 additions & 0 deletions __tests__/workers/postUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,70 @@ describe('on post create', () => {
expect(post).not.toBeNull();
expect(post?.contentQuality).toStrictEqual({});
});

describe('vordr', () => {
it('should create post with the vordr flags on submission with bad scout', async () => {
const uuid = randomUUID();
await saveFixtures(con, Submission, [
{
id: uuid,
url: 'http://vordr.com/test',
userId: '1',
flags: {
vordr: true,
},
},
]);

await expectSuccessfulBackground(worker, {
title: 'Title',
url: 'http://vordr.com/test',
source_id: COMMUNITY_PICKS_SOURCE,
submission_id: uuid,
});

const post = await con.getRepository(ArticlePost).findOneByOrFail({
url: 'http://vordr.com/test',
});

expect(post.flags.vordr).toEqual(true);
expect(post.banned).toEqual(true);
expect(post.flags.banned).toEqual(true);
expect(post.showOnFeed).toEqual(false);
expect(post.flags.showOnFeed).toEqual(false);
});

it('should create post with the vordr flags on submission with good scout', async () => {
const uuid = randomUUID();
await saveFixtures(con, Submission, [
{
id: uuid,
url: 'http://vordr.com/test',
userId: '1',
flags: {
vordr: false,
},
},
]);

await expectSuccessfulBackground(worker, {
title: 'Title',
url: 'http://vordr.com/test',
source_id: COMMUNITY_PICKS_SOURCE,
submission_id: uuid,
});

const post = await con.getRepository(ArticlePost).findOneByOrFail({
url: 'http://vordr.com/test',
});

expect(post.flags.vordr).toEqual(false);
expect(post.banned).toEqual(false);
expect(post.flags.banned).toBeUndefined();
expect(post.showOnFeed).toEqual(true);
expect(post.flags.showOnFeed).toEqual(true);
});
});
});

describe('on post update', () => {
Expand Down Expand Up @@ -1198,6 +1262,141 @@ describe('on post update', () => {
expect(post2).toBeTruthy();
expect(post2!.scoutId).toEqual('1');
});

describe('vordr', () => {
it('should update post with the vordr flags on submission with bad scout', async () => {
const uuid = randomUUID();
const postId = 'vordr3';
await saveFixtures(con, Submission, [
{
id: uuid,
url: 'http://vordr.com/test',
userId: '1',
flags: {
vordr: true,
},
},
]);

await con.getRepository(ArticlePost).save({
id: postId,
shortId: postId,
url: 'https://post.com/scp1',
title: 'Scouted title',
visible: false,
yggdrasilId: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
sourceId: COMMUNITY_PICKS_SOURCE,
});

await expectSuccessfulBackground(worker, {
id: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
post_id: postId,
url: 'http://vordr.com/test',
source_id: COMMUNITY_PICKS_SOURCE,
submission_id: uuid,
});

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

expect(updatedPost.flags.vordr).toEqual(true);
expect(updatedPost.banned).toEqual(true);
expect(updatedPost.flags.banned).toEqual(true);
expect(updatedPost.showOnFeed).toEqual(false);
expect(updatedPost.flags.showOnFeed).toEqual(false);
});

it('should update post with the vordr flags on submission with good scout', async () => {
const uuid = randomUUID();
const postId = 'vordr3';
await saveFixtures(con, Submission, [
{
id: uuid,
url: 'http://vordr.com/test',
userId: '1',
flags: {
vordr: false,
},
},
]);

await con.getRepository(ArticlePost).save({
id: postId,
shortId: postId,
url: 'https://post.com/scp1',
title: 'Scouted title',
visible: false,
yggdrasilId: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
sourceId: COMMUNITY_PICKS_SOURCE,
});

await expectSuccessfulBackground(worker, {
id: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
post_id: postId,
url: 'http://vordr.com/test',
source_id: COMMUNITY_PICKS_SOURCE,
submission_id: uuid,
});

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

expect(updatedPost.flags.vordr).toEqual(false);
expect(updatedPost.banned).toEqual(false);
Comment on lines +1346 to +1347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add expect to make sure if post had some other flags they did not get overwritten.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added extra test, does that work?

expect(updatedPost.flags.banned).toBeUndefined();
expect(updatedPost.showOnFeed).toEqual(true);
expect(updatedPost.flags.showOnFeed).toEqual(true);
});

it('should update post with the vordr flag but keep original flags', async () => {
const uuid = randomUUID();
const postId = 'vordr3';
await saveFixtures(con, Submission, [
{
id: uuid,
url: 'http://vordr.com/test',
userId: '1',
flags: {
vordr: false,
},
},
]);

await con.getRepository(ArticlePost).save({
id: postId,
shortId: postId,
url: 'https://post.com/scp1',
title: 'Scouted title',
visible: false,
yggdrasilId: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
sourceId: COMMUNITY_PICKS_SOURCE,
flags: {
promoteToPublic: 1,
banned: true,
showOnFeed: true,
},
});

await expectSuccessfulBackground(worker, {
id: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
post_id: postId,
url: 'http://vordr.com/test',
source_id: COMMUNITY_PICKS_SOURCE,
submission_id: uuid,
});

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

expect(updatedPost.flags.vordr).toEqual(false);
expect(updatedPost.flags.banned).toEqual(true);
expect(updatedPost.flags.showOnFeed).toEqual(true);
expect(updatedPost.flags.promoteToPublic).toEqual(1);
});
});
});

describe('on youtube post', () => {
Expand Down
Loading