fix(server): correct notification pagination by using 'lt' instead of 'gt' for createdAt (#11430)
This commit is contained in:
@@ -625,24 +625,7 @@ e2e('should list and count notifications', async t => {
|
|||||||
t.is(body2.workspace!.name, 'test-workspace-name');
|
t.is(body2.workspace!.name, 'test-workspace-name');
|
||||||
t.falsy(body2.workspace!.avatarUrl);
|
t.falsy(body2.workspace!.avatarUrl);
|
||||||
|
|
||||||
await app.login(owner);
|
// load more notifications
|
||||||
await app.gql({
|
|
||||||
query: mentionUserMutation,
|
|
||||||
variables: {
|
|
||||||
input: {
|
|
||||||
userId: member.id,
|
|
||||||
workspaceId: workspace.id,
|
|
||||||
doc: {
|
|
||||||
id: 'doc-id-5',
|
|
||||||
title: 'doc-title-5',
|
|
||||||
blockId: 'block-id-5',
|
|
||||||
mode: DocMode.page,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// get new notifications
|
|
||||||
await app.login(member);
|
await app.login(member);
|
||||||
const result2 = await app.gql({
|
const result2 = await app.gql({
|
||||||
query: listNotificationsQuery,
|
query: listNotificationsQuery,
|
||||||
@@ -650,43 +633,43 @@ e2e('should list and count notifications', async t => {
|
|||||||
pagination: {
|
pagination: {
|
||||||
first: 2,
|
first: 2,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
after: result.currentUser!.notifications.pageInfo.startCursor,
|
after: result.currentUser!.notifications.pageInfo.endCursor,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
t.is(result2.currentUser!.notifications.totalCount, 5);
|
t.is(result2.currentUser!.notifications.totalCount, 4);
|
||||||
t.is(result2.currentUser!.notifications.pageInfo.hasNextPage, false);
|
t.is(result2.currentUser!.notifications.pageInfo.hasNextPage, true);
|
||||||
t.is(result2.currentUser!.notifications.pageInfo.hasPreviousPage, true);
|
t.is(result2.currentUser!.notifications.pageInfo.hasPreviousPage, true);
|
||||||
const notifications2 = result2.currentUser!.notifications.edges.map(
|
const notifications2 = result2.currentUser!.notifications.edges.map(
|
||||||
edge => edge.node
|
edge => edge.node
|
||||||
) as NotificationObjectType[];
|
) as NotificationObjectType[];
|
||||||
t.is(notifications2.length, 1);
|
t.is(notifications2.length, 2);
|
||||||
|
|
||||||
const notification3 = notifications2[0];
|
const notification3 = notifications2[0];
|
||||||
t.is(notification3.read, false);
|
t.is(notification3.read, false);
|
||||||
const body3 = notification3.body as MentionNotificationBodyType;
|
const body3 = notification3.body as MentionNotificationBodyType;
|
||||||
t.is(body3.workspace!.id, workspace.id);
|
t.is(body3.workspace!.id, workspace.id);
|
||||||
t.is(body3.doc.id, 'doc-id-5');
|
t.is(body3.doc.id, 'doc-id-2');
|
||||||
t.is(body3.doc.title, 'doc-title-5');
|
t.is(body3.doc.title, 'doc-title-2');
|
||||||
t.is(body3.doc.blockId, 'block-id-5');
|
t.is(body3.doc.blockId, 'block-id-2');
|
||||||
t.is(body3.createdByUser!.id, owner.id);
|
t.is(body3.createdByUser!.id, owner.id);
|
||||||
t.is(body3.createdByUser!.name, owner.name);
|
t.is(body3.createdByUser!.name, owner.name);
|
||||||
t.is(body3.workspace!.id, workspace.id);
|
t.is(body3.workspace!.id, workspace.id);
|
||||||
t.is(body3.workspace!.name, 'test-workspace-name');
|
t.is(body3.workspace!.name, 'test-workspace-name');
|
||||||
t.falsy(body3.workspace!.avatarUrl);
|
t.falsy(body3.workspace!.avatarUrl);
|
||||||
|
|
||||||
// no new notifications
|
// no notifications
|
||||||
const result3 = await app.gql({
|
const result3 = await app.gql({
|
||||||
query: listNotificationsQuery,
|
query: listNotificationsQuery,
|
||||||
variables: {
|
variables: {
|
||||||
pagination: {
|
pagination: {
|
||||||
first: 2,
|
first: 2,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
after: result2.currentUser!.notifications.pageInfo.startCursor,
|
after: result2.currentUser!.notifications.pageInfo.endCursor,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
t.is(result3.currentUser!.notifications.totalCount, 5);
|
t.is(result3.currentUser!.notifications.totalCount, 4);
|
||||||
t.is(result3.currentUser!.notifications.pageInfo.hasNextPage, false);
|
t.is(result3.currentUser!.notifications.pageInfo.hasNextPage, false);
|
||||||
t.is(result3.currentUser!.notifications.pageInfo.hasPreviousPage, true);
|
t.is(result3.currentUser!.notifications.pageInfo.hasPreviousPage, true);
|
||||||
t.is(result3.currentUser!.notifications.pageInfo.startCursor, null);
|
t.is(result3.currentUser!.notifications.pageInfo.startCursor, null);
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ export class NotificationModel extends BaseModel {
|
|||||||
where: {
|
where: {
|
||||||
userId,
|
userId,
|
||||||
...(options?.includeRead ? {} : { read: false }),
|
...(options?.includeRead ? {} : { read: false }),
|
||||||
...(options?.after ? { createdAt: { gt: options.after } } : {}),
|
...(options?.after ? { createdAt: { lt: options.after } } : {}),
|
||||||
},
|
},
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
skip: options?.offset,
|
skip: options?.offset,
|
||||||
|
|||||||
Reference in New Issue
Block a user