mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
fix(notices): a release's notes show to whoever dismissed them on its prerelease
Dismissals were compared with the prerelease part dropped, so a notice closed on 5.0.0-pre.2 counted as closed on 5.0.0 and the final release showed nothing to anyone who had tried a prerelease. Versions now compare in full.
This commit is contained in:
@@ -143,14 +143,18 @@ export class SystemNoticesService {
|
||||
managed: this.env.isManaged(),
|
||||
settingFlag: (key: string) => settingFlags.get(key) ?? false,
|
||||
};
|
||||
const appVer = semver.coerce(currentAppVersion)?.version ?? '0.0.0';
|
||||
// Full versions, the prerelease part included: a dismissal on 5.0.0-pre.2 is older
|
||||
// than 5.0.0, so whoever tried a prerelease still gets the notes of the release.
|
||||
const fullVersion = (v: string | null | undefined) =>
|
||||
semver.valid(v ?? '') ?? semver.coerce(v ?? '')?.version ?? '0.0.0';
|
||||
const appVer = fullVersion(currentAppVersion);
|
||||
|
||||
const isStillDismissed = (n: SystemNotice): boolean => {
|
||||
if (!dismissals.has(n.id)) return false;
|
||||
if (n.recurring === 'per-version') {
|
||||
// Re-show once the running app version moves past the version it was last dismissed at,
|
||||
// so a per-version notice surfaces again on each install/upgrade.
|
||||
const dismissedVer = semver.coerce(dismissals.get(n.id) ?? '0.0.0')?.version ?? '0.0.0';
|
||||
const dismissedVer = fullVersion(dismissals.get(n.id));
|
||||
return semver.gte(dismissedVer, appVer);
|
||||
}
|
||||
return true; // default: permanent one-time dismissal
|
||||
|
||||
@@ -162,6 +162,18 @@ describe('SystemNoticesService (Plan 3f Task 6)', () => {
|
||||
).not.toContain('sn-test-release');
|
||||
});
|
||||
|
||||
it('SN4b — a dismissal on a prerelease of the running version is older, so the notice of the release shows', async () => {
|
||||
// Tried 5.0.0-pre.2, now on 5.0.0: the prerelease part must not be dropped.
|
||||
const prerelease = makeService({
|
||||
listForUser: [{ notice_id: 'sn-test-release', dismissed_app_version: `${getCurrentAppVersion()}-pre.2` }],
|
||||
});
|
||||
expect(
|
||||
(await prerelease.svc.getActiveFor(BASE_USER.id, new Set(['release']), getCurrentAppVersion())).map(
|
||||
(n) => n.id,
|
||||
),
|
||||
).toContain('sn-test-release');
|
||||
});
|
||||
|
||||
it('a permanently-dismissed (non-recurring) notice never returns', async () => {
|
||||
const { svc } = makeService({ listForUser: [{ notice_id: 'sn-test-generic', dismissed_app_version: null }] });
|
||||
expect((await svc.getActiveFor(BASE_USER.id)).map((n) => n.id)).not.toContain('sn-test-generic');
|
||||
|
||||
Reference in New Issue
Block a user