@@ -58,6 +58,7 @@ import {
5858 UserTopReader ,
5959 View ,
6060 PostType ,
61+ UNKNOWN_SOURCE ,
6162} from '../src/entity' ;
6263import { UserProfileAnalytics } from '../src/entity/user/UserProfileAnalytics' ;
6364import { UserProfileAnalyticsHistory } from '../src/entity/user/UserProfileAnalyticsHistory' ;
@@ -245,6 +246,18 @@ beforeAll(async () => {
245246
246247const now = new Date ( ) ;
247248
249+ const createUnknownSourceArticlePost = (
250+ id : string ,
251+ title : string ,
252+ ) : Partial < ArticlePost > => ( {
253+ id,
254+ title,
255+ shortId : id ,
256+ url : `http://${ id } .com` ,
257+ sourceId : UNKNOWN_SOURCE ,
258+ visible : true ,
259+ } ) ;
260+
248261beforeEach ( async ( ) => {
249262 loggedUser = null ;
250263 isPlus = false ;
@@ -3417,6 +3430,36 @@ describe('query readHistory', () => {
34173430 expect ( res . data . readHistory . edges [ 0 ] . node . post . id ) . toEqual ( 'p2' ) ;
34183431 } ) ;
34193432
3433+ it ( "should return user's reading history without posts from unknown source" , async ( ) => {
3434+ loggedUser = '1' ;
3435+ const createdAtOld = new Date ( '2020-09-22T07:15:51.247Z' ) ;
3436+ const createdAtNew = new Date ( '2021-09-22T07:15:51.247Z' ) ;
3437+
3438+ await con
3439+ . getRepository ( ArticlePost )
3440+ . save (
3441+ createUnknownSourceArticlePost ( 'p-unk-read' , 'Unknown source post' ) ,
3442+ ) ;
3443+
3444+ await saveFixtures ( con , View , [
3445+ {
3446+ userId : '1' ,
3447+ postId : 'p-unk-read' ,
3448+ timestamp : createdAtOld ,
3449+ } ,
3450+ {
3451+ userId : '1' ,
3452+ postId : 'p2' ,
3453+ timestamp : createdAtNew ,
3454+ } ,
3455+ ] ) ;
3456+
3457+ const res = await client . query ( QUERY ) ;
3458+ expect ( res . errors ) . toBeFalsy ( ) ;
3459+ expect ( res . data . readHistory . edges ) . toHaveLength ( 1 ) ;
3460+ expect ( res . data . readHistory . edges [ 0 ] . node . post . id ) . toEqual ( 'p2' ) ;
3461+ } ) ;
3462+
34203463 it ( "should return user's reading history with the banned posts" , async ( ) => {
34213464 loggedUser = '1' ;
34223465 const createdAtOld = new Date ( '2020-09-22T07:15:51.247Z' ) ;
@@ -3688,6 +3731,32 @@ describe('query search reading history', () => {
36883731 expect ( res . errors ) . toBeFalsy ( ) ;
36893732 expect ( res . data ) . toMatchSnapshot ( ) ;
36903733 } ) ;
3734+
3735+ it ( 'should return reading history search feed without unknown source posts' , async ( ) => {
3736+ loggedUser = '1' ;
3737+
3738+ await con
3739+ . getRepository ( ArticlePost )
3740+ . save (
3741+ createUnknownSourceArticlePost ( 'p-unk-search' , 'Unknown search result' ) ,
3742+ ) ;
3743+
3744+ await con . getRepository ( View ) . save ( [
3745+ {
3746+ userId : loggedUser ,
3747+ timestamp : subDays ( now , 1 ) ,
3748+ postId : 'p-unk-search' ,
3749+ } ,
3750+ { userId : loggedUser , timestamp : subDays ( now , 2 ) , postId : 'p1' } ,
3751+ ] ) ;
3752+
3753+ const res = await client . query ( QUERY , {
3754+ variables : { query : 'Unknown' } ,
3755+ } ) ;
3756+
3757+ expect ( res . errors ) . toBeFalsy ( ) ;
3758+ expect ( res . data . readHistory . edges ) . toEqual ( [ ] ) ;
3759+ } ) ;
36913760} ) ;
36923761
36933762describe ( 'mutation updateUserProfile' , ( ) => {
0 commit comments