2018-02-06 23:31:18 +01:00
|
|
|
const sinon = require('sinon');
|
|
|
|
const proxyquire = require('proxyquire').noCallThru();
|
|
|
|
|
|
|
|
const storage = {
|
2020-07-13 19:21:28 +02:00
|
|
|
kill: sinon.stub(),
|
2019-02-12 20:50:06 +01:00
|
|
|
ttl: sinon.stub()
|
2018-02-06 23:31:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function request(id) {
|
|
|
|
return {
|
|
|
|
params: { id }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function response() {
|
|
|
|
return {
|
|
|
|
sendStatus: sinon.stub()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const delRoute = proxyquire('../../server/routes/delete', {
|
|
|
|
'../storage': storage
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('/api/delete', function() {
|
|
|
|
afterEach(function() {
|
2020-07-13 19:21:28 +02:00
|
|
|
storage.kill.reset();
|
2018-02-06 23:31:18 +01:00
|
|
|
});
|
|
|
|
|
2020-07-13 19:21:28 +02:00
|
|
|
it('calls storage.kill with the id parameter', async function() {
|
2018-02-06 23:31:18 +01:00
|
|
|
const req = request('x');
|
|
|
|
const res = response();
|
|
|
|
await delRoute(req, res);
|
2020-07-13 19:21:28 +02:00
|
|
|
sinon.assert.calledWith(storage.kill, 'x');
|
2018-02-06 23:31:18 +01:00
|
|
|
sinon.assert.calledWith(res.sendStatus, 200);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sends a 404 on failure', async function() {
|
2020-07-13 19:21:28 +02:00
|
|
|
storage.kill.returns(Promise.reject(new Error()));
|
2018-02-06 23:31:18 +01:00
|
|
|
const res = response();
|
|
|
|
await delRoute(request('x'), res);
|
|
|
|
sinon.assert.calledWith(res.sendStatus, 404);
|
|
|
|
});
|
|
|
|
});
|