openvibers/openvibe.compare Commits
Compare: keep the currency on every compute offer (#12)
Changes
@@@ -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) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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) => {@@@ -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,@@@ -33,6 +33,7 @@ test('compute prices are normalized, derived from Exchange fields, and invalid rassert.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', asyassert.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' } });
@@ -4,7 +4,6 @@ const kit = require('openvibe-shared/kit');
@@ -4,7 +4,6 @@ const kit = require('openvibe-shared/kit');
const { PAGE, MONTH_HOURS, select, href, label } = require('./compute');
const { PAGE, MONTH_HOURS, select, href, label } = require('./compute');
const esc = (v) => String(v ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
const esc = (v) => String(v ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
-const json = (v) => JSON.stringify(v).replace(/</g, '\\u003c');
const day = (iso) => (iso ? iso.slice(0, 10) : '—');
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 month = (iso) => (iso ? new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' }) : '—');
const money = (v) => {
const money = (v) => {
@@ -34,6 +34,7 @@ function offer(p, now) {
@@ -34,6 +34,7 @@ function offer(p, now) {
provider: text(p.provider) || 'unknown',
provider: text(p.provider) || 'unknown',
region: text(p.region) || null,
region: text(p.region) || null,
kind,
kind,
+ currency: text(p.currency) || 'USD',
cpu: nonNegative(p.cpu),
cpu: nonNegative(p.cpu),
ram_mb: positive(p.ram_mb),
ram_mb: positive(p.ram_mb),
gpu: kind === 'gpu' ? text(p.gpu) || 'GPU' : null,
gpu: kind === 'gpu' ? text(p.gpu) || 'GPU' : null,
@@ -33,6 +33,7 @@ test('compute prices are normalized, derived from Exchange fields, and invalid r
@@ -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');
assert.equal(compute.offers[0].id, 'fly-iad-2x2');
const pre = compute.offers.find((o) => o.id === 'daytona-4090-preemptible');
const pre = compute.offers.find((o) => o.id === 'daytona-4090-preemptible');
assert.equal(pre.cheapest, true);
assert.equal(pre.cheapest, true);
+ assert.equal(pre.currency, 'USD');
assert.equal(pre.hourly, .57);
assert.equal(pre.hourly, .57);
assert.equal(pre.monthly_24_7, Math.round(.57 * MONTH_HOURS * 10000) / 10000);
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);
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
@@ -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, 'OpenVibe.Exchange');
assert.equal(body.source_url, SOURCE);
assert.equal(body.source_url, SOURCE);
assert.equal(body.offers.length, 6);
assert.equal(body.offers.length, 6);
+ assert.equal(body.offers[0].currency, 'USD');
assert.equal(body.cheapest.gpu, 'daytona-4090-preemptible');
assert.equal(body.cheapest.gpu, 'daytona-4090-preemptible');
assert.equal(body.month_hours, MONTH_HOURS);
assert.equal(body.month_hours, MONTH_HOURS);
r = await fetch(base + '/api/v1/compute', { headers: { Origin: 'https://evil.example' } });
r = await fetch(base + '/api/v1/compute', { headers: { Origin: 'https://evil.example' } });