mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(server): phase 1 review follow-ups — awaited returns, logged upload-filter rejections, covered handshake/notice branches, call-graph gate in CI, dead test imports
This commit is contained in:
@@ -33,6 +33,7 @@ import { authCookie } from '../helpers/auth';
|
||||
import { SYSTEM_NOTICES } from '../../src/systemNotices/registry';
|
||||
import { getCurrentAppVersion } from '../../src/systemNotices/service';
|
||||
import type { SystemNotice } from '../../src/systemNotices/types';
|
||||
import { ADDON_IDS } from '../../src/addons';
|
||||
|
||||
let nestApp: INestApplication;
|
||||
let app: Application;
|
||||
@@ -50,6 +51,21 @@ const TEST_NOTICE: SystemNotice = {
|
||||
priority: 0,
|
||||
};
|
||||
|
||||
// Test notice gated on an addon, so the addonFlags lookup in getActiveNoticesFor
|
||||
// (built once per call from every addonEnabled condition in SYSTEM_NOTICES) is
|
||||
// exercised for both the enabled and the disabled case.
|
||||
const TEST_NOTICE_ADDON: SystemNotice = {
|
||||
id: 'test-addon-notice',
|
||||
display: 'modal',
|
||||
severity: 'info',
|
||||
titleKey: 'system_notice.test_addon_notice.title',
|
||||
bodyKey: 'system_notice.test_addon_notice.body',
|
||||
dismissible: true,
|
||||
conditions: [{ kind: 'addonEnabled', addonId: ADDON_IDS.JOURNEY }],
|
||||
publishedAt: '2026-01-01T00:00:00Z',
|
||||
priority: 0,
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
nestApp = await buildApp();
|
||||
app = nestApp.getHttpAdapter().getInstance();
|
||||
@@ -119,6 +135,31 @@ describe('GET /api/system-notices/active', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('an addonEnabled-gated notice appears only while the addon is on', async () => {
|
||||
SYSTEM_NOTICES.push(TEST_NOTICE_ADDON);
|
||||
try {
|
||||
const { user } = createUser(testDb);
|
||||
testDb.prepare('UPDATE addons SET enabled = 0 WHERE id = ?').run(ADDON_IDS.JOURNEY);
|
||||
|
||||
const off = await request(app)
|
||||
.get('/api/system-notices/active')
|
||||
.set('Cookie', authCookie(user.id));
|
||||
expect(off.status).toBe(200);
|
||||
expect(off.body.find((n: { id: string }) => n.id === TEST_NOTICE_ADDON.id)).toBeUndefined();
|
||||
|
||||
testDb.prepare('UPDATE addons SET enabled = 1 WHERE id = ?').run(ADDON_IDS.JOURNEY);
|
||||
|
||||
const on = await request(app)
|
||||
.get('/api/system-notices/active')
|
||||
.set('Cookie', authCookie(user.id));
|
||||
expect(on.status).toBe(200);
|
||||
expect(on.body.find((n: { id: string }) => n.id === TEST_NOTICE_ADDON.id)).toBeDefined();
|
||||
} finally {
|
||||
const idx = SYSTEM_NOTICES.indexOf(TEST_NOTICE_ADDON);
|
||||
if (idx !== -1) SYSTEM_NOTICES.splice(idx, 1);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not return firstLogin notice for user with login_count > 1', async () => {
|
||||
SYSTEM_NOTICES.push(TEST_NOTICE);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user