Skip to content

Commit 5ebc0e8

Browse files
authored
fix(read-history): exclude unknown source posts (#3746)
1 parent f3fb173 commit 5ebc0e8

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

__tests__/users.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
UserTopReader,
5959
View,
6060
PostType,
61+
UNKNOWN_SOURCE,
6162
} from '../src/entity';
6263
import { UserProfileAnalytics } from '../src/entity/user/UserProfileAnalytics';
6364
import { UserProfileAnalyticsHistory } from '../src/entity/user/UserProfileAnalyticsHistory';
@@ -245,6 +246,18 @@ beforeAll(async () => {
245246

246247
const 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+
248261
beforeEach(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

36933762
describe('mutation updateUserProfile', () => {

src/schema/users.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
UserStreakActionType,
3030
View,
3131
PostType,
32+
UNKNOWN_SOURCE,
3233
} from '../entity';
3334
import { UserNotificationFlags, UserSocialLink } from '../entity/user/User';
3435
import {
@@ -1784,7 +1785,10 @@ const readHistoryResolver = async (
17841785
)
17851786
.addSelect('timestamp', 'timestampDb')
17861787
.andWhere('p.visible = true')
1787-
.andWhere('p.deleted = false');
1788+
.andWhere('p.deleted = false')
1789+
.andWhere('p.sourceId != :unknownSource', {
1790+
unknownSource: UNKNOWN_SOURCE,
1791+
});
17881792

17891793
if (args?.query) {
17901794
builder.queryBuilder.andWhere(`p.tsv @@ (${getSearchQuery(':query')})`, {

0 commit comments

Comments
 (0)