openvibers/openvibe.actor Commits
An approval's expiry rounds down (#329)
Changes
@@@ -17,7 +17,10 @@ function ago(iso, now = Date.now()) {if (!Number.isFinite(t)) return '';const d = Math.round((t - now) / 1000);const a = Math.abs(d);-- const [n, unit] = a < 60 ? [a, 'second'] : a < 3600 ? [Math.round(a / 60), 'minute'] : a < 86400 ? [Math.round(a / 3600), 'hour'] : [Math.round(a / 86400), 'day'];++ // A time to come rounds down (6.75 days left is "in 6 days": never promise more time than there is); a time past++ // rounds to the nearest.++ const r = d > 0 ? Math.floor : Math.round;++ const [n, unit] = a < 60 ? [a, 'second'] : a < 3600 ? [r(a / 60), 'minute'] : a < 86400 ? [r(a / 3600), 'hour'] : [r(a / 86400), 'day'];if (a < 45) return 'just now';const words = `${n} ${unit}${n === 1 ? '' : 's'}`;return d < 0 ? `${words} ago` : `in ${words}`;@@@ -138,6 +138,9 @@ const SAME = { 'sec-fetch-site': 'same-origin' };const asked = (one.text.match(/Asked [\s\S]{0,240}/) || [''])[0];assert.match(asked, /title="[^"]+ UTC">(just now|[^<]* ago)</, `a time a person reads, the exact one in its title: ${asked}`);assert.match(one.text, /expires <time[^>]*>in [67] days</);++ const later = await approvals.request(t.ctx.s, { owner, agentId: helper.id, kind: 'actor.action', summary: 'Run "ls" on your computer', payload: { argv: ['ls'], machine: 'dev_x' } });++ await t.ctx.s.db.query("UPDATE actor_approvals SET expires_at = $2 WHERE id = $1", [later.id, new Date(Date.parse(t.ctx.s.iso()) + 6.75 * 86400000).toISOString()]);++ assert.match((await t.get(`/me/approvals/${later.id}`, { as: ada })).text, /expires <time[^>]*>in 6 days</, 'never more time than there is');assert.ok(one.text.includes('The exact request'), 'the details stay, after the plain words');});} finally {
@@ -17,7 +17,10 @@ function ago(iso, now = Date.now()) {
@@ -17,7 +17,10 @@ function ago(iso, now = Date.now()) {
if (!Number.isFinite(t)) return '';
if (!Number.isFinite(t)) return '';
const d = Math.round((t - now) / 1000);
const d = Math.round((t - now) / 1000);
const a = Math.abs(d);
const a = Math.abs(d);
- const [n, unit] = a < 60 ? [a, 'second'] : a < 3600 ? [Math.round(a / 60), 'minute'] : a < 86400 ? [Math.round(a / 3600), 'hour'] : [Math.round(a / 86400), 'day'];
+ // A time to come rounds down (6.75 days left is "in 6 days": never promise more time than there is); a time past
+ // rounds to the nearest.
+ const r = d > 0 ? Math.floor : Math.round;
+ const [n, unit] = a < 60 ? [a, 'second'] : a < 3600 ? [r(a / 60), 'minute'] : a < 86400 ? [r(a / 3600), 'hour'] : [r(a / 86400), 'day'];
if (a < 45) return 'just now';
if (a < 45) return 'just now';
const words = `${n} ${unit}${n === 1 ? '' : 's'}`;
const words = `${n} ${unit}${n === 1 ? '' : 's'}`;
return d < 0 ? `${words} ago` : `in ${words}`;
return d < 0 ? `${words} ago` : `in ${words}`;
@@ -138,6 +138,9 @@ const SAME = { 'sec-fetch-site': 'same-origin' };
@@ -138,6 +138,9 @@ const SAME = { 'sec-fetch-site': 'same-origin' };
const asked = (one.text.match(/Asked [\s\S]{0,240}/) || [''])[0];
const asked = (one.text.match(/Asked [\s\S]{0,240}/) || [''])[0];
assert.match(asked, /title="[^"]+ UTC">(just now|[^<]* ago)</, `a time a person reads, the exact one in its title: ${asked}`);
assert.match(asked, /title="[^"]+ UTC">(just now|[^<]* ago)</, `a time a person reads, the exact one in its title: ${asked}`);
assert.match(one.text, /expires <time[^>]*>in [67] days</);
assert.match(one.text, /expires <time[^>]*>in [67] days</);
+ const later = await approvals.request(t.ctx.s, { owner, agentId: helper.id, kind: 'actor.action', summary: 'Run "ls" on your computer', payload: { argv: ['ls'], machine: 'dev_x' } });
+ await t.ctx.s.db.query("UPDATE actor_approvals SET expires_at = $2 WHERE id = $1", [later.id, new Date(Date.parse(t.ctx.s.iso()) + 6.75 * 86400000).toISOString()]);
+ assert.match((await t.get(`/me/approvals/${later.id}`, { as: ada })).text, /expires <time[^>]*>in 6 days</, 'never more time than there is');
assert.ok(one.text.includes('The exact request'), 'the details stay, after the plain words');
assert.ok(one.text.includes('The exact request'), 'the details stay, after the plain words');
});
});
} finally {
} finally {