openvibers/openvibe.watch Commits

A fired watch says when it fetched in words; the evidence keeps the ISO time (#257)

OP OpenVibers committed 4 days ago · d783913ae8 · 2 files, +12 −2

Changes

ddiff --git a/server/actions.js b/server/actions.js
iindex f2625ee..37c1df5 100644
---- a/server/actions.js
++++ b/server/actions.js
@@@ -88,6 +88,15 @@ const REFUSED_URL = new Set(['bad_url', 'port_refused', 'address_refused']);
const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? `${t.slice(0, n - 1)}…` : t; };
++/** "Nov 3, 05:01 UTC": when a value was fetched, as the alert's words say it (rich_content keeps the exact ISO time). */
++function readableTime(iso) {
++ const d = new Date(iso);
++ if (Number.isNaN(d.getTime())) return String(iso);
++ const month = d.toLocaleString('en-US', { month: 'short', timeZone: 'UTC' });
++ const hh = String(d.getUTCHours()).padStart(2, '0'), mm = String(d.getUTCMinutes()).padStart(2, '0');
++ return `${month} ${d.getUTCDate()}, ${hh}:${mm} UTC`;
++}
++
/**
* A value as a person reads it in one line. A feed entry or any record with a title or name reads as that title and
* a short summary ("(Senior) Product Engineer — Bielefeld · Remote"), never as its JSON; a list says how many and
@@@ -128,7 +137,7 @@ function notificationFor({ config, watch, run, action, value, previousValue, obs
const evidence = evidenceFor({ watch, value, previousValue, observedAt });
const facts = [before !== null && before !== now ? `${now} (was ${before})` : now];
if (evidence.source_url) facts.push(`from ${evidence.source_url}`);
-- if (evidence.fetched_at) facts.push(`fetched ${evidence.fetched_at}`);
++ if (evidence.fetched_at) facts.push(`fetched ${readableTime(evidence.fetched_at)}`);
return {
type: 'WATCH_TRIGGERED',
service: 'watch',
ddiff --git a/test/actions.test.js b/test/actions.test.js
iindex 41b9638..ea2da72 100644
---- a/test/actions.test.js
++++ b/test/actions.test.js
@@@ -133,7 +133,8 @@ t('a check that does not fire queues nothing; one that fires queues each action
assert.strictEqual(p.subjectId, person.sub);
assert.deepStrictEqual([p.type, p.service, p.category, p.priority], ['WATCH_TRIGGERED', 'watch', 'service', 'high']);
assert.strictEqual(p.title, '“Widget price” fired');
-- assert.match(p.message, /^7\.50 \(was 19\.99\) · from http:\/\/127\.0\.0\.1:\d+\/price · fetched \d{4}-\d{2}-\d{2}T/);
++ assert.match(p.message, /^7\.50 \(was 19\.99\) · from http:\/\/127\.0\.0\.1:\d+\/price · fetched [A-Z][a-z]{2} \d{1,2}, \d{2}:\d{2} UTC$/, 'a time a person reads');
++ assert.match(p.rich_content.evidence.fetched_at, /^\d{4}-\d{2}-\d{2}T/, 'the exact time stays in the evidence');
assert.strictEqual(p.url, `https://openvibe.watch/watches/${w.id}`);
assert.strictEqual(p.rich_content.check_run_id, out.run.id);
// The alert carries its evidence: before and after, the source and when it was fetched.