openvibers/openvibe.coupons Commits
agent.json: what a code's and a shop's id is (AGT-4) (#215)
Changes
@@@ -13,5 +13,11 @@ module.exports = {openapi: '/openapi.json',policy: {auth: ['none', 'Network OIDC'],++ // What an id in a page's address is, and that it never changes meaning (AGT-4): server/domain/coupons.js mints++ // the code ids, and server/http/public.js answers a taken-down code or shop with 410.++ stableIds: [++ { kind: 'code', url: 'https://openvibe.coupons/c/{id}', id: 'cpn_ and a ULID, minted once when the code is first reported: never reused, since a code is taken down but never deleted', gone: 'a code taken down answers 410; an id that never existed answers 404' },++ { kind: 'shop', url: 'https://openvibe.coupons/m/{slug}', id: 'the shop\'s slug', gone: 'a shop no longer listed answers 410' },++ ],},};nnew file mode 100644@@@ -0,0 +1,19 @@++'use strict';++// AGT-4: agent.json says what an id in a Coupons address is, and the code behaves as it says.++const assert = require('assert');++const fs = require('fs');++const path = require('path');++const { agentManifest } = require('openvibe-shared/agent-layer');++++const ids = agentManifest(require('../server/agent-descriptor')).policy.stableIds;++assert.deepStrictEqual(ids.map((x) => [x.kind, x.url]), [['code', 'https://openvibe.coupons/c/{id}'], ['shop', 'https://openvibe.coupons/m/{slug}']]);++const read = (f) => fs.readFileSync(path.join(__dirname, '..', 'server', f), 'utf8');++// A code id is a ULID minted once, and no code row is ever deleted (so no id is freed to be minted again).++assert.match(read('domain/coupons.js'), /const id = `cpn_\$\{ids\.ulid\(now\)\}`;/);++const all = fs.readdirSync(path.join(__dirname, '..', 'server'), { recursive: true }).filter((f) => f.endsWith('.js')).map((f) => read(f)).join('\n');++assert.doesNotMatch(all, /DELETE FROM coupons\b/i, 'a code is taken down, never deleted');++// Taken down: 410, both a code and a shop.++const pub = read('http/public.js');++assert.match(pub, /messagePage\(req, res, 410, 'Gone', 'This code was taken down\.'/);++assert.match(pub, /messagePage\(req, res, 410, 'Gone', 'This shop is no longer listed\.'/);++console.log('agent stable ids: ok');
@@ -13,5 +13,11 @@ module.exports = {
@@ -13,5 +13,11 @@ module.exports = {
openapi: '/openapi.json',
openapi: '/openapi.json',
policy: {
policy: {
auth: ['none', 'Network OIDC'],
auth: ['none', 'Network OIDC'],
+ // What an id in a page's address is, and that it never changes meaning (AGT-4): server/domain/coupons.js mints
+ // the code ids, and server/http/public.js answers a taken-down code or shop with 410.
+ stableIds: [
+ { kind: 'code', url: 'https://openvibe.coupons/c/{id}', id: 'cpn_ and a ULID, minted once when the code is first reported: never reused, since a code is taken down but never deleted', gone: 'a code taken down answers 410; an id that never existed answers 404' },
+ { kind: 'shop', url: 'https://openvibe.coupons/m/{slug}', id: 'the shop\'s slug', gone: 'a shop no longer listed answers 410' },
+ ],
},
},
};
};
new file mode 100644
new file mode 100644
@@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
+'use strict';
+// AGT-4: agent.json says what an id in a Coupons address is, and the code behaves as it says.
+const assert = require('assert');
+const fs = require('fs');
+const path = require('path');
+const { agentManifest } = require('openvibe-shared/agent-layer');
+
+const ids = agentManifest(require('../server/agent-descriptor')).policy.stableIds;
+assert.deepStrictEqual(ids.map((x) => [x.kind, x.url]), [['code', 'https://openvibe.coupons/c/{id}'], ['shop', 'https://openvibe.coupons/m/{slug}']]);
+const read = (f) => fs.readFileSync(path.join(__dirname, '..', 'server', f), 'utf8');
+// A code id is a ULID minted once, and no code row is ever deleted (so no id is freed to be minted again).
+assert.match(read('domain/coupons.js'), /const id = `cpn_\$\{ids\.ulid\(now\)\}`;/);
+const all = fs.readdirSync(path.join(__dirname, '..', 'server'), { recursive: true }).filter((f) => f.endsWith('.js')).map((f) => read(f)).join('\n');
+assert.doesNotMatch(all, /DELETE FROM coupons\b/i, 'a code is taken down, never deleted');
+// Taken down: 410, both a code and a shop.
+const pub = read('http/public.js');
+assert.match(pub, /messagePage\(req, res, 410, 'Gone', 'This code was taken down\.'/);
+assert.match(pub, /messagePage\(req, res, 410, 'Gone', 'This shop is no longer listed\.'/);
+console.log('agent stable ids: ok');