@@ -53,7 +53,7 @@ import {
5353 postTagsFixture ,
5454 videoPostsFixture ,
5555} from './fixture/post' ;
56- import { DataSource , DeepPartial , IsNull , Not } from 'typeorm' ;
56+ import { DataSource , DeepPartial , In , IsNull , Not } from 'typeorm' ;
5757import createOrGetConnection from '../src/db' ;
5858import {
5959 createSquadWelcomePost ,
@@ -3958,6 +3958,52 @@ describe('mutation createPostInMultipleSources', () => {
39583958 expect ( moderationItem . sharedPostId ) . toBe ( existingArticle . id ) ;
39593959 expect ( userSourcePost . sharedPostId ) . toBe ( existingArticle . id ) ;
39603960 } ) ;
3961+
3962+ it ( 'should share existing post when url differs only by www' , async ( ) => {
3963+ loggedUser = '1' ;
3964+ await con . getRepository ( ArticlePost ) . save ( {
3965+ id : 'pmswww' ,
3966+ shortId : 'pmswww' ,
3967+ url : 'http://www.multisource-www.com/a' ,
3968+ canonicalUrl : 'http://www.multisource-www.com/a' ,
3969+ sourceId : 'a' ,
3970+ visible : true ,
3971+ createdAt : new Date ( ) ,
3972+ type : PostType . Article ,
3973+ origin : PostOrigin . Squad ,
3974+ } ) ;
3975+
3976+ const res = await client . mutate ( MUTATION , {
3977+ variables : {
3978+ ...freeformParams ,
3979+ externalLink : 'http://multisource-www.com/a' ,
3980+ } ,
3981+ } ) ;
3982+
3983+ expect ( res . errors ) . toBeFalsy ( ) ;
3984+ const [ first , second , third ] = res . data . createPostInMultipleSources ;
3985+
3986+ const [ post , moderationItem , userSourcePost ] = await Promise . all ( [
3987+ con . getRepository ( SharePost ) . findOneByOrFail ( { id : first . id } ) ,
3988+ con . getRepository ( SourcePostModeration ) . findOneOrFail ( {
3989+ select : [ 'sharedPostId' ] ,
3990+ where : { id : second . id } ,
3991+ } ) ,
3992+ con . getRepository ( SharePost ) . findOneByOrFail ( { id : third . id } ) ,
3993+ ] ) ;
3994+
3995+ expect ( post . sharedPostId ) . toBe ( 'pmswww' ) ;
3996+ expect ( moderationItem . sharedPostId ) . toBe ( 'pmswww' ) ;
3997+ expect ( userSourcePost . sharedPostId ) . toBe ( 'pmswww' ) ;
3998+
3999+ const articlePosts = await con . getRepository ( ArticlePost ) . findBy ( {
4000+ url : In ( [
4001+ 'http://multisource-www.com/a' ,
4002+ 'http://www.multisource-www.com/a' ,
4003+ ] ) ,
4004+ } ) ;
4005+ expect ( articlePosts ) . toHaveLength ( 1 ) ;
4006+ } ) ;
39614007 } ) ;
39624008
39634009 describe ( 'poll post creation' , ( ) => {
@@ -4587,6 +4633,25 @@ describe('mutation submitExternalLink', () => {
45874633 expect ( sharedPost . visible ) . toEqual ( true ) ;
45884634 } ) ;
45894635
4636+ it ( 'should share existing post to squad when url differs only by www' , async ( ) => {
4637+ loggedUser = '1' ;
4638+ const res = await client . mutate ( MUTATION , {
4639+ variables : { ...variables , url : 'http://www.p6.com' } ,
4640+ } ) ;
4641+ expect ( res . errors ) . toBeFalsy ( ) ;
4642+
4643+ const articlePosts = await con
4644+ . getRepository ( ArticlePost )
4645+ . findBy ( { url : In ( [ 'http://p6.com' , 'http://www.p6.com' ] ) } ) ;
4646+ expect ( articlePosts ) . toHaveLength ( 1 ) ;
4647+ expect ( articlePosts [ 0 ] . id ) . toEqual ( 'p6' ) ;
4648+
4649+ const sharedPost = await con
4650+ . getRepository ( SharePost )
4651+ . findOneByOrFail ( { sharedPostId : 'p6' } ) ;
4652+ expect ( sharedPost . authorId ) . toEqual ( '1' ) ;
4653+ } ) ;
4654+
45904655 it ( 'should trigger content request when sharing existing post without title and summary' , async ( ) => {
45914656 loggedUser = '1' ;
45924657
0 commit comments