mirror of
https://github.com/outline/outline.git
synced 2026-12-03 10:00:13 +03:00
fix: return both total and unseen separately
This commit is contained in:
1 parent
83e0038716
commit
bebde97bdc
2 files changed
+35
-19
No files matched your search
@@ -59,11 +59,15 @@ describe("#notifications.list", () => {
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(body.data.length).toBe(3);
|
||||
expect(body.pagination.total).toBe(2);
|
||||
expect((randomElement(body.data) as any).actor.id).toBe(actor.id);
|
||||
expect((randomElement(body.data) as any).userId).toBe(user.id);
|
||||
const events = body.data.map((n: any) => n.event);
|
||||
expect(body.data.notifications.length).toBe(3);
|
||||
expect(body.pagination.total).toBe(3);
|
||||
expect((randomElement(body.data.notifications) as any).actor.id).toBe(
|
||||
actor.id
|
||||
);
|
||||
expect((randomElement(body.data.notifications) as any).userId).toBe(
|
||||
user.id
|
||||
);
|
||||
const events = body.data.notifications.map((n: any) => n.event);
|
||||
expect(events).toContain(NotificationEventType.UpdateDocument);
|
||||
expect(events).toContain(NotificationEventType.CreateComment);
|
||||
expect(events).toContain(NotificationEventType.MentionedInComment);
|
||||
@@ -116,11 +120,15 @@ describe("#notifications.list", () => {
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(body.data.length).toBe(1);
|
||||
expect(body.data.notifications.length).toBe(1);
|
||||
expect(body.pagination.total).toBe(1);
|
||||
expect((randomElement(body.data) as any).actor.id).toBe(actor.id);
|
||||
expect((randomElement(body.data) as any).userId).toBe(user.id);
|
||||
const events = body.data.map((n: any) => n.event);
|
||||
expect((randomElement(body.data.notifications) as any).actor.id).toBe(
|
||||
actor.id
|
||||
);
|
||||
expect((randomElement(body.data.notifications) as any).userId).toBe(
|
||||
user.id
|
||||
);
|
||||
const events = body.data.notifications.map((n: any) => n.event);
|
||||
expect(events).toContain(NotificationEventType.MentionedInComment);
|
||||
});
|
||||
|
||||
@@ -173,11 +181,15 @@ describe("#notifications.list", () => {
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(body.data.length).toBe(2);
|
||||
expect(body.data.notifications.length).toBe(2);
|
||||
expect(body.pagination.total).toBe(2);
|
||||
expect((randomElement(body.data) as any).actor.id).toBe(actor.id);
|
||||
expect((randomElement(body.data) as any).userId).toBe(user.id);
|
||||
const events = body.data.map((n: any) => n.event);
|
||||
expect((randomElement(body.data.notifications) as any).actor.id).toBe(
|
||||
actor.id
|
||||
);
|
||||
expect((randomElement(body.data.notifications) as any).userId).toBe(
|
||||
user.id
|
||||
);
|
||||
const events = body.data.notifications.map((n: any) => n.event);
|
||||
expect(events).toContain(NotificationEventType.CreateComment);
|
||||
expect(events).toContain(NotificationEventType.UpdateDocument);
|
||||
});
|
||||
|
||||
@@ -81,13 +81,16 @@ router.post(
|
||||
},
|
||||
};
|
||||
}
|
||||
const [notifications, total] = await Promise.all([
|
||||
const [notifications, total, unseen] = await Promise.all([
|
||||
Notification.scope(["withUser", "withActor"]).findAll({
|
||||
where,
|
||||
order: [["createdAt", "DESC"]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
}),
|
||||
Notification.count({
|
||||
where,
|
||||
}),
|
||||
Notification.count({
|
||||
where: {
|
||||
...where,
|
||||
@@ -98,13 +101,14 @@ router.post(
|
||||
}),
|
||||
]);
|
||||
|
||||
const data = notifications.map((notification) =>
|
||||
presentNotification(notification)
|
||||
);
|
||||
|
||||
ctx.body = {
|
||||
pagination: { ...ctx.state.pagination, total },
|
||||
data,
|
||||
data: {
|
||||
notifications: notifications.map((notification) =>
|
||||
presentNotification(notification)
|
||||
),
|
||||
unseen,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user