Begin implementing a reporting mechanism

This commit is contained in:
Danny Coates
2020-07-13 10:21:28 -07:00
parent ccbcb69666
commit 9891d1f0ba
37 changed files with 762 additions and 183 deletions

View File

@@ -2,7 +2,7 @@ const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru();
const storage = {
del: sinon.stub(),
kill: sinon.stub(),
ttl: sinon.stub()
};
@@ -24,19 +24,19 @@ const delRoute = proxyquire('../../server/routes/delete', {
describe('/api/delete', function() {
afterEach(function() {
storage.del.reset();
storage.kill.reset();
});
it('calls storage.del with the id parameter', async function() {
it('calls storage.kill with the id parameter', async function() {
const req = request('x');
const res = response();
await delRoute(req, res);
sinon.assert.calledWith(storage.del, 'x');
sinon.assert.calledWith(storage.kill, 'x');
sinon.assert.calledWith(res.sendStatus, 200);
});
it('sends a 404 on failure', async function() {
storage.del.returns(Promise.reject(new Error()));
storage.kill.returns(Promise.reject(new Error()));
const res = response();
await delRoute(request('x'), res);
sinon.assert.calledWith(res.sendStatus, 404);

View File

@@ -6,7 +6,7 @@ const storage = {
length: sinon.stub()
};
function request(id, meta) {
function request(id, meta = {}) {
return {
params: { id },
meta

View File

@@ -133,7 +133,12 @@ describe('Storage', function() {
};
await storage.set('x', null, m);
const meta = await storage.metadata('x');
assert.deepEqual(meta, m);
assert.deepEqual(meta, {
...m,
dead: false,
flagged: false,
key: undefined
});
});
});
});