Skip to content

Commit

Permalink
test: add missed tests in #2136
Browse files Browse the repository at this point in the history
  • Loading branch information
omBratteng committed Aug 13, 2024
1 parent cda0608 commit 0588e2a
Showing 1 changed file with 154 additions and 0 deletions.
154 changes: 154 additions & 0 deletions __tests__/workers/postUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,72 @@ 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, {
// id: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
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, {
// id: '90660dab-7cd1-49f0-8fe5-41c587ca837f',
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 +1264,94 @@ 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);
expect(updatedPost.flags.banned).toBeUndefined();
expect(updatedPost.showOnFeed).toEqual(true);
expect(updatedPost.flags.showOnFeed).toEqual(true);
});
});
});

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

0 comments on commit 0588e2a

Please sign in to comment.