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:
@@ -48,6 +48,7 @@ import { resetTestDb } from '../helpers/test-db';
|
||||
import { createUser, createAdmin } from '../helpers/factories';
|
||||
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';
|
||||
|
||||
let nestApp: INestApplication;
|
||||
@@ -235,12 +236,13 @@ describe('GET /api/system-notices/active', () => {
|
||||
const { user } = createUser(testDb);
|
||||
testDb.prepare('UPDATE users SET login_count = 5, first_seen_version = ? WHERE id = ?').run('3.0.0', user.id);
|
||||
|
||||
// The client announces the release layout with `?supports=release`; a bundle that
|
||||
// predates it never gets the notice (pinned separately below).
|
||||
// The client announces the release layout and the version it was built as; a
|
||||
// bundle that predates that, or one built for another version, never gets the
|
||||
// notice (pinned separately below).
|
||||
const shows = async () => {
|
||||
const res = await request(app)
|
||||
.get('/api/system-notices/active')
|
||||
.query({ supports: 'release' })
|
||||
.query({ supports: 'release', ui: getCurrentAppVersion() })
|
||||
.set('Cookie', authCookie(user.id));
|
||||
expect(res.status).toBe(200);
|
||||
return res.body.some((n: { id: string }) => n.id === 'release-notes');
|
||||
@@ -273,9 +275,10 @@ describe('GET /api/system-notices/active', () => {
|
||||
|
||||
// Right after an update the browser still runs the bundle the service worker cached,
|
||||
// which has neither the copy for the new release notice nor a way to tell. It would
|
||||
// draw the keys and, on close, spend the notice for this whole version. So the notice
|
||||
// waits for a client that announces the release layout; the reload brings one.
|
||||
it('keeps the release notes from a client that does not announce the release layout', async () => {
|
||||
// draw the keys, or its own older texts, and on close spend the notice for this whole
|
||||
// version. So the notice waits for a client that announces the release layout AND
|
||||
// was built for the version now running; the reload brings one.
|
||||
it('keeps the release notes from a client that does not announce the release layout for this version', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
testDb.prepare('UPDATE users SET login_count = 5, first_seen_version = ? WHERE id = ?').run('3.0.0', user.id);
|
||||
|
||||
@@ -289,9 +292,15 @@ describe('GET /api/system-notices/active', () => {
|
||||
expect(without.body.some((n: { id: string }) => n.id === 'release-notes')).toBe(false);
|
||||
expect(without.body.some((n: { release?: unknown }) => n.release !== undefined)).toBe(false);
|
||||
|
||||
const withLayout = await fetchActive({ supports: 'release' });
|
||||
expect(withLayout.status).toBe(200);
|
||||
expect(withLayout.body.some((n: { id: string }) => n.id === 'release-notes')).toBe(true);
|
||||
// The layout alone is the shell of the previous version after an update.
|
||||
const layoutOnly = await fetchActive({ supports: 'release' });
|
||||
expect(layoutOnly.body.some((n: { id: string }) => n.id === 'release-notes')).toBe(false);
|
||||
const olderBundle = await fetchActive({ supports: 'release', ui: '4.0.0' });
|
||||
expect(olderBundle.body.some((n: { id: string }) => n.id === 'release-notes')).toBe(false);
|
||||
|
||||
const matching = await fetchActive({ supports: 'release', ui: getCurrentAppVersion() });
|
||||
expect(matching.status).toBe(200);
|
||||
expect(matching.body.some((n: { id: string }) => n.id === 'release-notes')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user