notifications: make update alerts non-persistent
once acked, they remain acked. no need to keep nagging the user about them.
This commit is contained in:
@@ -114,7 +114,7 @@ describe('Eventlog', function () {
|
||||
for (const e of [ eventlog.ACTION_USER_LOGIN, eventlog.ACTION_USER_LOGIN_GHOST, eventlog.ACTION_USER_LOGOUT, eventlog.ACTION_USER_LOGIN ]) {
|
||||
const eventId = await eventlog.add(e, { ip: '1.2.3.4' }, { appId: 'thatapp' });
|
||||
|
||||
await notifications._add(eventId, 'title', 'some message');
|
||||
await notifications._add('title', 'some message', { eventId });
|
||||
}
|
||||
|
||||
await delay(3000);
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('Notifications', function () {
|
||||
|
||||
it('can add notifications', async function () {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const [error, id] = await safe(notifications._add(EVENT_0.id, `title ${i}`, `message ${i}`));
|
||||
const [error, id] = await safe(notifications._add(`title ${i}`, `message ${i}`, { eventId: EVENT_0.id }));
|
||||
expect(error).to.equal(null);
|
||||
expect(id).to.be.a('string');
|
||||
notificationIds.push(id);
|
||||
@@ -85,7 +85,7 @@ describe('Notifications', function () {
|
||||
|
||||
let alertId;
|
||||
it('can add alert', async function () {
|
||||
alertId = await notifications.alert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available', 'Awesome changelog');
|
||||
alertId = await notifications.alert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available', 'Awesome changelog', { persist: true });
|
||||
|
||||
const result = await notifications.get(alertId);
|
||||
expect(result.title).to.be('Cloudron xx is available');
|
||||
@@ -93,10 +93,10 @@ describe('Notifications', function () {
|
||||
expect(result.acknowledged).to.be(false);
|
||||
});
|
||||
|
||||
it('can update the alert', async function () {
|
||||
it('can update the alert (persist)', async function () {
|
||||
await notifications.update({ id: alertId }, { acknowledged: true }); // ack the alert
|
||||
|
||||
const id = await notifications.alert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available', 'Awesome new changelog');
|
||||
const id = await notifications.alert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available', 'Awesome new changelog', { persist: true });
|
||||
expect(id).to.be(alertId);
|
||||
|
||||
const result = await notifications.get(alertId);
|
||||
@@ -105,6 +105,18 @@ describe('Notifications', function () {
|
||||
expect(result.acknowledged).to.be(false); // notification resurfaces
|
||||
});
|
||||
|
||||
it('can update the alert (non-persist)', async function () {
|
||||
await notifications.update({ id: alertId }, { acknowledged: true }); // ack the alert
|
||||
|
||||
const id = await notifications.alert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available', 'Awesome new changelog', { persist: false });
|
||||
expect(id).to.be(alertId);
|
||||
|
||||
const result = await notifications.get(alertId);
|
||||
expect(result.title).to.be('Cloudron xx is available');
|
||||
expect(result.message).to.be('Awesome new changelog');
|
||||
expect(result.acknowledged).to.be(true); // notification does not resurface
|
||||
});
|
||||
|
||||
it('can clear the alert', async function () {
|
||||
const id = await notifications.clearAlert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available');
|
||||
expect(id).to.be(null);
|
||||
|
||||
Reference in New Issue
Block a user