mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +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:
@@ -26,7 +26,6 @@ import { DaysService, DayReorderError } from '../../src/nest/days/days.service';
|
||||
import { RealtimeService } from '../../src/nest/realtime/realtime.service';
|
||||
import { QueryHelpersService } from '../../src/nest/query-helpers/query-helpers.service';
|
||||
import { createTestUnitOfWork } from '../helpers/test-uow';
|
||||
import { UnitOfWork } from '../../src/nest/database/unit-of-work';
|
||||
|
||||
let svc: DaysService;
|
||||
beforeAll(async () => {
|
||||
|
||||
@@ -208,7 +208,7 @@ describe('PluginRuntimeService (M2 end-to-end)', () => {
|
||||
|
||||
// erasure: enqueue (durable) + drain → the plugin deletes its rows and the queue clears
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(runtime as any).enqueueUserErasure(5);
|
||||
await (runtime as any).enqueueUserErasure(5);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await (runtime as any).drainUserErasures();
|
||||
expect(testDb.prepare("SELECT COUNT(*) c FROM plugin_user_erasure_queue WHERE plugin_id='gdpr'").get()).toMatchObject({ c: 0 });
|
||||
@@ -245,7 +245,7 @@ describe('PluginRuntimeService (M2 end-to-end)', () => {
|
||||
// granted the hook but NOT active → enqueue keeps the row, drain leaves it
|
||||
testDb.prepare("INSERT INTO plugins (id, status, permissions, config) VALUES ('offliner','inactive','[\"db:own\",\"hook:user-data\"]','{}')").run();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(runtime as any).enqueueUserErasure(9);
|
||||
await (runtime as any).enqueueUserErasure(9);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await (runtime as any).drainUserErasures();
|
||||
expect(testDb.prepare("SELECT COUNT(*) c FROM plugin_user_erasure_queue WHERE plugin_id='offliner' AND user_id=9").get()).toMatchObject({ c: 1 });
|
||||
|
||||
@@ -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