Skip to content

Commit 3ffb443

Browse files
authored
feat: add reason reporting test (#2948)
1 parent 471d9ac commit 3ffb443

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

__tests__/workers/postUpdated.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,66 @@ it('should not update already approved post', async () => {
746746
expect(submission.status).toEqual(SubmissionStatus.Accepted);
747747
});
748748

749+
it('should update post after it was rejected first', async () => {
750+
const uuid = randomUUID();
751+
await createDefaultUser();
752+
await createDefaultSubmission(uuid);
753+
754+
const postId = await generateShortId();
755+
756+
await con.getRepository(FreeformPost).save({
757+
id: postId,
758+
shortId: postId,
759+
title: 'Title',
760+
url: 'https://post.com',
761+
sourceId: 'a',
762+
});
763+
764+
await expectSuccessfulBackground(worker, {
765+
id: 'f99a445f-e2fb-48e8-959c-e02a17f5e816',
766+
title: 'Title',
767+
url: 'https://post.com',
768+
source_id: 'a',
769+
submission_id: uuid,
770+
reject_reason: SubmissionFailErrorMessage.GENERIC_ERROR,
771+
post_id: postId,
772+
});
773+
const submissions = await con.getRepository(Submission).find();
774+
const [submission] = submissions;
775+
expect(submissions.length).toEqual(1);
776+
expect(submission.id).toEqual(uuid);
777+
expect(submission.status).toEqual(SubmissionStatus.Rejected);
778+
779+
const postBefore = await con.getRepository(Post).findOneBy({ id: postId });
780+
expect(postBefore).not.toBeNull();
781+
782+
expect(postBefore!.title).toEqual('Title');
783+
expect(postBefore!.yggdrasilId).toBeNull();
784+
785+
await expectSuccessfulBackground(worker, {
786+
id: 'f99a445f-e2fb-48e8-959c-e02a17f5e816',
787+
title: 'Title 2',
788+
url: 'https://post.com',
789+
source_id: 'a',
790+
submission_id: uuid,
791+
post_id: postId,
792+
});
793+
794+
const updatedSubmissions = await con.getRepository(Submission).find();
795+
const [updatedSubmission] = updatedSubmissions;
796+
expect(updatedSubmissions.length).toEqual(1);
797+
expect(updatedSubmission.id).toEqual(uuid);
798+
expect(updatedSubmission.status).toEqual(SubmissionStatus.Accepted);
799+
800+
const post = await con.getRepository(Post).findOneBy({
801+
id: postId,
802+
});
803+
expect(post).not.toBeNull();
804+
805+
expect(post!.yggdrasilId).toEqual('f99a445f-e2fb-48e8-959c-e02a17f5e816');
806+
expect(post!.title).toEqual('Title 2');
807+
});
808+
749809
describe('on post create', () => {
750810
beforeEach(async () => {
751811
await createDefaultUser();

0 commit comments

Comments
 (0)