From 64393107802f41cb75f6b734df3215b44199f97e Mon Sep 17 00:00:00 2001 From: Chris Bongers Date: Tue, 13 Aug 2024 17:32:28 +0200 Subject: [PATCH] fix: don't show non visible community picks (#2139) --- __tests__/submissions.ts | 31 +++++++++++++++++++++++++++++++ src/schema/submissions.ts | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/__tests__/submissions.ts b/__tests__/submissions.ts index baec83223..7a61aaf73 100644 --- a/__tests__/submissions.ts +++ b/__tests__/submissions.ts @@ -300,6 +300,37 @@ describe('mutation submitArticle', () => { }); }); + it('should reject if the post exist but not visible', async () => { + loggedUser = '1'; + const request = 'http://p8.com'; + await saveFixtures(con, Source, sourcesFixture); + await saveFixtures(con, ArticlePost, [ + { + id: 'pdeleted', + shortId: 'spdeleted', + title: 'PDeleted', + url: request, + canonicalUrl: request, + score: 0, + sourceId: 'a', + createdAt: new Date('2021-09-22T07:15:51.247Z'), + tagsStr: 'javascript,webdev', + visible: false, + }, + ]); + + const res = await client.mutate(MUTATION, { variables: { url: request } }); + expect(res.errors).toBeFalsy(); + expect(res.data).toEqual({ + submitArticle: { + result: 'rejected', + reason: SubmissionFailErrorMessage.POST_DELETED, + post: null, + submission: null, + }, + }); + }); + it('should not allow invalid urls', async () => { loggedUser = '1'; const request = 'test/sample/url'; diff --git a/src/schema/submissions.ts b/src/schema/submissions.ts index 7324c1acb..39f5fbb6a 100644 --- a/src/schema/submissions.ts +++ b/src/schema/submissions.ts @@ -173,7 +173,7 @@ export const resolvers: IResolvers = traceResolvers< .getRepository(ArticlePost) .findOneBy([{ url }, { canonicalUrl: url }]); if (existingPost) { - if (existingPost.deleted) { + if (existingPost.deleted || !existingPost.visible) { return { result: 'rejected', reason: SubmissionFailErrorMessage.POST_DELETED,