mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 23:16:46 +00:00
fix(notices): hand the release notice only to a bundle built for the running version
After an update the service worker keeps serving the previous bundle until the new one is installed. That shell announces the release layout too, so the layout alone let it draw the notice with its own older texts and use it up for the version now running with one click on X. The bundle now sends the version it was built as (client/package.json, baked in by define), and the server compares it with its own before it hands a notice with a release block over. A shell of another version is told nothing and gets the notice after the reload, from the bundle that can draw it. This holds for every update, not only the one that introduced the parameter.
This commit is contained in:
@@ -33,7 +33,7 @@ describe('SystemNoticesController (parity with the legacy /api/system-notices ro
|
||||
it('returns the evaluated notices for the current user', () => {
|
||||
const getActiveFor = vi.fn().mockReturnValue([notice]);
|
||||
expect(makeController({ getActiveFor }).active(user)).toEqual([notice]);
|
||||
expect(getActiveFor).toHaveBeenCalledWith(7, new Set());
|
||||
expect(getActiveFor).toHaveBeenCalledWith(7, new Set(), undefined);
|
||||
});
|
||||
|
||||
// The layouts a bundle announces with `?supports=` reach the service as a set, so
|
||||
@@ -41,25 +41,34 @@ describe('SystemNoticesController (parity with the legacy /api/system-notices ro
|
||||
it('passes the announced layouts through as a set', () => {
|
||||
const getActiveFor = vi.fn().mockReturnValue([]);
|
||||
makeController({ getActiveFor }).active(user, 'release');
|
||||
expect(getActiveFor).toHaveBeenCalledWith(7, new Set(['release']));
|
||||
expect(getActiveFor).toHaveBeenCalledWith(7, new Set(['release']), undefined);
|
||||
});
|
||||
|
||||
it('passes the bundle version through, trimmed, and only when it is one string', () => {
|
||||
const getActiveFor = vi.fn().mockReturnValue([]);
|
||||
const ctrl = makeController({ getActiveFor });
|
||||
ctrl.active(user, 'release', ' 4.3.0 ');
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(['release']), '4.3.0');
|
||||
ctrl.active(user, 'release', ['4.3.0', '4.3.1']);
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(['release']), undefined);
|
||||
});
|
||||
|
||||
it('splits a comma separated list and a repeated parameter alike', () => {
|
||||
const getActiveFor = vi.fn().mockReturnValue([]);
|
||||
const ctrl = makeController({ getActiveFor });
|
||||
ctrl.active(user, ' release, banner ,,');
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(['release', 'banner']));
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(['release', 'banner']), undefined);
|
||||
ctrl.active(user, ['release', 'banner']);
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(['release', 'banner']));
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(['release', 'banner']), undefined);
|
||||
});
|
||||
|
||||
it('announces nothing for an empty or missing parameter', () => {
|
||||
const getActiveFor = vi.fn().mockReturnValue([]);
|
||||
const ctrl = makeController({ getActiveFor });
|
||||
ctrl.active(user, '');
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set());
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(), undefined);
|
||||
ctrl.active(user, undefined);
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set());
|
||||
expect(getActiveFor).toHaveBeenLastCalledWith(7, new Set(), undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { mockGetActive, mockDismiss } = vi.hoisted(() => ({ mockGetActive: vi.fn(), mockDismiss: vi.fn() }));
|
||||
const { mockGetActive, mockDismiss, mockAppVersion } = vi.hoisted(() => ({ mockGetActive: vi.fn(), mockDismiss: vi.fn(), mockAppVersion: vi.fn(() => '4.3.0') }));
|
||||
vi.mock('../../../src/systemNotices/service', () => ({
|
||||
getActiveNoticesFor: mockGetActive,
|
||||
dismissNotice: mockDismiss,
|
||||
getCurrentAppVersion: mockAppVersion,
|
||||
}));
|
||||
|
||||
import { SystemNoticesService } from '../../../src/nest/system-notices/system-notices.service';
|
||||
@@ -70,15 +71,37 @@ describe('SystemNoticesService', () => {
|
||||
expect(svc.getActiveFor(7, new Set(['banner'])).map(n => n.id)).toEqual(['outage']);
|
||||
});
|
||||
|
||||
it('delivers it, in place, once the client announces the release layout', () => {
|
||||
it('delivers it, in place, once the client announces the release layout for the running version', () => {
|
||||
mockGetActive.mockReturnValue([release, generic]);
|
||||
expect(svc.getActiveFor(7, new Set(['release'])).map(n => n.id)).toEqual(['release-notes', 'outage']);
|
||||
expect(svc.getActiveFor(7, new Set(['release']), '4.3.0').map(n => n.id)).toEqual(['release-notes', 'outage']);
|
||||
});
|
||||
|
||||
it('drops it for a bundle that announces the layout but was built for another version', () => {
|
||||
// The shell the service worker serves right after an update: it can draw the
|
||||
// layout, but with the texts of the version it was built for, and its X would
|
||||
// use the notice up for the version now running.
|
||||
mockGetActive.mockReturnValue([release, generic]);
|
||||
expect(svc.getActiveFor(7, new Set(['release']), '4.2.1').map(n => n.id)).toEqual(['outage']);
|
||||
mockAppVersion.mockReturnValueOnce('4.3.1');
|
||||
expect(svc.getActiveFor(7, new Set(['release']), '4.3.0').map(n => n.id)).toEqual(['outage']);
|
||||
});
|
||||
|
||||
it('drops it for a bundle that names no version at all', () => {
|
||||
mockGetActive.mockReturnValue([release, generic]);
|
||||
expect(svc.getActiveFor(7, new Set(['release'])).map(n => n.id)).toEqual(['outage']);
|
||||
expect(svc.getActiveFor(7, new Set(['release']), '').map(n => n.id)).toEqual(['outage']);
|
||||
expect(svc.getActiveFor(7, new Set(['release']), 'dev').map(n => n.id)).toEqual(['outage']);
|
||||
});
|
||||
|
||||
it('reads the version loosely, as the server reads its own', () => {
|
||||
mockGetActive.mockReturnValue([release, generic]);
|
||||
expect(svc.getActiveFor(7, new Set(['release']), 'v4.3.0').map(n => n.id)).toEqual(['release-notes', 'outage']);
|
||||
});
|
||||
|
||||
it('always delivers a notice without a release block', () => {
|
||||
mockGetActive.mockReturnValue([generic]);
|
||||
expect(svc.getActiveFor(7).map(n => n.id)).toEqual(['outage']);
|
||||
expect(svc.getActiveFor(7, new Set(['release'])).map(n => n.id)).toEqual(['outage']);
|
||||
expect(svc.getActiveFor(7, new Set(['release']), '4.3.0').map(n => n.id)).toEqual(['outage']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user