Fix megaphone check for dontShowBeforeEpochMs

Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2026-02-18 12:41:42 -06:00
committed by GitHub
parent b1b4abdf7d
commit ef2a2da7b4
2 changed files with 13 additions and 1 deletions

View File

@@ -194,6 +194,7 @@ export function isMegaphoneShowable(
): megaphone is VisibleRemoteMegaphoneType {
const nowMs = Date.now();
const {
dontShowBeforeEpochMs,
dontShowAfterEpochMs,
isFinished,
snoozedAt,
@@ -201,7 +202,11 @@ export function isMegaphoneShowable(
secondaryCtaId,
} = megaphone;
if (isFinished || nowMs > dontShowAfterEpochMs) {
if (
isFinished ||
nowMs < dontShowBeforeEpochMs ||
nowMs > dontShowAfterEpochMs
) {
return false;
}

View File

@@ -109,6 +109,13 @@ describe('megaphone service', () => {
assert.strictEqual(isMegaphoneShowable(megaphone), true);
});
it('handles megaphone with dontShowBeforeEpochMs in the future', () => {
const megaphone = getMegaphone({
dontShowBeforeEpochMs: Date.now() + 1 * DAY,
});
assert.strictEqual(isMegaphoneShowable(megaphone), false);
});
it('handles megaphone expired past dontShowAfterEpochMs', () => {
const megaphone = getMegaphone({
dontShowAfterEpochMs: Date.now() - 1 * DAY,