openvibers/openvibe.compare Commits

Compare: keep the currency on every compute offer (#12)

OP OpenVibers committed 1 days ago · 148e7faac2 · 3 files, +3 −1

Exchange publishes each tariff with a currency; the comparison normalized it
away. Keep it (USD when the feed omits it) so /api/v1/compute consumers see
the unit beside hourly and monthly prices. Also drop an unused JSON helper.

Changes

ddiff --git a/server/compute-views.js b/server/compute-views.js
iindex 0779cbf..dc919d6 100644
---- a/server/compute-views.js
++++ b/server/compute-views.js
@@@ -4,7 +4,6 @@ const kit = require('openvibe-shared/kit');
const { PAGE, MONTH_HOURS, select, href, label } = require('./compute');
const esc = (v) => String(v ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
--const json = (v) => JSON.stringify(v).replace(/</g, '\\u003c');
const day = (iso) => (iso ? iso.slice(0, 10) : '—');
const month = (iso) => (iso ? new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' }) : '—');
const money = (v) => {
ddiff --git a/server/compute.js b/server/compute.js
iindex aeb05a7..6b4f977 100644
---- a/server/compute.js
++++ b/server/compute.js
@@@ -34,6 +34,7 @@ function offer(p, now) {
provider: text(p.provider) || 'unknown',
region: text(p.region) || null,
kind,
++ currency: text(p.currency) || 'USD',
cpu: nonNegative(p.cpu),
ram_mb: positive(p.ram_mb),
gpu: kind === 'gpu' ? text(p.gpu) || 'GPU' : null,
ddiff --git a/test/compute.test.js b/test/compute.test.js
iindex 85e4028..79ecb37 100644
---- a/test/compute.test.js
++++ b/test/compute.test.js
@@@ -33,6 +33,7 @@ test('compute prices are normalized, derived from Exchange fields, and invalid r
assert.equal(compute.offers[0].id, 'fly-iad-2x2');
const pre = compute.offers.find((o) => o.id === 'daytona-4090-preemptible');
assert.equal(pre.cheapest, true);
++ assert.equal(pre.currency, 'USD');
assert.equal(pre.hourly, .57);
assert.equal(pre.monthly_24_7, Math.round(.57 * MONTH_HOURS * 10000) / 10000);
assert.equal(pre.hourly_per_gpu_gb, Math.round(.57 / 24 * 10000) / 10000);
@@@ -141,6 +142,7 @@ test('API, page, phone/table markup, filters, Markdown, discovery and CORS', asy
assert.equal(body.source, 'OpenVibe.Exchange');
assert.equal(body.source_url, SOURCE);
assert.equal(body.offers.length, 6);
++ assert.equal(body.offers[0].currency, 'USD');
assert.equal(body.cheapest.gpu, 'daytona-4090-preemptible');
assert.equal(body.month_hours, MONTH_HOURS);
r = await fetch(base + '/api/v1/compute', { headers: { Origin: 'https://evil.example' } });